gov.sandia.cognition.math
Class MutableLong

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

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

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

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

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

MutableLong

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


MutableLong

public MutableLong(long value)
Creates an MutableLong with the given value.

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

MutableLong

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

Parameters:
other - The other value.
Method Detail

clone

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

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

compareTo

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

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

Returns:
The value.

setValue

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

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

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

plusEquals

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

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

minus

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

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

minusEquals

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

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

times

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

timesEquals

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

divide

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

divideEquals

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

dotTimes

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

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

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

scale

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

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

scaledPlus

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

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

isZero

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

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