Class PeriodStringConverter
- All Implemented Interfaces:
Serializable,StringConverter<Period>
An implementation of
StringConverter
for
Period
values.
While the method
toString(Period)
simply uses
Period.toString(),
the method
fromString(CharSequence)
uses
Period.parse(CharSequence)
to create the Period instance for the given value. The formats
accepted are based on the ISO-8601 period formats PnYnMnD and
PnW.
The string starts with an optional sign, denoted by the ASCII negative ('-') or positive ('+') symbol. If negative, the whole period is negated.
The ASCII letter "P" is next in upper or lower case.
There are then four sections, each consisting of a number and a suffix. At least one of the four sections must be present.
The sections have suffixes in ASCII of "Y", "M", "W" and "D" for years, months, weeks and days, accepted in upper or lower case.
The suffixes must occur in order. The number part of each section must
consist of ASCII digits. The number may be prefixed by the ASCII negative
or positive symbol. The number must parse to an int.
- Notes:
-
- The leading plus/minus sign, and negative values for other units are not originally part of the ISO-8601 standard.
- In addition, ISO-8601 does not permit mixing between the
PnYnMnDandPnWformats. Any week-based input is multiplied by 7 and treated as a number of days.
- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: PeriodStringConverter.java 1060 2023-09-24 19:21:40Z tquadrat $
- Since:
- 0.0.7
- See Also:
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.util.stringconverter.PeriodStringConverter"
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PeriodStringConverterAn instance of this class.static final StringThe error message for an invalid period String: "\'%1$s\' cannot be parsed as a valid period".Fields inherited from interface org.tquadrat.foundation.lang.StringConverter
METHOD_NAME_GetSubjectClass, METHOD_NAME_Provider -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal PeriodfromString(CharSequence source) static final PeriodStringConverterprovider()This method is used by theServiceLoaderto obtain the instance for thisStringConverterimplementation.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.tquadrat.foundation.lang.StringConverter
toString
-
Field Details
-
MSG_InvalidPeriod
The error message for an invalid period String: "\'%1$s\' cannot be parsed as a valid period".- See Also:
-
INSTANCE
An instance of this class.
-
-
Constructor Details
-
PeriodStringConverter
public PeriodStringConverter()Creates a new instance ofPeriodStringConverter.
-
-
Method Details
-
fromString
- Specified by:
fromStringin interfaceStringConverter<Period>- Throws:
IllegalArgumentException
-
provider
This method is used by theServiceLoaderto obtain the instance for thisStringConverterimplementation.- Returns:
- The instance for this
StringConverterimplementation.
-
