public class TLcdSpeedFormat extends Format implements Serializable, ILcdFormatter, ILcdParser
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.Format.Field
Modifier and Type | Field and Description |
---|---|
static int |
NUMBER_FIELD
Indicates the field containing the number of the speed.
|
static int |
UNIT_FIELD
Indicates the field containing the unit short name.
|
Constructor and Description |
---|
TLcdSpeedFormat()
|
TLcdSpeedFormat(TLcdSpeedUnit aDisplayUnit)
Create a speed format with
program unit: TTLcdSpeedUnit.MS |
TLcdSpeedFormat(TLcdSpeedUnit aProgramUnit,
TLcdSpeedUnit aDisplayUnit)
Create a speed format.
|
Modifier and Type | Method and Description |
---|---|
Object |
clone() |
StringBuffer |
format(Object aObject,
StringBuffer aStringBufferToAppendTo,
FieldPosition aFieldPosition) |
String |
formatSpeed(double aSpeed)
Format the speed as a String given the speed as a double (in program unit).
|
StringBuffer |
formatSpeed(double aSpeed,
StringBuffer aToAppendToSFCT)
Format the speed (in program unit) as a String and append to the given StringBuffer.
|
StringBuffer |
formatSpeed(double aSpeed,
StringBuffer aToAppendToSFCT,
FieldPosition aFieldPosition)
Formats the given speed and appends that to the given string buffer.
|
TLcdSpeedUnit |
getDisplayUnit()
Returns the display unit.
|
int |
getFractionDigits()
Returns the number of fraction digits used to format a speed.
|
String |
getNaNString()
Returns the string used for NaN values.
|
TLcdSpeedUnit |
getProgramUnit()
Returns the program unit.
|
boolean |
isAddUnitShortName()
Returns
true if format will add the unit short name, false otherwise. |
Object |
parse(String aString)
Parses a given
String and creates a new Object
with the corresponding type/properties. |
Object |
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.
|
String |
toString() |
format, formatToCharacterIterator, parseObject
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
format
public static final int NUMBER_FIELD
public static final int UNIT_FIELD
public TLcdSpeedFormat()
public TLcdSpeedFormat(TLcdSpeedUnit aDisplayUnit)
TTLcdSpeedUnit.MS
public TLcdSpeedFormat(TLcdSpeedUnit aProgramUnit, TLcdSpeedUnit aDisplayUnit)
public TLcdSpeedUnit getProgramUnit()
setProgramUnit(com.luciad.util.TLcdSpeedUnit)
public void setProgramUnit(TLcdSpeedUnit aProgramUnit)
aProgramUnit
- The program unit.getProgramUnit()
public TLcdSpeedUnit getDisplayUnit()
setDisplayUnit(com.luciad.util.TLcdSpeedUnit)
public void setDisplayUnit(TLcdSpeedUnit aDisplayUnit)
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.aDisplayUnit
- The display unit.getDisplayUnit()
public boolean isAddUnitShortName()
true
if format will add the unit short name, false
otherwise.true
if format will add the unit short name, false
otherwise.setAddUnitShortName(boolean)
public void setAddUnitShortName(boolean aAddUnitShortName)
aAddUnitShortName
- true
if unit short name should be added, false
otherwise.isAddUnitShortName()
public int getFractionDigits()
setFractionDigits(int)
public void setFractionDigits(int aFractionDigitCount)
aFractionDigitCount
- The number of fraction digits.getFractionDigits()
public String getNaNString()
setNaNString(String)
public void setNaNString(String aNaNString)
aNaNString
- the string to use.getNaNString()
public StringBuffer format(Object aObject, StringBuffer aStringBufferToAppendTo, FieldPosition aFieldPosition)
public Object parse(String aString) throws IllegalArgumentException
ILcdParser
String
and creates a new Object
with the corresponding type/properties.parse
in interface ILcdParser
aString
- the String
to be parsed.Object
.IllegalArgumentException
- if the String
can't be parsed.public Object parseObject(String aString, ParsePosition aParsePosition)
parseObject
in class Format
public String formatSpeed(double aSpeed)
aSpeed
- the speed as a double (in program unit).public StringBuffer formatSpeed(double aSpeed, StringBuffer aToAppendToSFCT)
aSpeed
- the speed as a double (in program unit).aToAppendToSFCT
- The string buffer to append to.public StringBuffer formatSpeed(double aSpeed, StringBuffer aToAppendToSFCT, FieldPosition aFieldPosition)
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.public double parseSpeed(String aSpeedString) throws ParseException
aSpeedString
- The string to parse, assumed to be in the display unit.ParseException
- If the given string cannot be parsed.public double parseSpeed(String aSpeedString, ParsePosition aParsePosition) throws ParseException
aSpeedString
- The string to parse, assumed to be in the display unit.aParsePosition
- The position to start the parsing at.ParseException
- If the given string cannot be parsed.