ucar.unidata.util
Class Format

java.lang.Object
  extended by ucar.unidata.util.Format

public class Format
extends Object

static formatting utilities. Replace with standard java library when possible.

Author:
John Caron

Constructor Summary
Format()
           
 
Method Summary
static String d(double d, int min_sigfig)
          Double value formatting with minimum number of significant figures in a minimum width.
static String d(double d, int min_sigfig, int width)
          Double value formatting with minimum number of significant figures in a specified width.
static String dfrac(double d, int fixed_decimals)
          Double value formatting with fixed number of digits to the right of the decimal point.
static String formatByteSize(double size)
          Nicely formatted representation of bytes, eg turn 5.636E7 into
static String formatDouble(double d, int min_sigFigs, int fixed_decimals)
          Format a double value
static String i(int v, int width)
          Format an integer value.
static String l(long v, int width)
          Format a long value.
static void main(String[] argv)
          Main method for testing
static String pad(String s, int width, boolean rightJustify)
          Create a new string by padding the existing one with blanks to specified width.
static String s(String s, int width)
          Create a new string by padding the existing one with blanks to specified width.
static void tab(StringBuffer sbuff, int tabStop, boolean alwaysOne)
          Blank fill sbuff with blanks, until position tabStop.
static void tab(StringBuilder sbuff, int tabStop, boolean alwaysOne)
          Blank fill sbuff with blanks, until position tabStop.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Format

public Format()
Method Detail

tab

public static void tab(StringBuffer sbuff,
                       int tabStop,
                       boolean alwaysOne)
Blank fill sbuff with blanks, until position tabStop.

Parameters:
sbuff - StringBuffer to manipulate
tabStop - pad out to here
alwaysOne - true if you want to guarentee at least one space.

tab

public static void tab(StringBuilder sbuff,
                       int tabStop,
                       boolean alwaysOne)
Blank fill sbuff with blanks, until position tabStop.

Parameters:
sbuff - StringBuilder to manipulate
tabStop - pad out to here
alwaysOne - true if you want to guarentee at least one space.

s

public static String s(String s,
                       int width)
Create a new string by padding the existing one with blanks to specified width. Do nothing if length is already greater or equal to width.

Parameters:
s - string to pad
width - length of return string
Returns:
padded string

pad

public static String pad(String s,
                         int width,
                         boolean rightJustify)
Create a new string by padding the existing one with blanks to specified width. Do nothing if length is already greater or equal to width.

Parameters:
s - string to pad
width - length of return string
rightJustify - if true, right justify, else left justify
Returns:
padded string

i

public static String i(int v,
                       int width)
Format an integer value.

Parameters:
v - : value
width - pad to this width
Returns:
formatted string

l

public static String l(long v,
                       int width)
Format a long value.

Parameters:
v - : value
width - pad to this width
Returns:
formatted string

d

public static String d(double d,
                       int min_sigfig)
Double value formatting with minimum number of significant figures in a minimum width. This will try to do a reasonable job of getting a representation that has min_sigfig significant figures in minimum width.

Parameters:
d - the number to format.
min_sigfig - minimum number of significant figures
Returns:
string representation

d

public static String d(double d,
                       int min_sigfig,
                       int width)
Double value formatting with minimum number of significant figures in a specified width. This will try to do a reasonable job of getting a representation that has min_sigfig significant figures in the specified width. Right now, all it does is call d( double d, int min_sigfig) and left pad out to width chars.

Parameters:
d - the number to format.
min_sigfig - minimum number of significant figures
width - width of the result
Returns:
string representation, right justified in field of specified width

dfrac

public static String dfrac(double d,
                           int fixed_decimals)
Double value formatting with fixed number of digits to the right of the decimal point.

Parameters:
d - the number to format.
fixed_decimals - number of digits to the right of the decimal point
Returns:
string representation, with specified number of decimal places

formatDouble

public static String formatDouble(double d,
                                  int min_sigFigs,
                                  int fixed_decimals)
Format a double value

Parameters:
d - value to format
min_sigFigs - minimum significant figures
fixed_decimals - number of fixed decimals
Returns:
double formatted as a string

formatByteSize

public static String formatByteSize(double size)
Nicely formatted representation of bytes, eg turn 5.636E7 into

Parameters:
size - the size in bytes
Returns:
formatted string

main

public static void main(String[] argv)
Main method for testing

Parameters:
argv - ignored


Copyright © 1999-2011 UCAR/Unidata. All Rights Reserved.