Jeospace API

org.jeospace.text
Class LengthFormat

java.lang.Object
  extended byorg.jeospace.text.LengthFormat
All Implemented Interfaces:
java.lang.Cloneable

public class LengthFormat
extends java.lang.Object
implements java.lang.Cloneable

Formats Length objects into readable strings and parses strings into Length objects.

Usage notes:

  1. A string is parsed from the end for a known unit symbol. If a unit symbol is found the remaining string is parsed from the end for a known multiplier symbol. The remaining string is then passed to the parse routine of NumberFormat to decode the magnitude of the Length represented by the string. Blank characters between any of these three fields of the string ( units, multiplier, magnitude ) will be ignored.
  2. parse and format only read and write units and multipliers as symbols. Parsing and formatting with full names is not implemented.
  3. LengthFormat utilizes NumberFormat to parse and format the numeric magnitude. The NumberFormat object is declared as public and it's properties may be customized through it's public methods. Note that NumberFormat does not gracefully handle very large ( larger than Long.MAX_VALUE ) or very small numbers which may be truncated.
  4. Settable separators between magnitude, multiplier and units fields in format are not supported. By default a single space separates the magnitude and multiplier. No separation is provided between the multiplier and unit symbols.

Version:
$Revision: 1.1.1.1 $
Author:
Rex Melton
See Also:
Length, LengthUnit, Mult, NumberFormat

Field Summary
protected  boolean formatOptionsAreSet
           
protected  java.lang.String[] localizedUnitSymbol
           
protected static Mult[] MULT
           
protected  Mult multiplier
           
protected  java.lang.String multiplierSymbol
           
protected  java.text.NumberFormat nf
          NumberFormat object used to format and parse the magnitude portion of a Length object.
protected static LengthUnit[] UNIT
           
protected  LengthUnit units
           
protected  java.lang.String unitSymbol
           
 
Constructor Summary
LengthFormat()
          Construct a LengthFormat object initialized to the default locale.
LengthFormat(java.util.Locale locale)
          Construct a LengthFormat object initialized to the specified locale.
LengthFormat(java.util.Locale locale, Mult multiplier, LengthUnit units)
          Construct a LengthFormat object initialized to the specified locale, multiplier and Length units.
LengthFormat(Mult multiplier, LengthUnit units)
          Construct a LengthFormat object initialized to the default locale and specified multiplier and Length units.
 
Method Summary
 void clearFormatOptions()
          Clear the multiplier and units of display for the format method of this LengthFormat object.
 java.lang.Object clone()
          Return a copy of this LengthFormat object.
 boolean equals(java.lang.Object obj)
          Compare two LengthFormats for equality.
 java.lang.String format(Length inLength)
          Format the passed Length object into a human readable String.
 java.text.NumberFormat getNumberFormat()
          Return the NumberFormat object associated with this LengthFormat object
 Length parse(java.lang.String inText)
          Parse the passed String into an Length object.
 void setFormatOptions(Mult multiplier, LengthUnit units)
          Set the multiplier and units of display for the format method of this LengthFormat object.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nf

protected final java.text.NumberFormat nf
NumberFormat object used to format and parse the magnitude portion of a Length object.


formatOptionsAreSet

protected boolean formatOptionsAreSet

multiplierSymbol

protected java.lang.String multiplierSymbol

unitSymbol

protected java.lang.String unitSymbol

multiplier

protected Mult multiplier

units

protected LengthUnit units

MULT

protected static final Mult[] MULT

UNIT

protected static final LengthUnit[] UNIT

localizedUnitSymbol

protected final java.lang.String[] localizedUnitSymbol
Constructor Detail

LengthFormat

public LengthFormat()
Construct a LengthFormat object initialized to the default locale. The multiplier and units from the Length object will be used for formatting.


LengthFormat

public LengthFormat(Mult multiplier,
                    LengthUnit units)
Construct a LengthFormat object initialized to the default locale and specified multiplier and Length units.


LengthFormat

public LengthFormat(java.util.Locale locale)
Construct a LengthFormat object initialized to the specified locale. The multiplier and units from the Length object will be used.


LengthFormat

public LengthFormat(java.util.Locale locale,
                    Mult multiplier,
                    LengthUnit units)
Construct a LengthFormat object initialized to the specified locale, multiplier and Length units.

Method Detail

getNumberFormat

public java.text.NumberFormat getNumberFormat()
Return the NumberFormat object associated with this LengthFormat object


clearFormatOptions

public void clearFormatOptions()
Clear the multiplier and units of display for the format method of this LengthFormat object. This will cause the multiplier and units from the Length object will be used for formatting.


setFormatOptions

public void setFormatOptions(Mult multiplier,
                             LengthUnit units)
Set the multiplier and units of display for the format method of this LengthFormat object.

Parameters:
multiplier - the Mult object
units - the LengthUnit object

format

public java.lang.String format(Length inLength)
Format the passed Length object into a human readable String.

Parameters:
inLength - the Length object to format.
Returns:
the formatted string representing the Length object.

parse

public Length parse(java.lang.String inText)
             throws java.text.ParseException
Parse the passed String into an Length object.

Parameters:
inText - the string to parse.
Returns:
the Length object.
Throws:
java.text.ParseException

clone

public java.lang.Object clone()
Return a copy of this LengthFormat object. Overrides Cloneable.

Returns:
a copy of this LengthFormat object.

equals

public boolean equals(java.lang.Object obj)
Compare two LengthFormats for equality. The result is true if and only if the argument object is not null, is a LengthFormat object and represents a LengthFormat of the same type and style.

Two LengthFormat objects are equal only when the format method will produce identical results with equal Length objects as arguments.


Jeospace API

Copyright © 2006 - jeospace.org