public class TimeFactory extends Object implements TimeDomain, TimePacker, TimeFormatter, TimeScanner
TimeIndex
objects and
acts as an immutable TimeDomain
.
A time domain is defined by the following 4 properties:
Resolution
,
BasePeriodPattern
,
SubPeriodPattern
BASE_YEAR_FOR_NANO, DAYS_TO_19700101, DAYS_TO_20000101
Constructor and Description |
---|
TimeFactory(TimeDomainDefinition def)
Constructor providing a default time formatter and time scanner.
|
TimeFactory(TimeDomainDefinition def,
TimeFormatter formatter)
Constructor providing a default time scanner.
|
TimeFactory(TimeDomainDefinition def,
TimeFormatter formatter,
TimeScanner scanner)
Construct a TimeFactory for the given time domain.
|
Modifier and Type | Method and Description |
---|---|
int |
compareResolutionTo(Resolution unit)
Return a negative, zero, positive number if the resolution is higher,
the same, or lower than the argument.
|
boolean |
equals(Object obj) |
String |
format(TimeParts timeParts)
Generate a string representing the time in the time parts object.
|
BasePeriodPattern |
getBasePeriodPattern()
Return the base period pattern.
|
int |
getBasePeriodSize()
Return the number of time points within a base period.
|
TimeIndex |
getBasePeriodStart(TimeIndex t)
Return the time index of the first time point in the base period containing
the time specified.
|
DayOfWeek |
getDayOfWeek(TimeIndex time)
Return the day of week for the given time.
|
TimeFormatter |
getFormatter()
Return the time formatter to use when formatting times in this domain.
|
String |
getLabel()
Return the label of the time domain, uniquely identifying the domain when
using a
TimeDomainCatalog . |
long |
getOrigin()
Return the origin of the time domain.
|
TimePacker |
getPacker()
Return the time packer to use for processing times in this domain.
|
Resolution |
getResolution()
Return the resolution of the time domain.
|
TimeScanner |
getScanner()
Return the time scanner to use when scanning strings as times in this domain.
|
SubPeriodPattern |
getSubPeriodPattern()
Return the sub period pattern.
|
int |
hashCode() |
TimeIndex |
maxTime()
Return a new TimeIndex giving the maximum time in this domain.
|
TimeIndex |
maxTime(boolean offsetCompatible)
Return a new TimeIndex giving the maximum time in this domain.
|
TimeIndex |
minTime()
Return a new TimeIndex giving the minimum time in this domain.
|
TimeIndex |
minTime(boolean offsetCompatible)
Return a new TimeIndex giving the minimum time in this domain.
|
long |
pack(TimeParts tp,
Adjustment adjust)
Pack the component elements of the time into a numeric time index.
|
void |
requireEquality(TimeDomain domain)
Throw an exception if the domain is not equal to this domain.
|
TimeParts |
scan(Resolution unit,
String time)
Scan the date string into a time parts object.
|
boolean |
similar(TimeDomain domain)
Compare to another time domain, ignoring label.
|
TimeIndex |
time(long index)
Return a new TimeIndex corresponding to the given index.
|
TimeIndex |
time(long year,
int month,
int day,
int hour,
int min,
int sec,
int usec,
Adjustment adjust)
Return a new TimeIndex corresponding to the list of parameters.
|
TimeIndex |
time(String date)
Return a new TimeIndex corresponding to the given date string.
|
TimeIndex |
time(String date,
Adjustment adjust)
Return a new TimeIndex corresponding to the given date string.
|
TimeIndex |
timeFromOffset(long offset)
Return a new TimeIndex corresponding to the given offset.
|
String |
toString() |
TimeParts |
unpack(long time)
Unpack the numeric representation of time into its component elements.
|
boolean |
valid(long t,
boolean testOnly)
Return true if the numeric time index is valid for the domain.
|
public TimeFactory(TimeDomainDefinition def, TimeFormatter formatter, TimeScanner scanner)
def
- a non-null time domain definitionformatter
- a non-null time formatterscanner
- a non-null time scannerpublic TimeFactory(TimeDomainDefinition def)
def
- a non-null time domain definitionpublic TimeFactory(TimeDomainDefinition def, TimeFormatter formatter)
def
- a non-null time domain definitionformatter
- a non-null time formatterpublic TimePacker getPacker()
TimeDomain
getPacker
in interface TimeDomain
public TimeFormatter getFormatter()
TimeDomain
getFormatter
in interface TimeDomain
public TimeScanner getScanner()
TimeDomain
getScanner
in interface TimeDomain
public String getLabel()
TimeDomain
TimeDomainCatalog
.getLabel
in interface TimeDomain
public long getOrigin()
TimeDomain
getOrigin
in interface TimeDomain
public Resolution getResolution()
TimeDomain
getResolution
in interface TimeDomain
public int compareResolutionTo(Resolution unit)
TimeDomain
compareResolutionTo
in interface TimeDomain
unit
- a non-null resolutionpublic void requireEquality(TimeDomain domain) throws T2Exception
TimeDomain
requireEquality
in interface TimeDomain
domain
- a time domainT2Exception
public boolean similar(TimeDomain domain)
TimeDomain
similar
in interface TimeDomain
domain
- a time domainpublic TimeIndex time(long year, int month, int day, int hour, int min, int sec, int usec, Adjustment adjust) throws T2Exception
TimeDomain
See the comment in TimeDomain.time(String)
for important details about
discarding unnecessary time components.
time
in interface TimeDomain
year
- the yearmonth
- the monthday
- the dayhour
- the hourmin
- the minutesec
- the secondusec
- the microsecondadjust
- a non-null adjustment modeT2Exception
public TimeIndex time(String date) throws T2Exception
TimeDomain
DefaultTimeScanner
.
Date and time components too precise for the resolution of the time domain are discarded. As an example, all time components are discarded when the resolution is daily or less. There are cases where the time components have an effect on a date component. In such cases it is necessary to use first a higher resolution time domain then to convert to the wanted domain. An example of such a case is when the time component includes a time zone offset which changes the day (and possibly the month and year, as on January first or December 31).
time
in interface TimeDomain
date
- a non-null date stringT2Exception
public TimeIndex time(String date, Adjustment adjust) throws T2Exception
TimeDomain
DefaultTimeScanner
.
See the comment in TimeDomain.time(String)
for important details about
discarding unnecessary time components.
time
in interface TimeDomain
date
- a non-null date stringadjust
- a non-null adjustment modeT2Exception
public TimeIndex minTime()
TimeDomain
minTime(false)
.minTime
in interface TimeDomain
public TimeIndex maxTime()
TimeDomain
maxTime(false)
.maxTime
in interface TimeDomain
public TimeIndex minTime(boolean offsetCompatible)
TimeDomain
minTime
in interface TimeDomain
offsetCompatible
- if true, return a TimeIndex representable as an offsetTimeIndex.asOffset()
public TimeIndex maxTime(boolean offsetCompatible)
TimeDomain
maxTime
in interface TimeDomain
offsetCompatible
- if true, return a TimeIndex representable as an offsetTimeIndex.asOffset()
public TimeIndex time(long index)
TimeDomain
time
in interface TimeDomain
index
- a numberpublic TimeIndex timeFromOffset(long offset)
TimeDomain
timeFromOffset
in interface TimeDomain
offset
- a number to be added to the domain's originpublic boolean valid(long t, boolean testOnly) throws T2Exception
TimePacker
valid
in interface TimePacker
t
- numeric time to validatetestOnly
- if true do not throw an exception when time is not validT2Exception
public BasePeriodPattern getBasePeriodPattern()
TimePacker
getBasePeriodPattern
in interface TimePacker
public SubPeriodPattern getSubPeriodPattern()
TimePacker
getSubPeriodPattern
in interface TimePacker
public TimeParts scan(Resolution unit, String time) throws T2Exception
TimeScanner
scan
in interface TimeScanner
unit
- the time resolutiontime
- a non-null string containing a date and time specificationTimeParts
T2Exception
public String format(TimeParts timeParts)
TimeFormatter
format
in interface TimeFormatter
timeParts
- a non-null time parts objectpublic long pack(TimeParts tp, Adjustment adjust) throws T2Exception
TimePacker
pack
in interface TimePacker
tp
- a time parts objectadjust
- a non-null adjustment modeT2Exception
public TimeParts unpack(long time)
TimePacker
unpack
in interface TimePacker
time
- a numeric time indexpublic DayOfWeek getDayOfWeek(TimeIndex time) throws T2Exception
TimePacker
getDayOfWeek
in interface TimePacker
time
- a time indexT2Exception
public int getBasePeriodSize()
TimePacker
getBasePeriodSize
in interface TimePacker
public TimeIndex getBasePeriodStart(TimeIndex t)
TimePacker
getBasePeriodStart
in interface TimePacker
t
- a non-null time index, which must be from this time domainCopyright © 2017. All rights reserved.