tauZaman
v0.1

tauzaman.timestamp
Class Granule

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

public class Granule
extends java.lang.Object
implements java.io.Serializable

A Granule is a pairing of a TimeValue and a Granularity, independent of a TauZamanService. This class implements operations on 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.

See Also:
TimeValue, ExtendedBoolean, Serialized Form

Field Summary
static int DETERMINATE
           
protected static ExtendedBoolean FALSE_EB
           
protected  Granularity granularity
           
static int INDETERMINATE
           
protected  int kind
           
protected  TimeValue lower
           
protected static ExtendedBoolean MAYBE_EB
           
static int NOWRELATIVE
           
protected  ProbabilityMassFunction pmf
           
protected static ExtendedBoolean TRUE_EB
           
protected  TimeValue upper
           
 
Constructor Summary
Granule(Granularity g, long p)
          Create a determinate granule at the specified Granularity
Granule(Granularity g, long lower, long upper)
          Create an indeterminate granule with an unknown PMF at the specified Granularity
Granule(Granularity g, long lower, long upper, ProbabilityMassFunction pmf)
          Create an indeterminate granule with the specified PMF at the specified Granularity
Granule(Granularity g, TimeValue p)
          Create a determinate granule at the specified Granularity
Granule(Granularity g, TimeValue lower, TimeValue upper)
          Create an indeterminate granule with an unknown PMF at the specified Granularity
Granule(Granularity g, TimeValue lower, TimeValue upper, ProbabilityMassFunction pmf)
          Create an indeterminate granule with the specified PMF at the specified Granularity
Granule(long p)
          Create a determinate granule at the default Granularity
Granule(long lower, long upper)
          Create an indeterminate granule with an unknown PMF at the default Granularity
Granule(long lower, long upper, ProbabilityMassFunction pmf)
          Create an indeterminate granule with the specified PMF at the default Granularity
Granule(TimeValue p)
          Create a determinate granule at the default Granularity
Granule(TimeValue lower, TimeValue upper)
          Create an indeterminate granule with an unknown PMF at the default Granularity
Granule(TimeValue lower, TimeValue upper, ProbabilityMassFunction pmf)
          Create an indeterminate granule with the specified PMF at the default Granularity
 
Method Summary
 Granule add(Granule other)
          Construct a new Granule that is this + other.
 Granule decrement()
          Construct a Granule that has each bound decremented by 1
 Granule divide(int n)
          Divide by a constant.
 ExtendedBoolean equalTo(Granule other)
          Is this == other?
 Granularity getGranularity()
          Accessor - retrieve the granularity of this granule
 TimeValue getGranule()
          Accessor - retrieve the granules from a determinate granule (defaults to lower bound for indeterminate granule)
 int getKind()
          Accessor - retrieve the kind of this granule, INDETERMINATE or DETERMINATE
 TimeValue getLower()
          Accessor - retrieve the lower bound from an indeterminate granule (defaults to granules for determinate granule)
 TimeValue getUpper()
          Accessor - retrieve the upper bound from an indeterminate granule (defaults to granules for determinate granule)
 ExtendedBoolean greaterThan(Granule other)
          Is this > other?
 ExtendedBoolean greaterThanOrEqualTo(Granule other)
          Is this >= other?
 java.lang.String image()
          Create a nice string image of a granule, alternative to toString()
 Granule increment()
          Construct a Granule that has each bound incremented by 1
 ExtendedBoolean lessThan(Granule other)
          Is this < other?
 ExtendedBoolean lessThanOrEqualTo(Granule other)
          Is this <= other?
static void main(java.lang.String[] argv)
          A simple test for the class.
 Granule multiply(int n)
          Multiply by a constant.
 Granule negate()
          Negate the granule.
 Granule subtract(Granule other)
          Construct a new Granule that is this - other.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

kind

protected int kind

DETERMINATE

public static final int DETERMINATE
See Also:
Constant Field Values

INDETERMINATE

public static final int INDETERMINATE
See Also:
Constant Field Values

NOWRELATIVE

public static final int NOWRELATIVE
See Also:
Constant Field Values

FALSE_EB

protected static final ExtendedBoolean FALSE_EB

TRUE_EB

protected static final ExtendedBoolean TRUE_EB

MAYBE_EB

protected static final ExtendedBoolean MAYBE_EB

granularity

protected Granularity granularity

lower

protected TimeValue lower

upper

protected TimeValue upper

pmf

protected ProbabilityMassFunction pmf
Constructor Detail

Granule

public Granule(TimeValue p)
Create a determinate granule at the default Granularity

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

Granule

public Granule(Granularity g,
               TimeValue p)
Create a determinate granule at the specified Granularity

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

Granule

public Granule(long p)
Create a determinate granule at the default Granularity

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

Granule

public Granule(Granularity g,
               long p)
Create a determinate granule at the specified Granularity

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

Granule

public Granule(TimeValue lower,
               TimeValue upper)
Create an indeterminate granule with an unknown PMF at the default Granularity

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

Granule

public Granule(long lower,
               long upper)
Create an indeterminate granule with an unknown PMF at the default Granularity

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

Granule

public Granule(Granularity g,
               TimeValue lower,
               TimeValue upper)
Create an indeterminate granule with an unknown PMF at the specified Granularity

Parameters:
g - - desired Granularity
lower - - count of granules
upper - - count of granules

Granule

public Granule(Granularity g,
               long lower,
               long upper)
Create an indeterminate granule with an unknown PMF at the specified Granularity

Parameters:
g - - desired Granularity
lower - - count of granules
upper - - count of granules

Granule

public Granule(TimeValue lower,
               TimeValue upper,
               ProbabilityMassFunction pmf)
