gov.sandia.cognition.math
Class MutableDouble

java.lang.Object
  extended by java.lang.Number
      extended by gov.sandia.cognition.math.MutableDouble
All Implemented Interfaces:
EuclideanRing<MutableDouble>, Field<MutableDouble>, Vectorizable, Ring<MutableDouble>, CloneableSerializable, Serializable, Cloneable, Comparable<MutableDouble>

public class MutableDouble
extends Number
implements CloneableSerializable, Comparable<MutableDouble>, Field<MutableDouble>, Vectorizable

A mutable object containing a double. It is meant to be used for cases where you may want to use a java.lang.Double but its value will be updated frequently, such as in a map or other data structure. Many of the implementations of the methods in this class are based on the behavior described in java.lang.Double.

Since:
3.2.0
Author:
Justin Basilico
See Also:
Serialized Form

Field Summary
 double value
          The value.
 
Constructor Summary
MutableDouble()
          Creates an MutableDouble with an initial value of zero.
MutableDouble(double value)
          Creates an MutableDouble with the given value.
MutableDouble(MutableDouble other)
          Creates a copy of a MutableDouble.
 
Method Summary
 MutableDouble clone()
          Creates a new clone (shallow copy) of this object.
 int compareTo(MutableDouble other)
           
 void convertFromVector(Vector parameters)
          Converts the object from a Vector of parameters.
 Vector1 convertToVector()
          Converts the object to a vector.
 MutableDouble divide(MutableDouble other)
          Divides this value by the other value, returning the result of the division as a new value.
 void divideEquals(MutableDouble other)
          Inline divises this value by the other value, storing the result inside this.
 MutableDouble dotTimes(MutableDouble other)
          Element-wise multiplication of this and other
 void dotTimesEquals(MutableDouble other)
          Inline element-wise multiplication of this and other
 double doubleValue()
           
 boolean equals(double other)
          Determines if this MutableDouble's value is equal to a given double.
 boolean equals(MutableDouble other)
          Determines if this MutableDouble is equal to another MutableDouble.
 boolean equals(MutableDouble other, double effectiveZero)
          Determines if two RingType objects are effectively equal
 boolean equals(Object other)
          Determines if two RingType objects are equal
 float floatValue()
           
 double getValue()
          Gets the value stored in the object.
 int hashCode()
           
 int intValue()
           
 MutableDouble inverse()
          Returns the inverse of this.
 void inverseEquals()
          Changes this value to be its inverse.
 boolean isZero()
          Determines if this ring is equal to zero.
 boolean isZero(double effectiveZero)
          Determines if this ring is equal to zero using the element-wise effective zero value.
 long longValue()
           
 MutableDouble minus(MutableDouble other)
          Arithmetic subtraction of other from this
 void minusEquals(MutableDouble other)
          Inline arithmetic subtraction of other from this
 MutableDouble negative()
          Returns the element-wise negation of this, such that this.plus( this.negative() ) has only zero elements.
 void negativeEquals()
          Inline element-wise negation of this
 MutableDouble plus(MutableDouble other)
          Arithmetic addition of this and other
 void plusEquals(MutableDouble other)
          Inline arithmetic addition of this and other
 MutableDouble scale(double scaleFactor)
          Element-wise scaling of this by scaleFactor
 MutableDouble scaledMinus(double scaleFactor, MutableDouble other)
          Arithmetic subtraction other after element-wise scaling of other by scaleFactor from this.
 void scaledMinusEquals(double scaleFactor, MutableDouble other)
          Inline arithmetic subtraction of other after element-wise scaling of other by scaleFactor from this.
 MutableDouble scaledPlus(double scaleFactor, MutableDouble other)
          Arithmetic addition of this and other after element-wise scaling of other by scaleFactor.
 void scaledPlusEquals(double scaleFactor, MutableDouble other)
          Inline arithmetic addition of this and other after element-wise scaling of other by scaleFactor.
 void scaleEquals(double scaleFactor)
          Inline element-wise scaling of this by scaleFactor
 void setValue(double value)
          Sets the value stored in the object.
 MutableDouble times(MutableDouble other)
          Multiplies this value by the other value, returning the result of the multiplication as a new value.
 void timesEquals(MutableDouble other)
          Inline multiplies this value by the other value, storing the result inside this.
 String toString()
           
 void zero()
          Zeros out all elements of this, so that the following are equivalent r1.scaleEquals( 0.0 ); and r1.zero(); Furthermore, r1.zero(); anything.dotTimes( r1 ).equals( r1 );
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

value

public double value
The value. Note: This is public just for performance reasons when people don't want to do the getter/setter for overhead reasons.

Constructor Detail

MutableDouble

public MutableDouble()
Creates an MutableDouble with an initial value of zero.


MutableDouble

public MutableDouble(double value)
Creates an MutableDouble with the given value.

Parameters:
value - The value to store in the object.

MutableDouble

public MutableDouble(MutableDouble other)
Creates a copy of a MutableDouble.

Parameters:
other - The other value.
Method Detail

clone

public MutableDouble clone()
Description copied from interface: CloneableSerializable
Creates a new clone (shallow copy) of this object.

