Jive Forums API (5.5.20.2-oracle) Developer Javadocs

com.jivesoftware.base.stats.element
Class CyclicElement

java.lang.Object
  extended by com.jivesoftware.base.stats.Element
      extended by com.jivesoftware.base.stats.element.LongElement
          extended by com.jivesoftware.base.stats.element.CyclicElement
All Implemented Interfaces:
java.lang.Comparable

public class CyclicElement
extends LongElement

An Element for which values wrap around after being incremented a sufficient number of times. This type of element is useful for dealing with days of the week, months of the year, hours of the day, and so on. Usually used with a CyclicSequence.

See Also:
CyclicSequence

Constructor Summary
CyclicElement(long cycleSize, long cycleStart, long n)
          Creates new CyclicElement with a specified cycle size, lower bound and an initial starting point.
 
Method Summary
 int compare(java.lang.Object o1, java.lang.Object o2)
          Compare two CyclicElements.
 boolean equals(java.lang.Object o)
          Test two CyclicEements for equality.
 long getCanonicalValue(long n)
          Helper function used to map a long to a value in [cycleStart, cycleStart+cycleSize)
 long getCycleSize()
          Returns the size of the cycle, for example 7 for a week long cycle.
 long getCycleStart()
          Returns the lower bound of the cycle.
 Element getInstance(long n)
          Generate a new CyclicElement.
 int hashCode()
          Generate a hashCode for the current element.
static void main(java.lang.String[] args)
           
 
Methods inherited from class com.jivesoftware.base.stats.element.LongElement
compareTo, getValue, setLongElement, toLong, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CyclicElement

public CyclicElement(long cycleSize,
                     long cycleStart,
                     long n)
Creates new CyclicElement with a specified cycle size, lower bound and an initial starting point.

Parameters:
cycleSize - the length of the cycle. When the internal counter reaches cycleSize+cycleStart, the counter will be reset to cycleStart.
cycleStart - Start of the cycle, used for comparing two CyclicElements.
n - Value of this element.
Method Detail

getCycleSize

public long getCycleSize()
Returns the size of the cycle, for example 7 for a week long cycle.

Returns:
the size of the cycle.

getCycleStart

public long getCycleStart()
Returns the lower bound of the cycle.

Returns:
the lower bound of the cycle.

getInstance

public Element getInstance(long n)
Generate a new CyclicElement. The new element will have the same cycleSize as the current one.

Overrides:
getInstance in class LongElement
Parameters:
n - Value for new CyclicElement
Returns:
a new CyclicElement

hashCode

public int hashCode()
Generate a hashCode for the current element.

Overrides:
hashCode in class LongElement
Returns:
a hash code for this object.

equals

public boolean equals(java.lang.Object o)
Test two CyclicEements for equality.

Overrides:
equals in class LongElement
Returns:
true if the two objects are both CyclicElements and they are both equal.

compare

public int compare(java.lang.Object o1,
                   java.lang.Object o2)
Compare two CyclicElements.

Parameters:
o1 - First object to compare.
o2 - Second object to compare.
Returns:
-1 if o1 < o2, 0 if o1 == o2, or 1 if o1 > o2

getCanonicalValue

public long getCanonicalValue(long n)
Helper function used to map a long to a value in [cycleStart, cycleStart+cycleSize)


main

public static void main(java.lang.String[] args)

Jive Forums Project Page

Copyright © 1999-2006 Jive Software.