public final class TLcdAngleFormat extends Format
Parses and formats angles. More specifically:
Example for display unit 'TLcdAngleUnit.DEGREE
' and program unit 'TLcdAngleUnit.RADIANS
'
By using the ParsePosition, a string containing more than one angle can be parsed too. For instance, the example below parses four angles:
String inputData = " 120\u00B0 3200mil 360 300some text";
TLcdAngleFormat angleFormat = new TLcdAngleFormat();
angleFormat.setProgramUnit(TLcdAngleUnit.DEGREE);
angleFormat.setDisplayUnit(TLcdAngleUnit.DEGREE);
ParsePosition parsePosition = new ParsePosition(0);
Double value1 = (Double) angleFormat.parseObject(inputData, parsePosition); // 120
Double value2 = (Double) angleFormat.parseObject(inputData, parsePosition); // 180
Double value3 = (Double) angleFormat.parseObject(inputData, parsePosition); // 360
Double value4 = (Double) angleFormat.parseObject(inputData, parsePosition); // 300
The resulting values will be 120, 180, 360, and 300.
A subsequent parse will return null
, because "some text" cannot be parsed.
For
it is also possible to specify a custom display format.
E.g. TLcdAngleUnit.DEGREE
DDDMMSS
to have angles formatted as 000°00'00"
After setting the display unit to DEGREE using setDisplayUnit(TLcdAngleUnit.DEGREE)
you can set
setCustomDegreeDisplayPattern(TLcdAngleFormat.DDDMMSS)
.
TLcdAngleFormat angleFormat = new TLcdAngleFormat(TLcdAngleUnit.DEGREE, TLcdAngleUnit.DEGREE);
angleFormat.setCustomDegreeDisplayPattern(TLcdAngleFormat.DDDMMSS);
String valueFormatted = angleFormat.format(123.4687); // 123°28'07"
Note that all measurements are formatted/parsed as is and won't be normalized to an interval such as
[-180, 180] or [0, 360].
E.g. parsing "400°" will return 400 should the program unit be set to TLcdAngleUnit.DEGREE
Format.Field
Modifier and Type | Field and Description |
---|---|
static String |
DDD
Custom display pattern 000° (can only be used for display unit
TLcdAngleUnit.DEGREE ) |
static String |
DDDd
Custom display pattern 000.0° (can only be used for display unit
TLcdAngleUnit.DEGREE ) |
static String |
DDDdd
Custom display pattern 000.00° (can only be used for display unit
TLcdAngleUnit.DEGREE ) |
static String |
DDDddd
Custom display pattern 000.000° (can only be used for display unit
TLcdAngleUnit.DEGREE ) |
static String |
DDDdddd
Custom display pattern 000.0000° (can only be used for display unit
TLcdAngleUnit.DEGREE ) |
static String |
DDDddddd
Custom display pattern 000.00000° (can only be used for display unit
TLcdAngleUnit.DEGREE ) |
static String |
DDDdddddd
Custom display pattern 000.000000° (can only be used for display unit
TLcdAngleUnit.DEGREE ) |
static String |
DDDddddddd
Custom display pattern 000.0000000° (can only be used for display unit
TLcdAngleUnit.DEGREE ) |
static String |
DDDdddddddd
Custom display pattern 000.00000000° (can only be used for display unit
TLcdAngleUnit.DEGREE ) |
static String |
DDDMMSS
Custom display pattern 000°00'00" (can only be used for display unit
TLcdAngleUnit.DEGREE ) |
static String |
DDDMMSSss
Custom display pattern 000°00'00.00" (can only be used for display unit
TLcdAngleUnit.DEGREE ) |
Constructor and Description |
---|
TLcdAngleFormat()
Create an angle format with
display unit:
TLcdAngleUnit.DEGREE
program unit: TLcdAngleUnit.DEGREE
|
TLcdAngleFormat(TLcdAngleUnit aDisplayUnit)
Create an angle format with
program unit: TLcdAngleUnit.DEGREE
and the given display unit
|
TLcdAngleFormat(TLcdAngleUnit aProgramUnit,
TLcdAngleUnit aDisplayUnit)
Create an angle format with the given program unit and display unit.
|
Modifier and Type | Method and Description |
---|---|
Object |
clone() |
StringBuffer |
format(Object aObject,
StringBuffer aStringBufferToAppendTo,
FieldPosition aFieldPosition) |
String |
getCustomDegreeDisplayPattern()
Get the custom display pattern for degrees.
|
TLcdAngleUnit |
getDisplayUnit()
Returns the display unit.
|
int |
getMaximumFractionDigits()
Returns the maximum number of fraction digits used to format an angle.
|
int |
getMinimumFractionDigits()
Returns the minimum number of fraction digits used to format an angle.
|
TLcdAngleUnit |
getProgramUnit()
Returns the program unit.
|
boolean |
isAddUnitShortName()
Returns
true if format will add the unit short name, false otherwise. |
Object |
parseObject(String aString,
ParsePosition aParsePosition) |
void |
setAddUnitShortName(boolean aAddUnitShortName)
Sets if format should add the unit short name.
|
void |
setCustomDegreeDisplayPattern(String aDegreePattern)
Set a custom display format for degrees.
|
void |
setDisplayUnit(TLcdAngleUnit aDisplayUnit)
Sets the display unit.
|
void |
setMaximumFractionDigits(int aFractionDigitCount)
Sets the maximum number of fraction digits that should be used when formatting an angle.
|
void |
setMinimumFractionDigits(int aFractionDigitCount)
Sets the minimum number of fraction digits that should be used when formatting an angle.
|
void |
setProgramUnit(TLcdAngleUnit aProgramUnit)
Sets the program unit.
|
String |
toString() |
format, formatToCharacterIterator, parseObject
public static final String DDD
TLcdAngleUnit.DEGREE
)public static final String DDDMMSS
TLcdAngleUnit.DEGREE
)public static final String DDDMMSSss
TLcdAngleUnit.DEGREE
)public static final String DDDd
TLcdAngleUnit.DEGREE
)public static final String DDDdd
TLcdAngleUnit.DEGREE
)public static final String DDDddd
TLcdAngleUnit.DEGREE
)public static final String DDDdddd
TLcdAngleUnit.DEGREE
)public static final String DDDddddd
TLcdAngleUnit.DEGREE
)public static final String DDDdddddd
TLcdAngleUnit.DEGREE
)public static final String DDDddddddd
TLcdAngleUnit.DEGREE
)public static final String DDDdddddddd
TLcdAngleUnit.DEGREE
)public TLcdAngleFormat()
TLcdAngleUnit.DEGREE
TLcdAngleUnit.DEGREE
public TLcdAngleFormat(TLcdAngleUnit aDisplayUnit)
TLcdAngleUnit.DEGREE
aDisplayUnit
- the display unitpublic TLcdAngleFormat(TLcdAngleUnit aProgramUnit, TLcdAngleUnit aDisplayUnit)
aProgramUnit
- the program unitaDisplayUnit
- the display unitpublic TLcdAngleUnit getProgramUnit()
setProgramUnit(TLcdAngleUnit)
public void setProgramUnit(TLcdAngleUnit aProgramUnit)
aProgramUnit
- The program unit.getProgramUnit()
public TLcdAngleUnit getDisplayUnit()
setDisplayUnit(TLcdAngleUnit)
public void setDisplayUnit(TLcdAngleUnit 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)
TLcdAngleUnit.DEGREE
aAddUnitShortName
- true
if unit short name should be added, false
otherwise.isAddUnitShortName()
public int getMinimumFractionDigits()
setMinimumFractionDigits(int)
public void setMinimumFractionDigits(int aFractionDigitCount)
TLcdAngleUnit.DEGREE
aFractionDigitCount
- The number of fraction digits.getMinimumFractionDigits()
public int getMaximumFractionDigits()
setMaximumFractionDigits(int)
public void setMaximumFractionDigits(int aFractionDigitCount)
TLcdAngleUnit.DEGREE
aFractionDigitCount
- The number of fraction digits.getMaximumFractionDigits()
public String getCustomDegreeDisplayPattern()
setCustomDegreeDisplayPattern(String)
public void setCustomDegreeDisplayPattern(String aDegreePattern)
Symbol | Meaning | Example |
---|---|---|
d | Integer degrees | 354 |
D | Integer degrees with degrees symbol | 354° |
m | Integer minutes | 54 |
M | Integer minutes with minutes symbol | 54' |
s | Integer seconds | 54 |
S | Integer seconds with seconds symbol | 54" |
+ | Coordinate sign. Results in a '-' if the coordinate is negative | - |
Example display patterns are provided e.g. DDD
or DDDMMSS
In order for the custom display format to be used the display unit should be set to
using
TLcdAngleUnit.DEGREE
setDisplayUnit
.
aDegreePattern
- the pattern to be used when formatting degrees or null when no custom pattern should be usedgetCustomDegreeDisplayPattern()
public StringBuffer format(Object aObject, StringBuffer aStringBufferToAppendTo, FieldPosition aFieldPosition)
public Object parseObject(String aString, ParsePosition aParsePosition)
parseObject
in class Format