|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.Calendar
org.ggf.drmaa.PartialTimestamp
The PartialTimestamp is a subclass of java.util.Calendar which allows for a partially specified time that is resolved as the soonest matching time that is in the future as the time of resolution. That is to say that if I create a PartialTimestamp object and set the hour to 10am and the minute to 0, and I resolve the time, i.e. PartialTimestamp.getTime(), at 11:01am on November 24th, the PartialTimestamp will resolve to 10:00am on November 25th, because that is the soonest time which matches the specified fields and is in the future. If I later resolve that same PartialTimestamp at 9:34am on December 1st, it will resolve to 10:00am on December 1st.
There are only two ways to resolve the time: getTime() and getTimeInMillis(). All other means of accessing field values will return unresolved values. In the PartialTimestamp class is unable to resolve a field because of other unset fields, it will simply leave the field unresolved. For example, if the DAY_OF_MONTH is set to 42, and the MONTH is unset, the DAY_OF_MONTH will remain as 42. If later the MONTH is set, the DAY_OF_MONTH may be resolved to an in-range value. ("May," because if the MONTH is FEBRUARY, the YEAR and CENTURY are also needed to be able to resolve the DAY_OF_MONTH.)
Whereever possible and sensible, the PartialTimestamp class mimics the functionality of the GregorianCalendar class.
Since the PartialTimestamp only supports dates within the epoch, the ERA field is always AD, and hence is not used. The DRMAA specification, requires that the year be handled as two separate fields, one for the first two digits (century) and one for the last two digits. Because of the symantics of extending the Calendar class, the CENTURY field is just an alias for the ERA field, and the ERA contains the century data. When using the PartialTimestmap, the ERA field should not be used.
When rolling a date field, if the PartialTimestamp doesn't have enough information to determine the field's valid value range, e.g. when rolling the DAY_OF_MONTH while MONTH is unset, an assumption will be made. The assumptions PartialTimestamp may make are: a year is 365 days or 53 weeks, and a month is 31 days or 5 weeks.
The PartialTimestamp class adds the idea of field modifiers. The field modifiers are accessed via the setModifier() and getModifier() methods. A modifier represents a number that will be added to the value of the field. This is useful because in a PartialTimestamp object, it may necessary to add to an unset field, for example to indicate the concept of "tomorrow." If an add() method or out of range set() method attempts to modify an unset field, the resulting modifier will be stored as the modifier for that field. For example, if the MONTH is set to DECEMBER, and the YEAR is unset, and 1 is added to the MONTH, the result will be that the MONTH is set to JANUARY, the year is still unset, and the YEAR modifier is set to 1. If later the YEAR is set to 97, the modifier will be applied, resulting in a year of 98. To avoid unwanted modifiers, user the roll() method.
The roll() method in the PartialTimestamp class is very simple. It does not take into account Daylight Savings Time or other complications, as does the roll() method of the GregorianCalendar. For the moment, that functionality seems to be unneeded. If it becomes clear that it is necessary, it can be added at a later time.
Example:
public static void main (String[] args) { SessionFactory factory = SessionFactory.getFactory (); Session session = factory.getSession (); try { session.init (null); JobTemplate jt = session.createJobTemplate (); jt.setRemoteCommand ("sleeper.sh"); jt.setArgs (new String[] {"5"}); PartialTimestamp date = new PartialTimestamp (); // Run the job on the first of the month at 11:30 date.set (PartialTimestamp.DATE, 1); date.set (PartialTimestamp.HOUR_OF_DAY, 11); date.set (PartialTimestamp.MINUTE, 30); jt.setStartTime (date); String id = session.runJob (jt); session.deleteJobTemplate (jt); session.exit (); } catch (DrmaaException e) { System.out.println ("Error: " + e.getMessage ()); } }
Field Summary | |
static int |
CENTURY
CENTURY is a field required by the DRMAA timestamp. |
static int |
UNSET
UNSET is the value assigned to fields which have not yet been set. |
Fields inherited from class java.util.Calendar |
AM, AM_PM, APRIL, areFieldsSet, AUGUST, DATE, DAY_OF_MONTH, DAY_OF_WEEK, DAY_OF_WEEK_IN_MONTH, DAY_OF_YEAR, DECEMBER, DST_OFFSET, ERA, FEBRUARY, FIELD_COUNT, fields, FRIDAY, HOUR, HOUR_OF_DAY, isSet, isTimeSet, JANUARY, JULY, JUNE, MARCH, MAY, MILLISECOND, MINUTE, MONDAY, MONTH, NOVEMBER, OCTOBER, PM, SATURDAY, SECOND, SEPTEMBER, SUNDAY, THURSDAY, time, TUESDAY, UNDECIMBER, WEDNESDAY, WEEK_OF_MONTH, WEEK_OF_YEAR, YEAR, ZONE_OFFSET |
Constructor Summary | |
PartialTimestamp()
Constructs a default GregorianCalendar using the current time in the default time zone with the default locale. |
|
PartialTimestamp(int hour,
int minute,
int second)
Constructs a GregorianCalendar with the given date and time set for the default time zone with the default locale. |
|
PartialTimestamp(int year,
int month,
int date,
int hour,
int minute)
Constructs a GregorianCalendar with the given date and time set for the default time zone with the default locale. |
|
PartialTimestamp(int year,
int month,
int date,
int hour,
int minute,
int second)
Constructs a GregorianCalendar with the given date and time set for the default time zone with the default locale. |
|
PartialTimestamp(java.util.Locale aLocale)
Constructs a GregorianCalendar based on the current time in the default time zone with the given locale. |
|
PartialTimestamp(java.util.TimeZone zone)
Constructs a GregorianCalendar based on the current time in the given time zone with the default locale. |
|
PartialTimestamp(java.util.TimeZone zone,
java.util.Locale aLocale)
Constructs a GregorianCalendar based on the current time in the given time zone with the given locale. |
Method Summary | |
void |
add(int field,
int amount)
Adds the given value to the given field. |
java.lang.Object |
clone()
Makes a complete copy of this object. |
protected void |
computeFields()
This method is called directly after the internal time in milliseconds is set. |
protected void |
computeTime()
This method uses the set fields and the current time to calculate the soonest time in milliseconds for this PartialTimestamp object which is in the future. |
boolean |
equals(java.lang.Object obj)
Compares two PartialTimestamp objects. |
int |
get(int field)
Get the value of the given field<. |
int |
getActualMaximum(int field)
Returns the actual maximum value for the field, based on the current field values. |
int |
getActualMinimum(int field)
Returns the actual minimum value for the field, based on the current field values. |
int |
getGreatestMinimum(int field)
Gets the greatest minimum value that the field may ever have. |
int |
getLeastMaximum(int field)
Gets the least maximum value that the field may ever have. |
int |
getMaximum(int field)
Gets the greatest maximum value that the field may ever have. |
int |
getMinimum(int field)
Gets the least minimum value that the field may ever have. |
int |
getModifier(int field)
Returns the value of the modifier for the given field. |
protected void |
myInternalSet(int field,
int value)
Sets the value of the given field. |
void |
roll(int field,
boolean up)
This method naively rolls the value of the given field by 1, either up or down. |
void |
roll(int field,
int amount)
This method naively rolls the value of the given field up by the given amount. |
void |
set(int field,
int value)
Sets the value of the given field<. |
void |
setModifier(int field,
int value)
Sets the value of the modifier for the given field. |
Methods inherited from class java.util.Calendar |
after, before, clear, clear, complete, getAvailableLocales, getFirstDayOfWeek, getInstance, getInstance, getInstance, getInstance, getMinimalDaysInFirstWeek, getTime, getTimeInMillis, getTimeZone, hashCode, internalGet, isLenient, isSet, set, set, set, setFirstDayOfWeek, setLenient, setMinimalDaysInFirstWeek, setTime, setTimeInMillis, setTimeZone, toString |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int CENTURY
public static final int UNSET
Constructor Detail |
public PartialTimestamp()
public PartialTimestamp(java.util.TimeZone zone)
zone
- the given time zone.public PartialTimestamp(java.util.Locale aLocale)
aLocale
- the given locale.public PartialTimestamp(java.util.TimeZone zone, java.util.Locale aLocale)
zone
- the given time zone.aLocale
- the given locale.public PartialTimestamp(int year, int month, int date, int hour, int minute)
year
- the value used to set the YEAR time field in the calendar.month
- the value used to set the MONTH time field in the calendar.
Month value is 0-based. e.g., 0 for January.date
- the value used to set the DATE time field in the calendar.hour
- the value used to set the HOUR_OF_DAY time field
in the calendar.minute
- the value used to set the MINUTE time field
in the calendar.public PartialTimestamp(int hour, int minute, int second)
hour
- the value used to set the HOUR_OF_DAY time field
in the calendar.minute
- the value used to set the MINUTE time field
in the calendar.second
- the value used to set the SECOND time field
in the calendar.public PartialTimestamp(int year, int month, int date, int hour, int minute, int second)
year
- the value used to set the YEAR time field in the calendar.month
- the value used to set the MONTH time field in the calendar.
Month value is 0-based. e.g., 0 for January.date
- the value used to set the DATE time field in the calendar.hour
- the value used to set the HOUR_OF_DAY time field
in the calendar.minute
- the value used to set the MINUTE time field
in the calendar.second
- the value used to set the SECOND time field
in the calendar.Method Detail |
public int getModifier(int field)
field
- the field whose modifier will be returned
public void setModifier(int field, int value)
field
- the field whose modifier will be setvalue
- the value to which to set the field's modifierpublic void add(int field, int amount)
field
- the field to which to add the amountamount
- the amount to addprotected void computeFields()
public void set(int field, int value)
field
- the field to setvalue
- the value to which to set the fieldpublic int get(int field)
field
- which field's value to get
protected void computeTime()
public int getGreatestMinimum(int field)
field
- the field of interest
public int getLeastMaximum(int field)
field
- the field of interest
public int getMaximum(int field)
field
- the field of interest
public int getMinimum(int field)
field
- the field of interest
public void roll(int field, boolean up)
field
- the field to rollup
- whether to roll uppublic void roll(int field, int amount)
field
- the field to rollamount
- the amount to roll upprotected void myInternalSet(int field, int value)
field
- the field to setvalue
- the value to which to set the fieldpublic int getActualMinimum(int field)
field
- the field of interest
public int getActualMaximum(int field)
field
- the field of interest
public boolean equals(java.lang.Object obj)
obj
- the object against which to compare
public java.lang.Object clone()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |