tauZaman
v0.1

tauzaman.timestamp
Class NowRelativeGranule

java.lang.Object
  |
  +--tauzaman.timestamp.Granule
        |
        +--tauzaman.timestamp.NowRelativeGranule
All Implemented Interfaces:
java.io.Serializable

public class NowRelativeGranule
extends Granule

The Granule class implements the arithmetic and comparison operations on Granules. A Granule is the most basic unit of time in a given Granularity. Each granule is a (TimeValue) distance (in granules). Granules can be used for both unanchored and anchored times. If the time is anchored, the Granule represents the distance from the granularity anchor point. If the time is unanchored, the Granule just represents a distance. Granules can be further classified as determinate or indeterminate. A determinate granule has a known, fixed distance. An indeterminate granule is some distance between a lower and upper bound. A probability mass function determines the probability of each indeterminate alternative. Granules can also be now-relative. A now-relative granule is a moving point on the time-line. It consists of the variable now that represents the current time, and an granule count that displaces the granule the specified distance from the current time. For example, the now-relative granule 'now + 1 day' indicates that the Granule represented is whatever the current time is displaced by one day in the future. This class implements now-relative instants that have a known, fixed displacement (as opposed to instants that have indeterminate displacements). Note that none of the operations are mutators, that is, they all create a new instant if needed.

See Also:
Granule, TimeValue, ExtendedBoolean, Serialized Form

Field Summary
 
Fields inherited from class tauzaman.timestamp.Granule
DETERMINATE, FALSE_EB, granularity, INDETERMINATE, kind, lower, MAYBE_EB, NOWRELATIVE, pmf, TRUE_EB, upper
 
Constructor Summary
NowRelativeGranule()
          Create the now granule at the default Granularity (i.e., 'now + 0')
NowRelativeGranule(Granularity g)
          Create the now granule at the specified Granularity (i.e., 'now + 0')
NowRelativeGranule(Granularity g, long p)
          Create a now-relative granule at the specified Granularity
NowRelativeGranule(Granularity g, TimeValue p)
          Create a now-relative granule at the specified Granularity
NowRelativeGranule(long p)
          Create a now-relative granule at the default Granularity
NowRelativeGranule(TimeValue p)
          Create a now-relative granule at the default Granularity
 
Method Summary
 NowRelativeGranule add(NowRelativeGranule other)
          Add a now-relative to a now-relative.
 Granule decrement()
          Construct a NowRelativeGranule that has the relative part decremented by 1
 Granule divide(int n)
          Divide by a constant.
 ExtendedBoolean equalTo(NowRelativeGranule other)
          NowRelative/NowRelative comparison - Is this == other?
 TimeValue getGranule()
          Accessor - retrieve the granule.
 TimeValue getLower()
          Accessor - retrieve the lower bound from the now-relative granule.
 TimeValue getUpper()
          Accessor - retrieve the upper bound from the now-relative granule.
 ExtendedBoolean greaterThan(NowRelativeGranule other)
          NowRelative/NowRelative comparison - Is this > other?
 ExtendedBoolean greaterThanOrEqualTo(NowRelativeGranule other)
          NowRelative/NowRelative comparison - Is this >= other?
 java.lang.String image()
          Create a nice string image of a granule, alternative to toString()
 Granule increment()
          Construct a NowRelativeGranule that has the relative part incremented by 1
 ExtendedBoolean lessThan(NowRelativeGranule other)
          NowRelative/NowRelative comparison - Is this < other?
 ExtendedBoolean lessThanOrEqualTo(NowRelativeGranule other)
          NowRelative/NowRelative comparison - Is this <= other?
 Granule multiply(int n)
          Multiply by a constant.
 Granule negate()
          Negate the granule.
 NowRelativeGranule subtract(NowRelativeGranule other)
          Subtract a now-relative from a now-relative.
 
Methods inherited from class tauzaman.timestamp.Granule
add, equalTo, getGranularity, getKind, greaterThan, greaterThanOrEqualTo, lessThan, lessThanOrEqualTo, main, subtract
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NowRelativeGranule

public NowRelativeGranule()
                   throws TauZamanException
Create the now granule at the default Granularity (i.e., 'now + 0')

Throws:
TauZamanException - if any abnormal condition occurs when setting this Granule's default Granularity

NowRelativeGranule

public NowRelativeGranule(Granularity g)
Create the now granule at the specified Granularity (i.e., 'now + 0')

Parameters:
g - - desired Granularity

NowRelativeGranule

public NowRelativeGranule(TimeValue p)
                   throws TauZamanException
Create a now-relative granule at the default Granularity

