celeboss.data
Class ChangableValue

java.lang.Object
  extended byceleboss.data.ChangableValue
All Implemented Interfaces:
java.lang.Comparable, java.io.Serializable
Direct Known Subclasses:
ChangableMinMaxValue, PercentChangableValue

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

This class represents a value that changes over time. It records a float representation for the current value. It also holds the sign of the first derivative of the changing value, hence the value can be increasing, decreasing or in a no change state.

Version:
1.0
Author:
bevans
See Also:
Serialized Form

Field Summary
static short DECREASING
          Constant for an decreasing value
static short INCREASING
          Constant for an increasing value
static short NOCHANGE
          Constant for an unchanging value
 
Constructor Summary
ChangableValue()
          Create a new changable value with default value
ChangableValue(float initalValue)
          Create a new changable value with the intial value.
 
Method Summary
 int compareTo(java.lang.Object arg0)
          Compare this vlaue with another object.
 boolean equals(java.lang.Object other)
          Compare this value to another.
 long getChangedOn()
          When did the value change
 java.text.NumberFormat getDefaultFormat()
          Format to use for toString method.
 int getIncreasing()
          Is this value increasing or decreasing
static long getMaximumAge()
          Get the maximum age values are allowed before they are rest
 double getOldValue()
          Get the numeric old value as a double.
 float getValue()
          Get the numeric value as a double.
 int hashCode()
           
 void resetValue()
          This method resets the old value to the current value.
static void setFormat(java.text.NumberFormat format)
          Set the default formatting for currency value.
static void setMaximumAge(long maximumAge)
          Set teh maximum age than values are allowed before they get reset as not moving
 boolean setValue(float newValue)
          Attempts to update teh vlaue of this changable.
 java.lang.String toString()
          Get the current value as a string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DECREASING

public static final short DECREASING
Constant for an decreasing value

See Also:
Constant Field Values

INCREASING

public static final short INCREASING
Constant for an increasing value

See Also:
Constant Field Values

NOCHANGE

public static final short NOCHANGE
Constant for an unchanging value

See Also:
Constant Field Values
Constructor Detail

ChangableValue

public ChangableValue()
Create a new changable value with default value


ChangableValue

public ChangableValue(float initalValue)
Create a new changable value with the intial value.

Parameters:
initalValue - Starting value
Method Detail

getMaximumAge

public static long getMaximumAge()
Get the maximum age values are allowed before they are rest

Returns:
Returns the maximumAge in minutes

setFormat

public static void setFormat(java.text.NumberFormat format)
Set the default formatting for currency value.

Parameters:
format - Number format to use.
See Also:
toString()

setMaximumAge

public static void setMaximumAge(long maximumAge)
Set teh maximum age than values are allowed before they get reset as not moving

Parameters:
maximumAge - The maximumAge to set in minutes

compareTo

public int compareTo(java.lang.Object arg0)
Compare this vlaue with another object. The comparision just checks the double values, not the direction of change.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
arg0 - Object to compare against.
Returns:
Int vlaue for difference.
See Also:
Comparable.compareTo(java.lang.Object)

equals

public boolean equals(java.lang.Object other)
Compare this value to another. If the other is a ChangableValue then the comparision is based on the current value.

Parameters:
other - The other object to compare.
Returns:
Result of comparision.
See Also:
Object.equals(java.lang.Object)

getChangedOn

public long getChangedOn()
When did the value change

Returns:
Returns the changedOn.

getDefaultFormat

public java.text.NumberFormat getDefaultFormat()
Format to use for toString method. This method should be overriden by any subclass to modify the string representation to reflect the data represented by the float values.

Returns:
Number format.

getIncreasing

public int getIncreasing()
Is this value increasing or decreasing

Returns:
Returns the increasing.

getOldValue

public double getOldValue()
Get the numeric old value as a double.

Returns:
double

getValue

public float getValue()
Get the numeric value as a double.

Returns:
double

hashCode

public int hashCode()
Returns:
Hash code value
See Also:
Object.hashCode()

resetValue

public void resetValue()
This method resets the old value to the current value. This method would generally be used to reset the value when it has expired and the chnage is no longer to be recorded.


setValue

public boolean setValue(float newValue)
Attempts to update teh vlaue of this changable. If the incoming value is different from the current value, an update is performed. If the incomign value is the same as the current, an update is only performed if the value is older than the age.

Parameters:
newValue - New value.
Returns:
Was an update performed.

toString

public java.lang.String toString()
Get the current value as a string. This uses the default NumberFormat for the system locale and Currency.

Returns:
String representation.
See Also:
Object.toString(), NumberFormat.getCurrencyInstance()