Specified by:
clone in interface Vectorizable
Specified by:
clone in interface Ring<MutableDouble>
Specified by:
clone in interface CloneableSerializable
Overrides:
clone in class Object
Returns:
A new clone (shallow copy) of this object.

equals

public boolean equals(Object other)
Description copied from interface: Ring
Determines if two RingType objects are equal

Specified by:
equals in interface Ring<MutableDouble>
Overrides:
equals in class Object
Parameters:
other - RingType to compare against this
Returns:
True if the two objects are equal, false otherwise

equals

public boolean equals(MutableDouble other)
Determines if this MutableDouble is equal to another MutableDouble. Provides a convenience for not casting.

Parameters:
other - The other value.
Returns:
True if the two values are equal and false otherwise.

equals

public boolean equals(double other)
Determines if this MutableDouble's value is equal to a given double. This is done using the Double equals method, which converts the values to a long and then does equality on those. Thus, for strange values, this may not be exactly the same as ==. For example, -0.0 == +0.0 is true but -0.0.equals(+0.0) is false. Likewise, NaN == NaN is false, but NaN.equals(NaN) is true. Thus, this method conforms to the Double equality method.

Parameters:
other - A double.
Returns:
True if the two values are equal (according to Double.equals) and false otherwise.

compareTo

public int compareTo(MutableDouble other)
Specified by:
compareTo in interface Comparable<MutableDouble>

hashCode

public int hashCode()
Overrides:
hashCode in class Object

intValue

public int intValue()
Specified by:
intValue in class Number

longValue

public long longValue()
Specified by:
longValue in class Number

floatValue

public float floatValue()
Specified by:
floatValue in class Number

doubleValue

public double doubleValue()
Specified by:
doubleValue in class Number

getValue

public double getValue()
Gets the value stored in the object.

Returns:
The value.

setValue

public void setValue(double value)
Sets the value stored in the object.

Parameters:
value - The value.

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(MutableDouble other,
                      double effectiveZero)
Description copied from interface: Ring
Determines if two RingType objects are effectively equal

Specified by:
equals in interface Ring<MutableDouble>
Parameters:
other - RingType to compare against this
effectiveZero - tolerance threshold for element-wise equality
Returns:
True if the two objects are equal, false otherwise

plus

public MutableDouble plus(MutableDouble other)
Description copied from interface: Ring
Arithmetic addition of this and other

Specified by:
plus in interface Ring<MutableDouble>
Parameters:
other - object to add to this
Returns:
sum of this and other

plusEquals

public void plusEquals(MutableDouble other)
Description copied from interface: Ring
Inline arithmetic addition of this and other

Specified by:
plusEquals in interface Ring<MutableDouble>
Parameters:
other - object to add to this

minus

public MutableDouble minus(MutableDouble other)
Description copied from interface: Ring
Arithmetic subtraction of other from this

Specified by:
minus in interface Ring<MutableDouble>
Parameters:
other - object to subtract from this
Returns:
difference of this and other

minusEquals

public void minusEquals(MutableDouble other)
Description copied from interface: Ring
Inline arithmetic subtraction of other from this

Specified by:
minusEquals in interface Ring<MutableDouble>
Parameters:
other - object to subtract from this

times

public MutableDouble times(MutableDouble other)
Description copied from interface: EuclideanRing
Multiplies this value by the other value, returning the result of the multiplication as a new value.

Specified by:
times in interface EuclideanRing<MutableDouble>
Parameters:
other - The other value.
Returns:
The result of the multiplication.

timesEquals

public void timesEquals(MutableDouble other)
Description copied from interface: EuclideanRing
Inline multiplies this value by the other value, storing the result inside this.

Specified by:
timesEquals in interface EuclideanRing<MutableDouble>
Parameters:
other - The other value.

divide

public MutableDouble divide(MutableDouble other)
Description copied from interface: EuclideanRing
Divides this value by the other value, returning the result of the division as a new value.

Specified by:
divide in interface EuclideanRing<MutableDouble>
Parameters:
other - The other value.
Returns:
The result of the division.

divideEquals

public void divideEquals(MutableDouble other)
Description copied from interface: EuclideanRing
Inline divises this value by the other value, storing the result inside this.

Specified by:
divideEquals in interface EuclideanRing<MutableDouble>
Parameters:
other - The other value.

dotTimes

public MutableDouble dotTimes(MutableDouble other)
Description copied from interface: Ring
Element-wise multiplication of this and other

Specified by:
dotTimes in interface Ring<MutableDouble>
Parameters:
other - elements of other will be multiplied to the corresponding elements of this
Returns:
element-wise multiplication of this and other

dotTimesEquals

public void dotTimesEquals(MutableDouble other)
Description copied from interface: Ring
Inline element-wise multiplication of this and other

Specified by:
dotTimesEquals in interface Ring<MutableDouble>
Parameters:
other - elements of other will be multiplied to the corresponding elements of this

scale

public MutableDouble scale(double scaleFactor)
Description copied from interface: Ring
Element-wise scaling of this by scaleFactor

