Jeospace API

org.jeospace.text
Class MassFormat

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

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

Formats Mass objects into readable strings and parses strings into Mass 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 Mass 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. MassFormat 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:
Mass, MassUnit, 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 Mass object.
protected static MassUnit[] UNIT
           
protected  MassUnit units
           
protected  java.lang.String unitSymbol
           
 
Constructor Summary
MassFormat()
          Construct a MassFormat object initialized to the default locale.
MassFormat(java.util.Locale locale)
          Construct a MassFormat object initialized to the specified locale.
MassFormat(java.util.Locale locale, Mult multiplier, MassUnit units)
          Construct a MassFormat object initialized to the specified locale, multiplier and Mass units.
MassFormat(Mult multiplier, MassUnit units)
          Construct a MassFormat object initialized to the default locale and specified multiplier and Mass units.
 
Method Summary
 void clearFormatOptions()
          Clear the multiplier and units of display for the format method of this MassFormat object.
 java.lang.Object clone()
          Return a copy of this MassFormat object.
 boolean equals(java.lang.Object obj)
          Compare two MassFormats for equality.
 java.lang.String format(Mass inMass)
          Format the passed Mass object into a human readable String.
 java.text.NumberFormat getNumberFormat()
          Return the NumberFormat object associated with this MassFormat object
 Mass parse(java.lang.String inText)
          Parse the passed String into an Mass object.
 void setFormatOptions(Mult multiplier, MassUnit units)
          Set the multiplier and units of display for the format method of this MassFormat 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 Mass object.


formatOptionsAreSet

protected boolean formatOptionsAreSet

multiplierSymbol

protected java.lang.String multiplierSymbol

unitSymbol

protected java.lang.String unitSymbol

multiplier

protected Mult multiplier

units

protected MassUnit units

MULT

protected static final Mult[] MULT

UNIT

protected static final MassUnit[] UNIT

localizedUnitSymbol

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

MassFormat

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


MassFormat

public MassFormat(Mult multiplier,
                  MassUnit units)
Construct a MassFormat object initialized to the default locale and specified multiplier and Mass units.


MassFormat

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


MassFormat

public MassFormat(java.util.Locale locale,
                  Mult multiplier,
                  MassUnit units)
Construct a MassFormat object initialized to the specified locale, multiplier and Mass units.

Method Detail

getNumberFormat

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


clearFormatOptions

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


setFormatOptions

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

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

format

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

Parameters:
inMass - the Mass object to format.
Returns:
the formatted string representing the Mass object.

parse

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

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

clone

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

Returns:
a copy of this MassFormat object.

equals

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

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


Jeospace API

Copyright © 2006 - jeospace.org