Package com.luciad.text
Class TLcdAltitudeFormat
java.lang.Object
java.text.Format
com.luciad.text.TLcdAltitudeFormat
- All Implemented Interfaces:
ILcdFormatter
,ILcdParser
,Serializable
,Cloneable
Parses and formats altitudes. More specifically:
- it parses a string containing altitudes in any unit (or without any unit) into doubles of the chosen 'program' unit
- it formats a double of the given 'program' unit into a String containing the chosen 'display' unit
Example for display unit 'TLcdAltitudeUnit.METRE
' and program unit 'TLcdAltitudeUnit.KM
'
- Parsing '1000 m' will result in 1 (km)
- Formatting '20' (km) will result in '20000 m'
By using the ParsePosition, a string containing more than one altitude can be parsed too. For instance, this string contains four altitudes:
" 200m 1000 1500ft300some text"It can be parsed by calling parse four times with the same parse position instance. The parse position will be just before "some text". An altitude format configured with meter as its program unit and ft as its display unit will parse the following altitudes, all in meter: 200, 304.8, 457.2, and 91.44. A subsequent parse will return
null
, because "some text" cannot be parsed.- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Describes the alignment of the unit with respect to the altitude value.Nested classes/interfaces inherited from class java.text.Format
Format.Field
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Indicates the field containing the number of the altitude.static final int
Indicates the field containing the unit short name. -
Constructor Summary
ConstructorDescriptionCreate an altitude format with
display unit:TLcdAltitudeUnit.METRE
program unit:TLcdAltitudeUnit.METRE
TLcdAltitudeFormat
(TLcdAltitudeUnit aDisplayUnit) Create an altitude format with
program unit:TLcdAltitudeUnit.METRE
TLcdAltitudeFormat
(TLcdAltitudeUnit aProgramUnit, TLcdAltitudeUnit aDisplayUnit) Create an altitude format. -
Method Summary
Modifier and TypeMethodDescriptionclone()
format
(Object aObject, StringBuffer aStringBufferToAppendTo, FieldPosition aFieldPosition) formatAltitude
(double aAltitude) Format the altitude as a String given the altitude as a double (in program unit).formatAltitude
(double aAltitude, StringBuffer aToAppendToSFCT) Format the altitude (in program unit) as a String and append to the given StringBuffer.formatAltitude
(double aAltitude, StringBuffer aToAppendToSFCT, FieldPosition aFieldPosition) Formats the given altitude and appends that to the given string buffer.Returns the display unit.int
Returns the number of fraction digits used to format the measurement.Returns the string used for NaN values.Returns the program unit.Returns how the unit short name is aligned.boolean
Returnstrue
if format will add the unit short name,false
otherwise.Parses a givenString
and creates a newObject
with the corresponding type/properties.double
parseAltitude
(String aAltitudeString) Returns the altitude (in program unit) given a altitude as a string (in display unit).double
parseAltitude
(String aAltitudeString, ParsePosition aParsePosition) Returns the altitude (in program unit) given a altitude as a string (in display unit).parseObject
(String aString, ParsePosition aParsePosition) void
setAddUnitShortName
(boolean aAddUnitShortName) Sets if format should add the unit short name.void
setDisplayUnit
(TLcdAltitudeUnit aDisplayUnit) Sets the display unit.void
setFractionDigits
(int aFractionDigitCount) Sets the number of fraction digits that should be used when formatting the measurement.void
setNaNString
(String aNaNString) Sets the string that should be used for NaN values.void
setProgramUnit
(TLcdAltitudeUnit aProgramUnit) Sets the program unit.void
setUnitAlignment
(TLcdAltitudeFormat.Alignment aUnitAlignment) Sets how the unit short name is aligned in the formatted altitude.toString()
Methods inherited from class java.text.Format
format, formatToCharacterIterator, parseObject
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.luciad.util.ILcdFormatter
format
-
Field Details
-
NUMBER_FIELD
public static final int NUMBER_FIELDIndicates the field containing the number of the altitude. It is, the altitude without the unit short name. Use format with a FieldPosition with field NUMBER_FIELD to know the start and end index of the number.- See Also:
-
UNIT_FIELD
public static final int UNIT_FIELDIndicates the field containing the unit short name. Use format with a FieldPosition with field UNIT_FIELD to know the start and end index of the unit short name.- See Also:
-
-
Constructor Details
-
TLcdAltitudeFormat
public TLcdAltitudeFormat()Create an altitude format with
display unit:TLcdAltitudeUnit.METRE
program unit:TLcdAltitudeUnit.METRE
-
TLcdAltitudeFormat
Create an altitude format with
program unit:TLcdAltitudeUnit.METRE
-
TLcdAltitudeFormat
Create an altitude format.
-
-
Method Details
-
getProgramUnit
Returns the program unit.- Returns:
- the program unit.
- See Also:
-
setProgramUnit
Sets the program unit. Format will assume the given altitude is in this unit. Parse will convert the parsed number to this unit.- Parameters:
aProgramUnit
- The program unit.- See Also:
-
getDisplayUnit
Returns the display unit.- Returns:
- the display unit.
- See Also:
-
setDisplayUnit
Sets the display unit.Format.format(Object)
will convert the given measurement to this unit.parse(String)
will detect and parse the display unit as well as other units of the same measure type. When no unit name is provided the format assumes the value is in the display unit.- Parameters:
aDisplayUnit
- The display unit.Changing the display unit will reset the following properties to a default that is appropriate for the unit:
- See Also:
-
isAddUnitShortName
public boolean isAddUnitShortName()Returnstrue
if format will add the unit short name,false
otherwise.- Returns:
true
if format will add the unit short name,false
otherwise.- See Also:
-
setAddUnitShortName
public void setAddUnitShortName(boolean aAddUnitShortName) Sets if format should add the unit short name. Note that parsing ignores this setting.- Parameters:
aAddUnitShortName
-true
if unit short name should be added,false
otherwise.- See Also:
-
getUnitAlignment
Returns how the unit short name is aligned.- Returns:
- one of
TLcdAltitudeFormat.Alignment.LEFT
orTLcdAltitudeFormat.Alignment.RIGHT
- See Also:
-
setUnitAlignment
Sets how the unit short name is aligned in the formatted altitude.- Parameters:
aUnitAlignment
- one ofTLcdAltitudeFormat.Alignment.LEFT
orTLcdAltitudeFormat.Alignment.RIGHT
- See Also:
-
getFractionDigits
public int getFractionDigits()Returns the number of fraction digits used to format the measurement. This is the same value as thegetMinimumFractionDigits
returns.- Returns:
- the number of fraction digits used to format the measurement.
- See Also:
-
setFractionDigits
public void setFractionDigits(int aFractionDigitCount) Sets the number of fraction digits that should be used when formatting the measurement. This sets both the minimum and the maximum fraction digits.- Parameters:
aFractionDigitCount
- The number of fraction digits.- See Also:
-
getNaNString
Returns the string used for NaN values.- Returns:
- the string used for NaN values.
- See Also:
-
setNaNString
Sets the string that should be used for NaN values.- Parameters:
aNaNString
- the string to use.- See Also:
-
formatAltitude
Format the altitude as a String given the altitude as a double (in program unit).- Parameters:
aAltitude
- the altitude as a double (in program unit).- Returns:
- the String representation of the altitude.
-
formatAltitude
Format the altitude (in program unit) as a String and append to the given StringBuffer.- Parameters:
aAltitude
- the altitude as a double (in program unit).aToAppendToSFCT
- The string buffer to append to.- Returns:
- The given StringBuffer: aToAppendToSFCT
-
formatAltitude
public StringBuffer formatAltitude(double aAltitude, StringBuffer aToAppendToSFCT, FieldPosition aFieldPosition) Formats the given altitude and appends that to the given string buffer. The altitude (in program unit) will be converted to display unit.- Parameters:
aAltitude
- Must be instance of Number.aToAppendToSFCT
- The string buffer where the formatted altitude will be appended to.aFieldPosition
- NUMBER_FIELD or USER_FIELD. Can be used to retrieve the indices of the unit or of the number.- Returns:
- The given StringBuffer: aStringBufferToAppendTo
-
parseAltitude
Returns the altitude (in program unit) given a altitude as a string (in display unit).- Parameters:
aAltitudeString
- The string to parse, assumed to be in the display unit.- Returns:
- A Double with the altitude converted to the program unit.
- Throws:
ParseException
- If the given string cannot be parsed.
-
parseAltitude
public double parseAltitude(String aAltitudeString, ParsePosition aParsePosition) throws ParseException Returns the altitude (in program unit) given a altitude as a string (in display unit).- Parameters:
aAltitudeString
- The string to parse, assumed to be in the display unit.aParsePosition
- The position to start the parsing at.- Returns:
- A Double with the altitude converted to the program unit.
- Throws:
ParseException
- If the given string cannot be parsed.
-
format
public StringBuffer format(Object aObject, StringBuffer aStringBufferToAppendTo, FieldPosition aFieldPosition) -
parse
Description copied from interface:ILcdParser
Parses a givenString
and creates a newObject
with the corresponding type/properties.- Specified by:
parse
in interfaceILcdParser
- Parameters:
aString
- theString
to be parsed.- Returns:
- the resulting new
Object
. - Throws:
IllegalArgumentException
- if theString
can't be parsed.
-
parseObject
- Specified by:
parseObject
in classFormat
-
toString
-
clone
-