Specified by:
scale in interface Ring<MutableDouble>
Parameters:
scaleFactor - amount to scale the elements of this
Returns:
scaling of this

scaleEquals

public void scaleEquals(double scaleFactor)
Description copied from interface: Ring
Inline element-wise scaling of this by scaleFactor

Specified by:
scaleEquals in interface Ring<MutableDouble>
Parameters:
scaleFactor - amount to scale the elements of this

scaledPlus

public MutableDouble scaledPlus(double scaleFactor,
                                MutableDouble other)
Description copied from interface: Ring
Arithmetic addition of this and other after element-wise scaling of other by scaleFactor. If this is x, other is y, and scaleFactor is a, then this method is equivalent to x + a * y. It is typically a more efficient way of doing this.plus(other.scale(scaleFactor)) since it can avoid intermediate object creation.

Specified by:
scaledPlus in interface Ring<MutableDouble>
Parameters:
scaleFactor - The scale factor to multiply by the elements of other before adding to the elements of this.
other - Object to scale and then add to this.
Returns:
The result of applying the scale factor to other then adding to this.

scaledPlusEquals

public void scaledPlusEquals(double scaleFactor,
                             MutableDouble other)
Description copied from interface: Ring
Inline arithmetic addition of this and other after element-wise scaling of other by scaleFactor. If this is x, other is y, and scaleFactor is a, then this method is equivalent to x += a * y. It is typically a more efficient way of doing this.plusEquals(other.scale(scaleFactor)) since it can avoid intermediate object creation.

Specified by:
scaledPlusEquals in interface Ring<MutableDouble>
Parameters:
scaleFactor - The scale factor to multiply by the elements of other before adding to the elements of this.
other - Object to scale and then add to this.

scaledMinus

public MutableDouble scaledMinus(double scaleFactor,
                                 MutableDouble other)
Description copied from interface: Ring
Arithmetic subtraction other after element-wise scaling of other by scaleFactor from this. If this is x, other is y, and scaleFactor is a, then this method is equivalent to x - a * y. It is typically a more efficient way of doing this.minus(other.scale(scaleFactor)) since it can avoid intermediate object creation.

Specified by:
scaledMinus in interface Ring<MutableDouble>
Parameters:
scaleFactor - The scale factor to multiply by the elements of other before subtracting from the elements of this.
other - Object to scale and then subtract from this.
Returns:
The result of applying the scale factor to other then subtract from this.

scaledMinusEquals

public void scaledMinusEquals(double scaleFactor,
                              MutableDouble other)
Description copied from interface: Ring
Inline arithmetic subtraction of other after element-wise scaling of other by scaleFactor from this. If this is x, other is y, and scaleFactor is a, then this method is equivalent to x -= a * y. It is typically a more efficient way of doing this.minusEquals(other.scale(scaleFactor)) since it can avoid intermediate object creation.

Specified by:
scaledMinusEquals in interface Ring<MutableDouble>
Parameters:
scaleFactor - The scale factor to multiply by the elements of other before adding to the elements of this.
other - Object to scale and then add to this.

negative

public MutableDouble negative()
Description copied from interface: Ring
Returns the element-wise negation of this, such that this.plus( this.negative() ) has only zero elements.

Specified by:
negative in interface Ring<MutableDouble>
Returns:
element-wise negation of this

negativeEquals

public void negativeEquals()
Description copied from interface: Ring
Inline element-wise negation of this

Specified by:
negativeEquals in interface Ring<MutableDouble>

inverse

public MutableDouble inverse()
Description copied from interface: Field
Returns the inverse of this.

Specified by:
inverse in interface Field<MutableDouble>
Returns:
The inverse of this field.

inverseEquals

public void inverseEquals()
Description copied from interface: Field
Changes this value to be its inverse.

Specified by:
inverseEquals in interface Field<MutableDouble>

zero

public void zero()
Description copied from interface: Ring
Zeros out all elements of this, so that the following are equivalent r1.scaleEquals( 0.0 ); and r1.zero(); Furthermore, r1.zero(); anything.dotTimes( r1 ).equals( r1 );

Specified by:
zero in interface Ring<MutableDouble>

isZero

public boolean isZero()
Description copied from interface: Ring
Determines if this ring is equal to zero.

Specified by:
isZero in interface Ring<MutableDouble>
Returns:
True if all of the elements of this ring are zero.

isZero

public boolean isZero(double effectiveZero)
Description copied from interface: Ring
Determines if this ring is equal to zero using the element-wise effective zero value.

Specified by:
isZero in interface Ring<MutableDouble>
Parameters:
effectiveZero - Tolerance threshold for element-wise equality
Returns:
True if all of the elements of this ring are effectively zero.

convertToVector

public Vector1 convertToVector()
Description copied from interface: Vectorizable
Converts the object to a vector.

Specified by:
convertToVector in interface Vectorizable
Returns:
The Vector form of the object.

convertFromVector

public void convertFromVector(Vector parameters)
Description copied from interface: Vectorizable
Converts the object from a Vector of parameters.

Specified by:
convertFromVector in interface Vectorizable
Parameters:
parameters - The parameters to incorporate.