Package com.luciad.text
Class TLcdSpeedFormat
java.lang.Object
java.text.Format
com.luciad.text.TLcdSpeedFormat
- All Implemented Interfaces:
ILcdFormatter
,ILcdParser
,Serializable
,Cloneable
Parses and formats speeds. More specifically:
- it parses a string containing speeds 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 'user' unit
Example for user unit 'TLcdSpeedUnit.MS
' and program unit 'TLcdSpeedUnit.KmH
'
- Parsing '1000 m/s' will result in 3600 (km/h)
- Formatting '50' (km/h) will result in '13.89 m/s'
By using the ParsePosition, a string containing more than one speed can be parsed too. For instance, this string contains three speeds:" 12m/s 120km/h 120some text"It can be parsed by calling parse three times with the same parse position instance. The parse position will be just before "some text". A speed format configured with m/s as its program unit and km/h as its display unit will parse the following speeds, all in m/s: 12, 33.33..., and 33.33... A subsequent parse will return
null
, because "some text" cannot be parsed.- See Also:
-
Nested Class Summary
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 speed.static final int
Indicates the field containing the unit short name. -
Constructor Summary
ConstructorDescriptionTLcdSpeedFormat
(TLcdSpeedUnit aDisplayUnit) Create a speed format with
program unit:TTLcdSpeedUnit.MS
TLcdSpeedFormat
(TLcdSpeedUnit aProgramUnit, TLcdSpeedUnit aDisplayUnit) Create a speed format. -
Method Summary
Modifier and TypeMethodDescriptionclone()
format
(Object aObject, StringBuffer aStringBufferToAppendTo, FieldPosition aFieldPosition) formatSpeed
(double aSpeed) Format the speed as a String given the speed as a double (in program unit).formatSpeed
(double aSpeed, StringBuffer aToAppendToSFCT) Format the speed (in program unit) as a String and append to the given StringBuffer.formatSpeed
(double aSpeed, StringBuffer aToAppendToSFCT, FieldPosition aFieldPosition) Formats the given speed and appends that to the given string buffer.Returns the display unit.int
Returns the number of fraction digits used to format a speed.Returns the string used for NaN values.Returns the program unit.boolean
Returnstrue
if format will add the unit short name,false
otherwise.Parses a givenString
and creates a newObject
with the corresponding type/properties.parseObject
(String aString, ParsePosition aParsePosition) double
parseSpeed
(String aSpeedString) Returns the speed (in program unit) given a speed as a string (in display unit).double
parseSpeed
(String aSpeedString, ParsePosition aParsePosition) Returns the speed (in program unit) given a speed as a string (in display unit).void
setAddUnitShortName
(boolean aAddUnitShortName) Sets if format should add the unit short name.void
setDisplayUnit
(TLcdSpeedUnit aDisplayUnit) Sets the display unit.void
setFractionDigits
(int aFractionDigitCount) Sets the number of fraction digits that should be used when formatting a speed.void
setNaNString
(String aNaNString) Sets the string that should be used for NaN values.void
setProgramUnit
(TLcdSpeedUnit aProgramUnit) Sets the program unit.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 speed. It is, the speed 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
-
TLcdSpeedFormat
public TLcdSpeedFormat() -
TLcdSpeedFormat
Create a speed format with
program unit:TTLcdSpeedUnit.MS
-
TLcdSpeedFormat
Create a speed format.
-
-
Method Details
-
getProgramUnit
Returns the program unit.- Returns:
- the program unit.
- See Also:
-
setProgramUnit
Sets the program unit. Format will assume the given speed 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.Format.parseObject(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.- 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:
-
getFractionDigits
public int getFractionDigits()Returns the number of fraction digits used to format a speed.- Returns:
- the number of fraction digits used to format a speed.
- See Also:
-
setFractionDigits
public void setFractionDigits(int aFractionDigitCount) Sets the number of fraction digits that should be used when formatting a speed.- 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:
-
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
-
formatSpeed
Format the speed as a String given the speed as a double (in program unit).- Parameters:
aSpeed
- the speed as a double (in program unit).- Returns:
- the String representation of the speed.
-
formatSpeed
Format the speed (in program unit) as a String and append to the given StringBuffer.- Parameters:
aSpeed
- the speed as a double (in program unit).aToAppendToSFCT
- The string buffer to append to.- Returns:
- The given StringBuffer: aToAppendToSFCT
-
formatSpeed
public StringBuffer formatSpeed(double aSpeed, StringBuffer aToAppendToSFCT, FieldPosition aFieldPosition) Formats the given speed and appends that to the given string buffer. The speed (in program unit) will be converted to display unit.- Parameters:
aSpeed
- Must be instance of Number.aToAppendToSFCT
- The string buffer where the formatted speed 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
-
parseSpeed
Returns the speed (in program unit) given a speed as a string (in display unit).- Parameters:
aSpeedString
- The string to parse, assumed to be in the display unit.- Returns:
- A Double with the speed converted to the program unit.
- Throws:
ParseException
- If the given string cannot be parsed.
-
parseSpeed
Returns the speed (in program unit) given a speed as a string (in display unit).- Parameters:
aSpeedString
- The string to parse, assumed to be in the display unit.aParsePosition
- The position to start the parsing at.- Returns:
- A Double with the speed converted to the program unit.
- Throws:
ParseException
- If the given string cannot be parsed.
-
toString
-
clone
-