PartialTimestamp
Keywords: org.ggf.drmaa.PartialTimestamp class

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.ggf.drmaa
Class PartialTimestamp

    java.lang.Object
      java.util.Calendar
          org.ggf.drmaa.PartialTimestamp

All Implemented Interfaces:
  java.lang.Cloneable, java.io.Serializable

public class PartialTimestamp
extends java.util.Calendar

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 ());
       }
     }

Since:
  0.5
Author:
  dan.templeton@sun.com
See Also:
  Serialized Form

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

### CENTURY

    public static final int CENTURY

  CENTURY is a field required by the DRMAA timestamp.

  See Also:
    Constant Field Values

### UNSET

    public static final int UNSET

  UNSET is the value assigned to fields which have not yet been set.

  See Also:
    Constant Field Values

Constructor Detail

### PartialTimestamp

    public PartialTimestamp()

  Constructs a default GregorianCalendar using the current time in the default time zone with the default locale.

### PartialTimestamp

    public PartialTimestamp(java.util.TimeZone zone)

  Constructs a GregorianCalendar based on the current time in the given time zone with the default locale.

Parameters:
  `zone` - the given time zone.

### PartialTimestamp

    public PartialTimestamp(java.util.Locale aLocale)

  Constructs a GregorianCalendar based on the current time in the default time zone with the given locale.

Parameters:
  `aLocale` - the given locale.

### PartialTimestamp

    public 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.

Parameters:
  `zone` - the given time zone.
  `aLocale` - the given locale.

### PartialTimestamp

    public 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.

Parameters:
  `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.

### PartialTimestamp

    public 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.

Parameters:
  `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.

### PartialTimestamp

    public 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.

Parameters:
  `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

### getModifier

    public int getModifier(int field)

  Returns the value of the modifier for the given field.

  Parameters:
    `field` - the field whose modifier will be returned
  Returns:
    the value of the field's modifier

### setModifier

    public void setModifier(int field,
                            int value)

  Sets the value of the modifier for the given field.

  Parameters:
    `field` - the field whose modifier will be set
    `value` - the value to which to set the field's modifier

### add

    public void add(int field,
                    int amount)

  Adds the given value to the given field. If the field< is unset, the amount will be added to the field's modifier instead. If the field is set, but the addition causes changes to another field, which is unset, the unset field will receive the change as a modifier.

  Parameters:
    `field` - the field to which to add the amount
    `amount` - the amount to add

### computeFields

    protected void computeFields()

  This method is called directly after the internal time in milliseconds is set. It computes from this time all the resulting field values. After computeFields() is called, all fields are considered set.

### set

    public void set(int field,
                    int value)

  Sets the value of the given field<. After a call to set, the field is considered set. There is no way to unset a field that has been previously set. If the value is out of range for the field, it will be adjusted to be within range, if possible. If, because of other unset fields, there is not enough information to adjust the field, the field will remain as set.

  Parameters:
    `field` - the field to set
    `value` - the value to which to set the field

### get

    public int get(int field)

  Get the value of the given field<. If the field is unset, this method will return UNSET.

  Parameters:
    `field` - which field's value to get
  Returns:
    The value of the field.

### computeTime

    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. If no time in the future can be found, the resulting time will be the same as creating a new GregorianCalendar() and setting all the set fields of the PartialTimestamp object in it. In any case, the resulting is stored internally.

### getGreatestMinimum

    public int getGreatestMinimum(int field)

  Gets the greatest minimum value that the field may ever have.

  Parameters:
    `field` - the field of interest
  Returns:
    the greatest minimum value that the field may ever have

### getLeastMaximum

    public int getLeastMaximum(int field)

  Gets the least maximum value that the field may ever have.

  Parameters:
    `field` - the field of interest
  Returns:
    the least maximum value that the field may ever have

### getMaximum

    public int getMaximum(int field)

  Gets the greatest maximum value that the field may ever have.

  Parameters:
    `field` - the field of interest
  Returns:
    the greatest maximum value that the field may ever have

### getMinimum

    public int getMinimum(int field)

  Gets the least minimum value that the field may ever have.

  Parameters:
    `field` - the field of interest
  Returns:
    the least minimum value that the field may ever have

### roll

    public void roll(int field,
                     boolean up)

  This method naively rolls the value of the given field by 1, either up or down. If the resulting value is out of range for the field, the value will roll over without affecting other fields.

  Parameters:
    `field` - the field to roll
    `up` - whether to roll up

### roll

    public void roll(int field,
                     int amount)

  This method naively rolls the value of the given field up by the given amount. To roll down, use a negative amount. If the resulting value is out of range for the field, the value will roll over without affecting other fields.

  Parameters:
    `field` - the field to roll
    `amount` - the amount to roll up

### myInternalSet

    protected void myInternalSet(int field,
                                 int value)

  Sets the value of the given field. If the field is unset before the call, it will still be "unset" after the call finishes.

  Parameters:
    `field` - the field to set
    `value` - the value to which to set the field

### getActualMinimum

    public int getActualMinimum(int field)

  Returns the actual minimum value for the field, based on the current field values.

  Parameters:
    `field` - the field of interest
  Returns:
    the actual minimum value for the field

### getActualMaximum

    public int getActualMaximum(int field)

  Returns the actual maximum value for the field, based on the current field values.

  Parameters:
    `field` - the field of interest
  Returns:
    the actual maximum value for the field

### equals

    public boolean equals(java.lang.Object obj)

  Compares two PartialTimestamp objects. They are equal if they both have all of the same field values and field modifier values.

  Parameters:
    `obj` - the object against which to compare
  Returns:
    whether the given object equals this object

### clone

    public java.lang.Object clone()

  Makes a complete copy of this object.

  Returns:
    a complete copy of this object

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD