Package com.luciad.text
Class TLcdDurationFormat
java.lang.Object
java.text.Format
com.luciad.text.TLcdDurationFormat
- All Implemented Interfaces:
Serializable,Cloneable
Format which handles ILcdISO19103Measure instances
which have a unit of measure
with measure type
TLcdISO19103MeasureTypeCodeExtension.DURATION
Days {DaysTextSeparator} Hours {HoursTextSeparator} Minutes {MinutesTextSeparator} Seconds {SecondsTextSeparator} TrimOption
where:
-
Days can be:
- d : to be displayed for values > 0 and not when equal to 0
- D : to be always displayed, even when equal to 0
- Nothing, in order to not be displayed at all
-
Hours can be:
- h : to be displayed for values > 0 and not when equal to 0
- H : to be always displayed, even when equal to 0
- Nothing, in order to not be displayed at all
-
Minutes can be:
- m : to be displayed for values > 0 and not when equal to 0
- M : to be always displayed, even when equal to 0
- Nothing, in order to not be displayed at all
-
Seconds can be:
- s : to be displayed for values > 0 and not when equal to 0
- S : to be always displayed, even when equal to 0
- Nothing, in order to not be displayed at all
Each character can be repeated several times in order to force preceding zeros for small values. For example, 'sss' will add preceding zeros to the value in order to reach a length of 3 characters. No zero is added if the length of the value is 3 or more. The same applies for capitalized letters.
-
DaysTextSeparator, HoursTextSeparator, MinutesTextSeparator and SecondsTextSeparator are strings that represent the different separators.
Their format is {<separator>}.
A distinction between the singular and the plural versions can also be made by separating them with a ":", such as {hour:hours}, {Tag:Tage}, {seconde:secondes},...
A white-space only separator is currently not supported. -
The last of the Days, Hours, Minutes or Seconds items can be represented with decimals using <item>.NumberOfDecimalsOfLastDisplayed, which can be:
- fff...: to be displayed when the decimals are present
- FFF....: to be displayed even when the decimals are equal to zero
-
TrimOption is an optional parameter that can be:
-
TL: To trim the left part of the expression, removing the starting items equal to 0, if present -
TR: To trim the right part of the expression, removing the ending items equal to 0, if present -
TLR: to trim both left and right
-
Usage example
Parsing
TLcdDurationFormat format = new TLcdDurationFormat(TLcdDurationFormat.NON_ZERO_ONLY);
ILcdISO19103Measure measure = (ILcdISO19103Measure) format.parseObject("3h 0m 10s");
Formatting
ILcdISO19103Measure measure = new TLcdISO19103Measure(3.4, TLcdUnitOfMeasureFactory.DURATION_SECONDS);
String formatted = format.format(measure);
Pattern example
| Pattern | Result |
|---|---|
d {d} h {hour :hours } s.ff {second:seconds} |
3hours 10.40seconds |
s.f {s} |
10,810.4s |
m.FFF {minute:minutes} |
180.173minutes |
h {heures} |
3heures |
dd {d } HHH {h} |
003h |
DD {d : days} HH {h :hours } MM {m :minutes} |
00d 03hours 00m |
DD {d : days} HH {h :hours } MM {m :minutes} TL |
03hours 00m |
DD {d : days} HH {h :hours } MM {m :minutes} TR |
00d 03hours |
DD {d : days} HH {h :hours } MM {m :minutes} TLR |
03hours |
- Since:
- 2017.1
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.text.Format
Format.Field -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringSame asMINIMUM_PATTERNbut with longer separators, with a distinction between the singular form and the plural one.
d {day :days } h {hour :hours } m {minute :minutes } s.f {second :seconds }static final StringThis pattern only displays the items with a value above 0.
d {d } h {h } m {m } s.f {s}static final StringThis pattern displays every element and trims the expression left and right the values equal to 0.
DD {d } HH {h } MM {m } SS.f {s} TLR -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newTLcdDurationFormatthat will use a default pattern and Locale.TLcdDurationFormat(String aPattern) Creates a newTLcdDurationFormatthat will use the specified pattern and a default Locale.TLcdDurationFormat(String aPattern, Locale aLocale) Creates a newTLcdDurationFormatthat will use the specified pattern and the specified locale. -
Method Summary
Modifier and TypeMethodDescriptionbooleanformat(Object aObject, StringBuffer toAppendTo, FieldPosition pos) Returns the pattern used to format Strings intoILcdISO19103Measureinstances.inthashCode()parseObject(String aSource, ParsePosition pos) toString()Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
-
Field Details
-
MINIMUM_PATTERN
This pattern only displays the items with a value above 0.
d {d } h {h } m {m } s.f {s}- See Also:
-
LONG_SEPARATORS_PATTERN
Same asMINIMUM_PATTERNbut with longer separators, with a distinction between the singular form and the plural one.
d {day :days } h {hour :hours } m {minute :minutes } s.f {second :seconds }- See Also:
-
NON_ZERO_ONLY
This pattern displays every element and trims the expression left and right the values equal to 0.
DD {d } HH {h } MM {m } SS.f {s} TLR- See Also:
-
-
Constructor Details
-
TLcdDurationFormat
public TLcdDurationFormat()Creates a newTLcdDurationFormatthat will use a default pattern and Locale. -
TLcdDurationFormat
Creates a newTLcdDurationFormatthat will use the specified pattern and a default Locale.- Parameters:
aPattern- is the string representing the formatting pattern, as defined in the class documentation.- Throws:
IllegalArgumentException- WhenaPatternis not a valid pattern.NullPointerException- whenaPatternis null.
-
TLcdDurationFormat
Creates a newTLcdDurationFormatthat will use the specified pattern and the specified locale.- Parameters:
aPattern- is the string representing the formatting pattern, as defined in the class documentation.aLocale- theLocaleto be used to parse and format.- Throws:
IllegalArgumentException- WhenaPatternis not a valid pattern.NullPointerException- whenaPatternoraLocaleis null.
-
-
Method Details
-
getPattern
Returns the pattern used to format Strings intoILcdISO19103Measureinstances.- Returns:
- the pattern as a string.
-
format
-
parseObject
- Specified by:
parseObjectin classFormat
-
equals
-
hashCode
public int hashCode() -
toString
-