gov.sandia.cognition.math
Class MutableInteger

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

public class MutableInteger
extends Number
implements CloneableSerializable, Comparable<MutableInteger>, EuclideanRing<MutableInteger>, Vectorizable

A mutable object containing an integer. It is meant to be used for cases where you may want to use a java.lang.Integer 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.Integer.

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

Field Summary
 int value
          The value.
 
Constructor Summary
MutableInteger()
          Creates an MutableInteger with an initial value of zero.
MutableInteger(int value)
          Creates an MutableInteger with the given value.
MutableInteger(MutableInteger other)
          Creates a copy of a MutableInteger.
 
Method Summary
 MutableInteger clone()
          Creates a new clone (shallow copy) of this object.
 int compareTo(MutableInteger other)
           
 void convertFromVector(Vector parameters)
          Converts the object from a Vector of parameters.
 Vector1 convertToVector()
          Converts the object to a vector.
 MutableInteger divide(MutableInteger other)
          Divides this value by the other value, returning the result of the division as a new value.
 void divideEquals(MutableInteger other)
          Inline divises this value by the other value, storing the result inside this.
 MutableInteger dotTimes(MutableInteger other)
          Element-wise multiplication of this and other
 void dotTimesEquals(MutableInteger other)
          Inline element-wise multiplication of this and other
 double doubleValue()
           
 boolean equals(int other)
          Determines if this MutableInteger's value is equal to a given integer.
 boolean equals(MutableInteger other)
          Determines if this MutableInteger is equal to another MutableInteger.
 boolean equals(MutableInteger other, double effectiveZero)
          Determines if two RingType objects are effectively equal
 boolean equals(Object other)
          Determines if two RingType objects are equal
 float floatValue()
           
 int getValue()
          Gets the value stored in the object.
 int hashCode()
           
 int intValue()
           
 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()
           
 MutableInteger minus(MutableInteger other)
          Arithmetic subtraction of other from this
 void minusEquals(MutableInteger other)
          Inline arithmetic subtraction of other from this
 MutableInteger 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
 MutableInteger plus(MutableInteger other)
          Arithmetic addition of this and other
 void plusEquals(MutableInteger other)
          Inline arithmetic addition of this and other
 MutableInteger scale(double scaleFactor)
          Element-wise scaling of this by scaleFactor
 MutableInteger scaledMinus(double scaleFactor, MutableInteger other)
          Arithmetic subtraction other after element-wise scaling of other by scaleFactor from this.
 void scaledMinusEquals(double scaleFactor, MutableInteger other)
          Inline arithmetic subtraction of other after element-wise scaling of other by scaleFactor from this.
 MutableInteger scaledPlus(double scaleFactor, MutableInteger other)
          Arithmetic addition of this and other after element-wise scaling of other by scaleFactor.
 void scaledPlusEquals(double scaleFactor, MutableInteger 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(int value)
          Sets the value stored in the object.
 MutableInteger times(MutableInteger other)
          Multiplies this value by the other value, returning the result of the multiplication as a new value.
 void timesEquals(MutableInteger 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 int 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

MutableInteger

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


MutableInteger

public MutableInteger(int value)
Creates an MutableInteger with the given value.

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

MutableInteger

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

Parameters:
other - The other value.
Method Detail

clone

public MutableInteger 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<MutableInteger>
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<MutableInteger>
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(MutableInteger other)
Determines if this MutableInteger is equal to another MutableInteger. 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(int other)
Determines if this MutableInteger's value is equal to a given integer.

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

compareTo

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

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 int getValue()
Gets the value stored in the object.

Returns:
The value.

setValue

public void setValue(int 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(MutableInteger other,
                      double effectiveZero)
Description copied from interface: Ring
Determines if two RingType objects are effectively equal

Specified by:
equals in interface Ring<MutableInteger>
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 MutableInteger plus(MutableInteger other)
Description copied from interface: Ring
Arithmetic addition of this and other

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

plusEquals

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

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

minus

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

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

minusEquals

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

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

times

public MutableInteger times(MutableInteger 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<MutableInteger>
Parameters:
other - The other value.
Returns:
The result of the multiplication.

timesEquals

public void timesEquals(MutableInteger 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<MutableInteger>
Parameters:
other - The other value.

divide

public MutableInteger divide(MutableInteger 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<MutableInteger>
Parameters:
other - The other value.
Returns:
The result of the division.

divideEquals

public void divideEquals(MutableInteger 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<MutableInteger>
Parameters:
other - The other value.

dotTimes

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

Specified by:
dotTimes in interface Ring<MutableInteger>
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(MutableInteger other)
Description copied from interface: Ring
Inline element-wise multiplication of this and other

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

scale

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

Specified by:
scale in interface Ring<MutableInteger>
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<MutableInteger>
Parameters:
scaleFactor - amount to scale the elements of this

scaledPlus

public MutableInteger scaledPlus(double scaleFactor,
                                 MutableInteger 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<MutableInteger>
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,
                             MutableInteger 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<MutableInteger>
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 MutableInteger scaledMinus(double scaleFactor,
                                  MutableInteger 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<MutableInteger>
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,
                              MutableInteger 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<MutableInteger>
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 MutableInteger 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<MutableInteger>
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<MutableInteger>

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<MutableInteger>

isZero

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

Specified by:
isZero in interface Ring<MutableInteger>
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<MutableInteger>
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.