tauZaman
v0.1

tauzaman.calendricsystem.granularitylattice
Class GranularityLattice

java.lang.Object
  |
  +--tauzaman.calendricsystem.granularitylattice.GranularityLattice

public class GranularityLattice
extends java.lang.Object


Field Summary
static boolean CACHE_DEBUG
           
 
Constructor Summary
GranularityLattice(Calendar[] calendars, Mapping[] interCalMappings)
          Constructs a GranularityLattice object.
 
Method Summary
 void addCalendar(Calendar calendar)
          Adds an entire calendar to the lattice by going through each mapping in the calendar, adding any nodes that are not already in the lattice plus the edges connecting the nodes in each mapping.
 void addMapping(Mapping mapping)
          Creates an edge between the "from" granularity and the "to" granularity in the Mapping object with the Mapping object itself as the edge's label.
 Granule castAnchored(Granule granule, Granularity toGranularity)
          Uses the lattice to cast the given anchored granule from its granularity to another granularity.
 Granule castUnanchored(Granule granule, Granularity toGranularity)
          Uses the lattice to cast the given unanchored granule from its granularity to another granularity.
 void clearCaches()
          Resets all of the lattice's caches.
 boolean isCoarser(Granularity g1, Granularity g2)
          Uses the lattice to determine if one granularity is coarser than another.
 boolean isEquivalent(Granularity g1, Granularity g2)
          Uses the lattice to determine if the two granularities are equivalent.
 boolean isFiner(Granularity g1, Granularity g2)
          Uses the lattice to determine if one granularity is finer than another.
 boolean isIncomparable(Granularity g1, Granularity g2)
          Uses the lattice to determine if the two granularities are equivalent.
 java.lang.String toString()
          Returns a string representation of the lattice.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CACHE_DEBUG

public static boolean CACHE_DEBUG
Constructor Detail

GranularityLattice

public GranularityLattice(Calendar[] calendars,
                          Mapping[] interCalMappings)
                   throws CalendricSystemFormationException
Constructs a GranularityLattice object. The construction is done by: (1) For each calendar in calendars, get the calendar's mappings and set up LatticeNodes for each granularity encountered and connecting the nodes with the mappings themselves. (2) Connecting the granularities in different calendars using the mappings in the inter-calendar mappings array.

Parameters:
calendars - the array of all Calendar objects that are in this calendric system
Throws:
CalendricSystemFormationException - if any error occurs while forming GranularityLattice
Method Detail

addCalendar

public void addCalendar(Calendar calendar)
                 throws CalendricSystemFormationException
Adds an entire calendar to the lattice by going through each mapping in the calendar, adding any nodes that are not already in the lattice plus the edges connecting the nodes in each mapping.

Parameters:
calendar - Calendar to be added to the lattice
CalendricSystemFormationException

addMapping

public void addMapping(Mapping mapping)
                throws CalendricSystemFormationException
Creates an edge between the "from" granularity and the "to" granularity in the Mapping object with the Mapping object itself as the edge's label.

Parameters:
mapping - Mapping that is the edge's label
Throws:
NoSuchGranularityException - if either of the Granularities in the mapping are not recognized by the lattice (i.e., there is no node in the lattice that has this granularity)
CalendricSystemFormationException

castAnchored

public Granule castAnchored(Granule granule,
                            Granularity toGranularity)
                     throws CalendricSystemServiceException
Uses the lattice to cast the given anchored granule from its granularity to another granularity.

Parameters:
granule - the granule to cast from its granularity to another granularity
toGranularity - the granularity to which to cast the given granule
Returns:
a Granule that represent the given granule converted to the given granularity
Throws:
CalendricSystemServiceException - if either the Granularity of the given granule or the toGranularity are not recognized by the lattice (i.e., there is no node in the lattice that has this granularity)

castUnanchored

public Granule castUnanchored(Granule granule,
                              Granularity toGranularity)
                       throws CalendricSystemServiceException
Uses the lattice to cast the given unanchored granule from its granularity to another granularity.

Parameters:
granule - the granule to cast from its granularity to another granularity
toGranularity - the granularity to which to cast the given granule
Returns:
a Granule that represent the given granule converted to the given granularity
Throws:
CalendricSystemServiceException - if either the Granularity of the given granule or the toGranularity are not recognized by the lattice (i.e., there is no node in the lattice that has this granularity)

isCoarser

public boolean isCoarser(Granularity g1,
                         Granularity g2)
                  throws CalendricSystemServiceException
Uses the lattice to determine if one granularity is coarser than another.

Parameters:
g1 - the first granule to be compared
g2 - the second granule to be compared
Returns:
true if g1 is coarser than g2, false if g1 is finer than g2 or if g1 and g2 cannot be compared
Throws:
NoSuchGranularityException - if either of the granularities passed in are not recognized by the lattice (i.e., there is no node in the lattice that has this granularity)
CalendricSystemServiceException

isEquivalent

public boolean isEquivalent(Granularity g1,
                            Granularity g2)
                     throws CalendricSystemServiceException
Uses the lattice to determine if the two granularities are equivalent.

Parameters:
g1 - the first granule to be compared for equivalence
g2 - the second granule to be compared for equivalence
Returns:
true if g1 is equivalent to g2, false if g1 is not equivalent to g2
Throws:
NoSuchGranularityException - if either of the granularities passed in are not recognized by the lattice (i.e., there is no node in the lattice that has this granularity)
CalendricSystemServiceException

isIncomparable

public boolean isIncomparable(Granularity g1,
                              Granularity g2)
                       throws CalendricSystemServiceException
Uses the lattice to determine if the two granularities are equivalent.

Parameters:
g1 - the first granule to be compared for equivalence
g2 - the second granule to be compared for equivalence
Returns:
true if g1 is equivalent to g2, false if g1 is not equivalent to g2
Throws:
NoSuchGranularityException - if either of the granularities passed in are not recognized by the lattice (i.e., there is no node in the lattice that has this granularity)
CalendricSystemServiceException

isFiner

public boolean isFiner(Granularity g1,
                       Granularity g2)
                throws CalendricSystemServiceException
Uses the lattice to determine if one granularity is finer than another.

Parameters:
g1 - the first granule to be compared
g2 - the second granule to be compared
Returns:
true if g1 is finer than g2, false if g1 is coarser than g2 or if g1 and g2 cannot be compared
Throws:
NoSuchGranularityException - if either of the granularities passed in are not recognized by the lattice (i.e., there is no node in the lattice that has this granularity)
CalendricSystemServiceException

clearCaches

public void clearCaches()
Resets all of the lattice's caches.


toString

public java.lang.String toString()
Returns a string representation of the lattice.

Overrides:
toString in class java.lang.Object
Returns:
a String representation of the lattice.

tauZaman
v0.1

Submit a bug or feature

tauZaman is an open-source, publicly avaliable project