javatools.parsers
Class NumberFormatter

java.lang.Object
  extended by javatools.parsers.NumberFormatter

public class NumberFormatter
extends java.lang.Object

This class is part of the Java Tools (see http://mpii.de/yago-naga/javatools). It is licensed under the Creative Commons Attribution License (see http://creativecommons.org/licenses/by/3.0) by the YAGO-NAGA team (see http://mpii.de/yago-naga). This class is a simple number formatter. Furthermore, this class offers some methods for the ISO8601 time format
Example:

         System.out.println(new NumberFormatter("+##.###").format(3.1119));
         -->      +03.112
         System.out.println(NumberFormatter.ISOtime());
         -->      2006-01-17 T 21:01:00.000
         System.out.println(NumberFormatter.ISOweekTime());
         -->      2006-w03-2 T 21:01:00.000
   
The pattern for numbers may look like

        [+|-|+/-]  #*[x]#* [.#*]

   
without blanks. 'x' is a separator character for groups of 3 digits. Only one x will be recognized and it will always separate groups of 3, no matter where it appears. Examples:
       +###.#####
       -#
       +/-#.######
       ##
       +#'###'###.##
   
If the formatted number is negative, a negative sign is always output. If the number is positive, a sign will only be output if the pattern starts with "+" or "+/-". The output will contain at least as many digits as specified in the pattern. If the integer part of a number contains more digits than specified in the pattern, the digits will be output nevertheless. If the fractional part of a number contains more digits than specified in the pattern, the number will be rounded and the digits will not be output. Instead of '#', you may write digits.


Field Summary
static NumberFormatter fiveDigits
          Predefined NumberFormatter for #####
static NumberFormatter fourDigits
          Predefined NumberFormatter for ####
static NumberFormatter fourFractions
          Predefined NumberFormatter for #.####
static NumberFormatter oneDigit
          Predefined NumberFormatter for #
static NumberFormatter sixDigits
          Predefined NumberFormatter for ######
static NumberFormatter threeDigits
          Predefined NumberFormatter for ###
static NumberFormatter twoDigits
          Predefined NumberFormatter for ##
static NumberFormatter twoFractions
          Predefined NumberFormatter for #.##
 
Constructor Summary
NumberFormatter(java.lang.String f)
          Creates a NumberFormatter for a pattern
 
Method Summary
 java.lang.String format(double d)
          Converts a double to a String
static java.lang.String formatMS(long ms)
          Converts milliseconds to a nice String
static java.lang.String ISOdate()
          Returns an ISO8601 string representation of the current date
static java.lang.String ISOdate(java.util.Calendar c)
          Returns an ISO8601 string representation of the time given by the calendar
static java.lang.String ISOtime()
          Returns an ISO8601 string representation of the current time
static java.lang.String ISOtime(java.util.Calendar c)
          Returns an ISO8601 string representation of the time given by the calendar
static java.lang.String ISOweekTime()
          Returns an ISO8601 string representation of the current time, using a week-oriented representation
static java.lang.String ISOweekTime(java.util.Calendar c)
          Returns an ISO8601 string representation of the time given by the calendar, using a week-oriented representation
static void main(java.lang.String[] argv)
          Test routine
static java.lang.String timeStamp()
          Returns a current timestamp
static java.lang.String timeStamp(java.util.Calendar c)
          Returns a timestamp from a Calendar
static java.lang.String timeStamp(java.lang.String isoTime)
          Returns a timestamp from an ISOweekTime or an ISOtime
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sixDigits

public static NumberFormatter sixDigits
Predefined NumberFormatter for ######


fiveDigits

public static NumberFormatter fiveDigits
Predefined NumberFormatter for #####


fourDigits

public static NumberFormatter fourDigits
Predefined NumberFormatter for ####


threeDigits

public static NumberFormatter threeDigits
Predefined NumberFormatter for ###


twoDigits

public static NumberFormatter twoDigits
Predefined NumberFormatter for ##


oneDigit

public static NumberFormatter oneDigit
Predefined NumberFormatter for #


fourFractions

public static NumberFormatter fourFractions
Predefined NumberFormatter for #.####


twoFractions

public static NumberFormatter twoFractions
Predefined NumberFormatter for #.##

Constructor Detail

NumberFormatter

public NumberFormatter(java.lang.String f)
Creates a NumberFormatter for a pattern

Method Detail

format

public java.lang.String format(double d)
Converts a double to a String


ISOtime

public static java.lang.String ISOtime()
Returns an ISO8601 string representation of the current time


ISOtime

public static java.lang.String ISOtime(java.util.Calendar c)
Returns an ISO8601 string representation of the time given by the calendar


ISOdate

public static java.lang.String ISOdate()
Returns an ISO8601 string representation of the current date


ISOdate

public static java.lang.String ISOdate(java.util.Calendar c)
Returns an ISO8601 string representation of the time given by the calendar


ISOweekTime

public static java.lang.String ISOweekTime()
Returns an ISO8601 string representation of the current time, using a week-oriented representation


ISOweekTime

public static java.lang.String ISOweekTime(java.util.Calendar c)
Returns an ISO8601 string representation of the time given by the calendar, using a week-oriented representation


timeStamp

public static java.lang.String timeStamp(java.lang.String isoTime)
Returns a timestamp from an ISOweekTime or an ISOtime


timeStamp

public static java.lang.String timeStamp(java.util.Calendar c)
Returns a timestamp from a Calendar


timeStamp

public static java.lang.String timeStamp()
Returns a current timestamp


formatMS

public static java.lang.String formatMS(long ms)
Converts milliseconds to a nice String


main

public static void main(java.lang.String[] argv)
Test routine