org.xnap.util
Class Formatter

java.lang.Object
  extended by org.xnap.util.Formatter

public class Formatter
extends java.lang.Object

Helper class providing static methods for formatting different number and date formats.


Field Summary
static int CENTER
           
static int LEFT
           
static int RIGHT
           
static java.lang.String[] SIZES
           
 
Constructor Summary
Formatter()
           
 
Method Summary
static java.lang.String fill(java.lang.String s, int count)
          Creates a string from a string being count times appended to itself.
static java.lang.String formatDate(java.util.Date date)
          Formats date.
static java.lang.String formatLength(long i)
          Formats number of seconds in appropriate time unit
static java.lang.String formatNumber(double number)
          Formats a number without any digits in the fraction portion.
static java.lang.String formatNumber(double number, int decimal)
          Formats double as decimal number.
static java.lang.String formatSize(double size)
          Returns value (byte) formatted as a file size.
static java.lang.String formatTable(java.lang.String[] rows, int[] colAlignment)
          Formats a row of strings according to given alignments for the console output.
static java.lang.String formatTime(long time)
          Formats time from given milliseconds time value.
static java.lang.String getCLFDate()
          Returns the current date in the format needed for CLF.
static java.lang.String shortDate()
          Returns a string of the current date in short format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEFT

public static final int LEFT
See Also:
Constant Field Values

CENTER

public static final int CENTER
See Also:
Constant Field Values

RIGHT

public static final int RIGHT
See Also:
Constant Field Values

SIZES

public static final java.lang.String[] SIZES
Constructor Detail

Formatter

public Formatter()
Method Detail

formatNumber

public static java.lang.String formatNumber(double number,
                                            int decimal)
Formats double as decimal number.

Parameters:
number - number to be formatted
decimal - the number of digits allowed in the fraction portion of a number
Returns:
formatted number as string

formatNumber

public static java.lang.String formatNumber(double number)
Formats a number without any digits in the fraction portion.

Parameters:
number - number to be formatted
Returns:
formatted number as string

formatSize

public static java.lang.String formatSize(double size)
Returns value (byte) formatted as a file size. For example value=2048 returns "2 kb".

Parameters:
size - filesize to be formatted
Returns:
formatted number as string

formatLength

public static java.lang.String formatLength(long i)
Formats number of seconds in appropriate time unit

Parameters:
i - number of seconds
Returns:
formatted duration as string

formatDate

public static java.lang.String formatDate(java.util.Date date)
Formats date.


formatTime

public static java.lang.String formatTime(long time)
Formats time from given milliseconds time value.

Parameters:
time - milliseconds since January 1, 1970, 00:00:00 GMT not to exceed the milliseconds representation for the year 8099. A negative number indicates the number of milliseconds before January 1, 1970, 00:00:00 GMT.

formatTable

public static java.lang.String formatTable(java.lang.String[] rows,
                                           int[] colAlignment)
Formats a row of strings according to given alignments for the console output.

Parameters:
rows - array of strings to be formatted
colAlignment - array of alignment policies

fill

public static java.lang.String fill(java.lang.String s,
                                    int count)
Creates a string from a string being count times appended to itself.

Parameters:
s - string
count - number of times it's appended to itself

getCLFDate

public static java.lang.String getCLFDate()
Returns the current date in the format needed for CLF. Example: 15/Dec/2002:23:46:16


shortDate

public static java.lang.String shortDate()
Returns a string of the current date in short format. Example: 11.19.80



Copyright © 2001-2005 XNap Team. All Rights Reserved.