JScience v4.3

javax.measure.unit
Class UnitFormat.DefaultFormat

java.lang.Object
  extended by java.text.Format
      extended by javax.measure.unit.UnitFormat
          extended by javax.measure.unit.UnitFormat.DefaultFormat
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
UnitFormat.ASCIIFormat
Enclosing class:
UnitFormat

protected static class UnitFormat.DefaultFormat
extends UnitFormat

This class represents the standard format.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.measure.unit.UnitFormat
UnitFormat.ASCIIFormat, UnitFormat.DefaultFormat
 
Nested classes/interfaces inherited from class java.text.Format
java.text.Format.Field
 
Constructor Summary
protected UnitFormat.DefaultFormat()
           
 
Method Summary
 void alias(Unit<?> unit, java.lang.String alias)
          Attaches a system-wide alias to this unit.
 java.lang.Appendable format(Unit<?> unit, java.lang.Appendable appendable)
          Formats the specified unit.
 boolean isValidIdentifier(java.lang.String name)
          Indicates if the specified name can be used as unit identifier.
 void label(Unit<?> unit, java.lang.String label)
          Attaches a system-wide label to the specified unit.
 java.lang.String nameFor(Unit<?> unit)
           
 Unit<? extends Quantity> parseProductUnit(java.lang.CharSequence csq, java.text.ParsePosition pos)
          Parses a sequence of character to produce a unit or a rational product of unit.
 Unit<? extends Quantity> parseSingleUnit(java.lang.CharSequence csq, java.text.ParsePosition pos)
          Parses a sequence of character to produce a single unit.
 Unit<?> unitFor(java.lang.String name)
           
 
Methods inherited from class javax.measure.unit.UnitFormat
format, getInstance, getInstance, getUCUMInstance, parseObject
 
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UnitFormat.DefaultFormat

protected UnitFormat.DefaultFormat()
Method Detail

label

public void label(Unit<?> unit,
                  java.lang.String label)
Description copied from class: UnitFormat
Attaches a system-wide label to the specified unit. For example:
     UnitFormat.getInstance().label(DAY.multiply(365), "year");
     UnitFormat.getInstance().label(METER.multiply(0.3048), "ft");
 
If the specified label is already associated to an unit the previous association is discarded or ignored.

Specified by:
label in class UnitFormat
Parameters:
unit - the unit being labelled.
label - the new label for this unit.

alias

public void alias(Unit<?> unit,
                  java.lang.String alias)
Description copied from class: UnitFormat
Attaches a system-wide alias to this unit. Multiple aliases may be attached to the same unit. Aliases are used during parsing to recognize different variants of the same unit. For example:
     UnitFormat.getLocaleInstance().alias(METER.multiply(0.3048), "foot");
     UnitFormat.getLocaleInstance().alias(METER.multiply(0.3048), "feet");
     UnitFormat.getLocaleInstance().alias(METER, "meter");
     UnitFormat.getLocaleInstance().alias(METER, "metre");
 
If the specified label is already associated to an unit the previous association is discarded or ignored.

Specified by:
alias in class UnitFormat
Parameters:
unit - the unit being aliased.
alias - the alias attached to this unit.

isValidIdentifier

public boolean isValidIdentifier(java.lang.String name)
Description copied from class: UnitFormat
Indicates if the specified name can be used as unit identifier.

Specified by:
isValidIdentifier in class UnitFormat
Parameters:
name - the identifier to be tested.
Returns:
true if the name specified can be used as label or alias for this format;false otherwise.

nameFor

public java.lang.String nameFor(Unit<?> unit)

unitFor

public Unit<?> unitFor(java.lang.String name)

parseSingleUnit

public Unit<? extends Quantity> parseSingleUnit(java.lang.CharSequence csq,
                                                java.text.ParsePosition pos)
                                         throws java.text.ParseException
Description copied from class: UnitFormat
Parses a sequence of character to produce a single unit.

Specified by:
parseSingleUnit in class UnitFormat
Parameters:
csq - the CharSequence to parse.
pos - an object holding the parsing index and error position.
Returns:
an Unit parsed from the character sequence.
Throws:
java.text.ParseException

parseProductUnit

public Unit<? extends Quantity> parseProductUnit(java.lang.CharSequence csq,
                                                 java.text.ParsePosition pos)
                                          throws java.text.ParseException
Description copied from class: UnitFormat
Parses a sequence of character to produce a unit or a rational product of unit.

Specified by:
parseProductUnit in class UnitFormat
Parameters:
csq - the CharSequence to parse.
pos - an object holding the parsing index and error position.
Returns:
an Unit parsed from the character sequence.
Throws:
java.text.ParseException

format

public java.lang.Appendable format(Unit<?> unit,
                                   java.lang.Appendable appendable)
                            throws java.io.IOException
Description copied from class: UnitFormat
Formats the specified unit.

Specified by:
format in class UnitFormat
Parameters:
unit - the unit to format.
appendable - the appendable destination.
Throws:
java.io.IOException - if an error occurs.

JScience v4.3

Copyright © 2006 JScience.