Parameters:
p - - displacement from now
Throws:
TauZamanException - if any abnormal condition occurs when setting this Granule's default Granularity

NowRelativeGranule

public NowRelativeGranule(Granularity g,
                          TimeValue p)
Create a now-relative granule at the specified Granularity

Parameters:
g - - desired Granularity
p - - displacement from now

NowRelativeGranule

public NowRelativeGranule(long p)
                   throws TauZamanException
Create a now-relative granule at the default Granularity

Parameters:
p - - count of granules
Throws:
TauZamanException - if any abnormal condition occurs when setting this Granule's default Granularity

NowRelativeGranule

public NowRelativeGranule(Granularity g,
                          long p)
Create a now-relative granule at the specified Granularity

Parameters:
g - - desired Granularity
p - - count of granules
Method Detail

getGranule

public TimeValue getGranule()
Accessor - retrieve the granule. When the value is returned it is first bound to the current time and the displacment is added.

Overrides:
getGranule in class Granule
Returns:
TimeValue object that represents the current time + displacement

getLower

public TimeValue getLower()
Accessor - retrieve the lower bound from the now-relative granule. The lower bound is computed by displacing the current time with the lower bound.

Overrides:
getLower in class Granule
Returns:
TimeValue object that represents the current lower bound

getUpper

public TimeValue getUpper()
Accessor - retrieve the upper bound from the now-relative granule. The upper bound is computed by displacing the current time with the upper bound.

Overrides:
getUpper in class Granule
Returns:
TimeValue object that represents the current upper bound

image

public java.lang.String image()
Create a nice string image of a granule, alternative to toString()

Overrides:
image in class Granule
Returns:
String image of a granule
Status:
NOT IMPLEMENTED for INDETERMINATE GRANULES

decrement

public Granule decrement()
Construct a NowRelativeGranule that has the relative part decremented by 1

Overrides:
decrement in class Granule
Returns:
this - 1

increment

public Granule increment()
Construct a NowRelativeGranule that has the relative part incremented by 1

Overrides:
increment in class Granule
Returns:
this + 1

negate

public Granule negate()
Negate the granule. This method constructs a new granule that has the relative part negated. This does NOT NEGATE NOW.

Overrides:
negate in class Granule
Returns:
a new Granule with the relative part negated

equalTo

public ExtendedBoolean equalTo(NowRelativeGranule other)
NowRelative/NowRelative comparison - Is this == other? capture the comparison for other kinds of granules.

Parameters:
other - - The NowRelativeGranule to compare
Returns:
does this == other?

lessThan

public ExtendedBoolean lessThan(NowRelativeGranule other)
NowRelative/NowRelative comparison - Is this < other?

Parameters:
other - - The NowRelativeGranule to compare
Returns:
does this < other?

lessThanOrEqualTo

public ExtendedBoolean lessThanOrEqualTo(NowRelativeGranule other)
NowRelative/NowRelative comparison - Is this <= other?

Parameters:
other - - The NowRelativeGranule to compare
Returns:
does this <= other?

greaterThan

public ExtendedBoolean greaterThan(NowRelativeGranule other)
NowRelative/NowRelative comparison - Is this > other?

Parameters:
other - - The NowRelativeGranule to compare
Returns:
does this > other?

greaterThanOrEqualTo

public ExtendedBoolean greaterThanOrEqualTo(NowRelativeGranule other)
NowRelative/NowRelative comparison - Is this >= other?

Parameters:
other - - The NowRelativeGranule to compare
Returns:
does this >= other?

add

public NowRelativeGranule add(NowRelativeGranule other)
Add a now-relative to a now-relative. Only the displacements are added.

Parameters:
other - - The NowRelativeGranule to add return this + other

subtract

public NowRelativeGranule subtract(NowRelativeGranule other)
Subtract a now-relative from a now-relative. Only the displacements are subtracted.

Parameters:
other - - The NowRelativeGranule to subtract return this - other

multiply

public Granule multiply(int n)
Multiply by a constant. This constructs a new NowRelativeGranule that is the the multiplication of the existing granule by a constant. The granularity remains the same.

Overrides:
multiply in class Granule
Parameters:
n - - The multiplier
Returns:
a new NowRelativeGranule with the relative part multiplied by n

divide

public Granule divide(int n)
Divide by a constant. This constructs a new NowRelativeGranule that is the the division of the existing granule by a constant. The granularity remains the same.

Overrides:
divide in class Granule
Parameters:
n - - The divisor
Returns:
a new NowRelativeGranule with the relative part divided by n

tauZaman
v0.1

Submit a bug or feature

tauZaman is an open-source, publicly avaliable project