Create an indeterminate granule with the specified PMF at the default Granularity

Parameters:
lower - - count of granules
upper - - count of granules
pmf - - probability mass function
Throws:
TauZamanException - if any abnormal condition occurs when setting this Granule's default Granularity

Granule

public Granule(long lower,
               long upper,
               ProbabilityMassFunction pmf)
Create an indeterminate granule with the specified PMF at the default Granularity

Parameters:
lower - - count of granules
upper - - count of granules
pmf - - probability mass function
Throws:
TauZamanException - if any abnormal condition occurs when setting this Granule's default Granularity

Granule

public Granule(Granularity g,
               TimeValue lower,
               TimeValue upper,
               ProbabilityMassFunction pmf)
Create an indeterminate granule with the specified PMF at the specified Granularity

Parameters:
g - - desired Granularity
lower - - count of granules
upper - - count of granules
pmf - - probability mass function

Granule

public Granule(Granularity g,
               long lower,
               long upper,
               ProbabilityMassFunction pmf)
Create an indeterminate granule with the specified PMF at the specified Granularity

Parameters:
g - - desired Granularity
lower - - count of granules
upper - - count of granules
pmf - - probability mass function
Method Detail

getGranularity

public Granularity getGranularity()
Accessor - retrieve the granularity of this granule

Returns:
the granularity

getKind

public int getKind()
Accessor - retrieve the kind of this granule, INDETERMINATE or DETERMINATE

Returns:
the kind

getGranule

public TimeValue getGranule()
Accessor - retrieve the granules from a determinate granule (defaults to lower bound for indeterminate granule)

Returns:
TimeValue object that records the granules

getLower

public TimeValue getLower()
Accessor - retrieve the lower bound from an indeterminate granule (defaults to granules for determinate granule)

Returns:
TimeValue object that records the lower bound

getUpper

public TimeValue getUpper()
Accessor - retrieve the upper bound from an indeterminate granule (defaults to granules for determinate granule)

Returns:
TimeValue object that records the lower bound

image

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

Returns:
String image of a granule

decrement

public Granule decrement()
Construct a Granule that has each bound decremented by 1

Returns:
this - 1

increment

public Granule increment()
Construct a Granule that has each bound incremented by 1

Returns:
this + 1

negate

public Granule negate()
Negate the granule. This method constructs a new granule that has both both bounds negated. Since the granule represents a distance, negation is well-defined. The PMF and granularity are unchanged.

Returns:
a new Granule with the lower and upper bounds negated

equalTo

public ExtendedBoolean equalTo(Granule other)
Is this == other? This returns an ExtendedBoolean value to capture the comparison for indeterminate granules. For determinate granules, two granules are equal if they represent the same granule. For indeterminate granules, the probability of their being equal must exceed the plausibility.

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

lessThan

public ExtendedBoolean lessThan(Granule other)
Is this < other? This returns an ExtendedBoolean value to capture the comparison for indeterminate granules. For determinate granules, a granule is < if the count is no smaller. For indeterminate granules, the probability of their being < must exceed the plausibility.

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

lessThanOrEqualTo

public ExtendedBoolean lessThanOrEqualTo(Granule other)
Is this <= other? This returns an ExtendedBoolean value to capture the comparison for indeterminate granules. For determinate granules, a granule is <= if the count is no smaller. For indeterminate granules, the probability of their being <= must exceed the plausibility.

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

greaterThan

public ExtendedBoolean greaterThan(Granule other)
Is this > other? This returns an ExtendedBoolean value to capture the comparison for indeterminate granules. For determinate granules, a granule is > if the count is no smaller. For indeterminate granules, the probability of their being > must exceed the plausibility.

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

greaterThanOrEqualTo

public ExtendedBoolean greaterThanOrEqualTo(Granule other)
Is this >= other? This returns an ExtendedBoolean value to capture the comparison for indeterminate granules. For determinate granules, a granule is >= if the count is no smaller. For indeterminate granules, the probability of their being >= must exceed the plausibility.

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

add

public Granule add(Granule other)
Construct a new Granule that is this + other. The addition is similar to that in interval mathematics, i.e., [a,b] + [c,d] = [a+c, b+d], where a and c are lower bounds and b and d are upper bounds of the respective granules. The granules must be at the same granularity. The addition discards the PMF, that is, the PMF of the new granule is (usually) unknown since the needed PMF is the convolution of the two PMFs which is difficult/expensive to construct on the fly.

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

subtract

public Granule subtract(Granule other)
Construct a new Granule that is this - other. The addition is similar to that in interval mathematics, i.e., [a,b] - [c,d] = [a-c, b-d], where a and c are lower bounds and b and d are upper bounds of the respective granules. The granules must be at the same granularity. The subtraction discards the PMF, that is, the PMF of the new granule is (usually) unknown since the needed PMF is the convolution of the two PMFs which is difficult/expensive to construct on the fly.

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

multiply

public Granule multiply(int n)
Multiply by a constant. This constructs a new Granule that is the the multiplication of the existing granule by a constant. Both bounds are multiplied, but the PMF and granularity remain the same.

Parameters:
n - - The divisor
Returns:
a new Granule with the lower and upper bounds multiplied by n

divide

public Granule divide(int n)
Divide by a constant. This constructs a new Granule that is the the division of the existing granule by a constant. Both bounds are divided, but the PMF and granularity remain the same.

Parameters:
n - - The divisor
Returns:
a new Granule with the lower and upper bounds divided by n

main

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

java.lang.Exception

tauZaman
v0.1

Submit a bug or feature

tauZaman is an open-source, publicly avaliable project