Package org.joda.time.convert
Class StringConverter
- java.lang.Object
-
- org.joda.time.convert.AbstractConverter
-
- org.joda.time.convert.StringConverter
-
- All Implemented Interfaces:
Converter
,DurationConverter
,InstantConverter
,IntervalConverter
,PartialConverter
,PeriodConverter
class StringConverter extends AbstractConverter implements InstantConverter, PartialConverter, DurationConverter, PeriodConverter, IntervalConverter
StringConverter converts from a String to an instant, partial, duration, period or interval..- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static StringConverter
INSTANCE
Singleton instance.
-
Constructor Summary
Constructors Modifier Constructor Description protected
StringConverter()
Restricted constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
getDurationMillis(java.lang.Object object)
Gets the duration of the string using the standard type.long
getInstantMillis(java.lang.Object object, Chronology chrono)
Gets the millis, which is the ISO parsed string value.int[]
getPartialValues(ReadablePartial fieldSource, java.lang.Object object, Chronology chrono, DateTimeFormatter parser)
Extracts the values of the partial from an object of this converter's type.java.lang.Class<?>
getSupportedType()
Returns String.class.void
setInto(ReadWritableInterval writableInterval, java.lang.Object object, Chronology chrono)
Sets the value of the mutable interval from the string.void
setInto(ReadWritablePeriod period, java.lang.Object object, Chronology chrono)
Extracts duration values from an object of this converter's type, and sets them into the given ReadWritableDuration.-
Methods inherited from class org.joda.time.convert.AbstractConverter
getChronology, getChronology, getPartialValues, getPeriodType, isReadableInterval, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.joda.time.convert.InstantConverter
getChronology, getChronology
-
Methods inherited from interface org.joda.time.convert.IntervalConverter
isReadableInterval
-
Methods inherited from interface org.joda.time.convert.PartialConverter
getChronology, getChronology, getPartialValues
-
Methods inherited from interface org.joda.time.convert.PeriodConverter
getPeriodType
-
-
-
-
Field Detail
-
INSTANCE
static final StringConverter INSTANCE
Singleton instance.
-
-
Method Detail
-
getInstantMillis
public long getInstantMillis(java.lang.Object object, Chronology chrono)
Gets the millis, which is the ISO parsed string value.- Specified by:
getInstantMillis
in interfaceInstantConverter
- Overrides:
getInstantMillis
in classAbstractConverter
- Parameters:
object
- the String to convert, must not be nullchrono
- the chronology to use, non-null result of getChronology- Returns:
- the millisecond value
- Throws:
java.lang.IllegalArgumentException
- if the value if invalid
-
getPartialValues
public int[] getPartialValues(ReadablePartial fieldSource, java.lang.Object object, Chronology chrono, DateTimeFormatter parser)
Extracts the values of the partial from an object of this converter's type. This method checks if the parser has a zone, and uses it if present. This is most useful for parsing local times with UTC.- Specified by:
getPartialValues
in interfacePartialConverter
- Overrides:
getPartialValues
in classAbstractConverter
- Parameters:
fieldSource
- a partial that provides access to the fields. This partial may be incomplete and only getFieldType(int) should be usedobject
- the object to convertchrono
- the chronology to use, which is the non-null result of getChronology()parser
- the parser to use, may be null- Returns:
- the array of field values that match the fieldSource, must be non-null valid
- Throws:
java.lang.ClassCastException
- if the object is invalidjava.lang.IllegalArgumentException
- if the value if invalid- Since:
- 1.3
-
getDurationMillis
public long getDurationMillis(java.lang.Object object)
Gets the duration of the string using the standard type. This matches the toString() method of ReadableDuration.- Specified by:
getDurationMillis
in interfaceDurationConverter
- Parameters:
object
- the String to convert, must not be null- Returns:
- the millisecond duration
- Throws:
java.lang.ClassCastException
- if the object is invalid
-
setInto
public void setInto(ReadWritablePeriod period, java.lang.Object object, Chronology chrono)
Extracts duration values from an object of this converter's type, and sets them into the given ReadWritableDuration.- Specified by:
setInto
in interfacePeriodConverter
- Parameters:
period
- period to get modifiedobject
- the String to convert, must not be nullchrono
- the chronology to use- Throws:
java.lang.ClassCastException
- if the object is invalid
-
setInto
public void setInto(ReadWritableInterval writableInterval, java.lang.Object object, Chronology chrono)
Sets the value of the mutable interval from the string.- Specified by:
setInto
in interfaceIntervalConverter
- Parameters:
writableInterval
- the interval to setobject
- the String to convert, must not be nullchrono
- the chronology to use, may be null
-
getSupportedType
public java.lang.Class<?> getSupportedType()
Returns String.class.- Specified by:
getSupportedType
in interfaceConverter
- Returns:
- String.class
-
-