tauZaman
v0.1

tauzaman.timestamp
Class TimeValue

java.lang.Object
  |
  +--tauzaman.timestamp.TimeValue
All Implemented Interfaces:
java.lang.Comparable, java.io.Serializable

public class TimeValue
extends java.lang.Object
implements java.lang.Comparable, java.io.Serializable

TimeValue class implements the arithmetic and comparison operations for an underlying domain of times times that are bounded by "MIN" and "MAX" values. MIN (MAX) are before (after) the smallest (largest) times. Operations on TimeValues usually construct a new TimeValue, they never mutate a TimeValue. For example, assuming a discrete domain of times implemented using longs.

    TimeValue min = TimeValue.BEGINNING_OF_TIME;
    TimeValue max = TimeValue.END_OF_TIME;
    TimeValue one = new TimeValue(1);
    TimeValue three = new TimeValue(3);
    TimeValue result = max.add(min);
    System.out.println(max.image());  // Prints [TimeValue MAX]
    System.out.println(min.image()); // Prints [TimeValue MIN]
    System.out.println(result.image()); // prints [TimeValue NORMAL 0]
    result = one.add(three); 
    System.out.println(one.image()); // Prints [TimeValue NORMAL 1]
    System.out.println(three.image()); // Prints [TimeValue NORMAL 3]
    System.out.println(result.image()); //Prints [TimeValue NORMAL 4]
 

See Also:
Granule, Serialized Form
Status:
IMPLEMENTED and TESTED

Field Summary
static TimeValue ALL_OF_TIME
           
static TimeValue BEGINNING_OF_TIME
           
static TimeValue END_OF_TIME
           
private  int kind
           
private static int MAX
           
private static int MIN
           
static TimeValue MINUS_ONE_TIMEVALUE
           
static TimeValue NEGATIVE_ALL_OF_TIME
           
private static int NORMAL
           
static TimeValue ONE_TIMEVALUE
           
private  long value
           
static TimeValue ZERO_TIMEVALUE
           
 
Constructor Summary
TimeValue(int count)
          Construct a NORMAL time value.
TimeValue(int kind, int count)
          Construct a NORMAL, MAX or MIN time value.
TimeValue(int kind, long count)
          Construct a NORMAL, MAX or MIN time value.
TimeValue(long granules)
          Creates a NORMAL TimeValue.
 
Method Summary
 TimeValue add(TimeValue other)
          Construct the result of "this plus other".
 int compareTo(java.lang.Object otherTimeValue)
          Compare this TimeValue with another.
 TimeValue decrement()
          Construct this TimeValue - 1
 TimeValue divide(int n)
          Construct the result of "this div N".
 int getKind()
          Accessor function to get the kind represented by this TimeValue.
 long getValue()
          Accessor function to get the value represented by this TimeValue.
 java.lang.String image()
          Create a nice string image of a time value
 TimeValue increment()
          Construct this TimeValue + 1
static void main(java.lang.String[] argv)
          A simple test for the class.
 TimeValue multiply(int n)
          Construct the result of "this times N".
 TimeValue negate()
          Construct the result of "minus this".
 TimeValue subtract(TimeValue other)
          Construct the result of "this minus other".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX

private static final int MAX
See Also:
Constant Field Values

MIN

private static final int MIN
See Also:
Constant Field Values

NORMAL

private static final int NORMAL
See Also:
Constant Field Values

END_OF_TIME

public static final TimeValue END_OF_TIME

ALL_OF_TIME

public static final TimeValue ALL_OF_TIME

BEGINNING_OF_TIME

public static final TimeValue BEGINNING_OF_TIME

NEGATIVE_ALL_OF_TIME

public static final TimeValue NEGATIVE_ALL_OF_TIME

ZERO_TIMEVALUE

public static final TimeValue ZERO_TIMEVALUE

ONE_TIMEVALUE

public static final TimeValue ONE_TIMEVALUE

MINUS_ONE_TIMEVALUE

public static final TimeValue MINUS_ONE_TIMEVALUE

kind

private int kind

value

private long value
Constructor Detail

TimeValue

public TimeValue(int kind,
                 long count)
Construct a NORMAL, MAX or MIN time value. The long represents the displacement from the origin, it is ignored for MAX or MIN TimeValues.

Parameters:
kind - - NORMAL, MAX, or MIN
count - - granule count

TimeValue

public TimeValue(int kind,
                 int count)
Construct a NORMAL, MAX or MIN time value. The long represents the displacement from the origin, it is ignored for MAX or MIN TimeValues.

Parameters:
kind - - NORMAL, MAX, or MIN
count - - granule count

TimeValue

public TimeValue(int count)
Construct a NORMAL time value.

Parameters:
count - - granule count

TimeValue

public TimeValue(long granules)
Creates a NORMAL TimeValue.

Parameters:
granules - - count in granules of this TimeValue
Method Detail

image

public java.lang.String image()
Create a nice string image of a time value

Returns:
String image of time value

getKind

public int getKind()
Accessor function to get the kind represented by this TimeValue.

Returns:
the kind

getValue

public long getValue()
Accessor function to get the value represented by this TimeValue.

Returns:
the value

compareTo

public int compareTo(java.lang.Object otherTimeValue)
Compare this TimeValue with another. Implements the Comparable interface. if this < other then returns negative number if this == other then returns 0 if this > other then returns positive number

Specified by:
compareTo in interface java.lang.Comparable
Returns:
integer representing result of comparison
See Also:
Comparable
Status:
NOT TESTED

subtract

public TimeValue subtract(TimeValue other)
Construct the result of "this minus other".

Parameters:
other - - The TimeValue to subtract
Returns:
this - other

add

public TimeValue add(TimeValue other)
Construct the result of "this plus other".

Parameters:
other - - The TimeValue to add
Returns:
this + other

negate

public TimeValue negate()
Construct the result of "minus this".

Returns:
this * -1

increment

public TimeValue increment()
Construct this TimeValue + 1

Returns:
this + 1

decrement

public TimeValue decrement()
Construct this TimeValue - 1

Returns:
this - 1

multiply

public TimeValue multiply(int n)
Construct the result of "this times N".

Returns:
this * N

divide

public TimeValue divide(int n)
Construct the result of "this div N".

Returns:
this/N

main

public static void main(java.lang.String[] argv)
A simple test for the class.


tauZaman
v0.1

Submit a bug or feature

tauZaman is an open-source, publicly avaliable project