org.eclipse.stardust.common
Class Period

java.lang.Object
  extended by org.eclipse.stardust.common.Period
All Implemented Interfaces:
Serializable

public class Period
extends Object
implements Serializable

The Period class is used to handle time periods. A period consists of a group of 6 numbers, each specifying an amount of units, i.e. 6 months and 3 hours. The Period also provides convenient methods to perform operations on Calendars.

Version:
$Revision$
Author:
ubirkemeyer
See Also:
Serialized Form

Field Summary
static int DAYS
          Identifier for the number of days field.
static int HOURS
          Identifier for the number of hours field.
static int MINUTES
          Identifier for the number of minutes field.
static int MONTHS
          Identifier for the number of months field.
static int SECONDS
          Identifier for the number of seconds field.
static int YEARS
          Identifier for the number of years field.
 
Constructor Summary
Period(short years, short months, short days, short hours, short minutes, short seconds)
          Creates a new Period from the given values.
Period(String raw)
          Creates a new Period from a string representation.
 
Method Summary
 Calendar add(Calendar source)
          Adds this period to the provided calendar.
 boolean equals(Object o)
           
 short get(int field)
          Gets the value of a specific field of the period.
 int hashCode()
           
 Calendar subtract(Calendar source)
          Subtracts this period from the provided calendar.
 String toString()
          Returns a fixed size String representation of the period, where each field has 6 digits allocated.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

YEARS

public static final int YEARS
Identifier for the number of years field.

See Also:
Constant Field Values

MONTHS

public static final int MONTHS
Identifier for the number of months field.

See Also:
Constant Field Values

DAYS

public static final int DAYS
Identifier for the number of days field.

See Also:
Constant Field Values

HOURS

public static final int HOURS
Identifier for the number of hours field.

See Also:
Constant Field Values

MINUTES

public static final int MINUTES
Identifier for the number of minutes field.

See Also:
Constant Field Values

SECONDS

public static final int SECONDS
Identifier for the number of seconds field.

See Also:
Constant Field Values
Constructor Detail

Period

public Period(String raw)
Creates a new Period from a string representation. The format should contain in order: the years, months, days, hours, minutes and seconds. As field separator is used the colon (':').

Example: "0:6:0:3:0:0" represents a period of 6 months and 3 hours.

Parameters:
raw - the String representation of the period.

Period

public Period(short years,
              short months,
              short days,
              short hours,
              short minutes,
              short seconds)
Creates a new Period from the given values.

Parameters:
years - the number of years contained in the period.
months - the number of months contained in the period.
days - the number of days contained in the period.
hours - the number of hours contained in the period.
minutes - the number of minutes contained in the period.
seconds - the number of seconds contained in the period.
Method Detail

toString

public String toString()
Returns a fixed size String representation of the period, where each field has 6 digits allocated.

Overrides:
toString in class Object
Returns:
the string representation of the period.

add

public Calendar add(Calendar source)
Adds this period to the provided calendar.

Parameters:
source - the reference time.
Returns:
the time obtained by adding this period to the reference time.

subtract

public Calendar subtract(Calendar source)
Subtracts this period from the provided calendar.

Parameters:
source - the reference time.
Returns:
the time obtained by subtracting this period from the reference time.

get

public short get(int field)
Gets the value of a specific field of the period.

Parameters:
field - one of the identifier constants.
Returns:
the value of the field.

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object


Copyright © 2017 Eclipse Stardust. All Rights Reserved.