Class ModifiableInteger
- java.lang.Object
-
- java.lang.Number
-
- org.jgrapht.util.ModifiableInteger
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<ModifiableInteger>
public class ModifiableInteger extends java.lang.Number implements java.lang.Comparable<ModifiableInteger>
TheModifiableIntegerclass wraps a value of the primitive typeintin an object, similarly toInteger. An object of typeModifiableIntegercontains a single field whose type isint.Unlike
java.lang.Integer, the int value which the ModifiableInteger represents can be modified. It becomes useful when used together with the collection framework. For example, if you want to have aListof counters. You could useIntegerbut that would have became wasteful and inefficient if you frequently had to update the counters.WARNING: Because instances of this class are mutable, great care must be exercised if used as keys of a
Mapor as values in aSetin a manner that affects equals comparisons while the instances are keys in the map (or values in the set). For more see documentation ofMapandSet.- Author:
- Barak Naveh
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description intvalueThe int value represented by thisModifiableInteger.
-
Constructor Summary
Constructors Constructor Description ModifiableInteger()Deprecated.not really deprecated, just marked so to avoid mistaken use.ModifiableInteger(int value)Constructs a newly allocatedModifiableIntegerobject that represents the specifiedintvalue.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(ModifiableInteger anotherInteger)Compares twoModifiableIntegerobjects numerically.voiddecrement()Subtracts one from the value of this modifiable integer.doubledoubleValue()booleanequals(java.lang.Object o)Compares this object to the specified object.floatfloatValue()intgetValue()Returns the value of this object, similarly tointValue().inthashCode()Returns a hash code for thisModifiableInteger.voidincrement()Adds one to the value of this modifiable integer.intintValue()longlongValue()voidsetValue(int value)Sets a new value for this modifiable integer.java.lang.IntegertoInteger()Returns anIntegerobject representing thisModifiableInteger's value.java.lang.StringtoString()Returns aStringobject representing thisModifiableInteger's value.
-
-
-
Constructor Detail
-
ModifiableInteger
@Deprecated public ModifiableInteger()
Deprecated.not really deprecated, just marked so to avoid mistaken use.!!! DON'T USE - Use theModifiableInteger(int)constructor instead !!!This constructor is for the use of java.beans.XMLDecoder deserialization. The constructor is marked as 'deprecated' to indicate to the programmer against using it by mistake.
-
ModifiableInteger
public ModifiableInteger(int value)
Constructs a newly allocatedModifiableIntegerobject that represents the specifiedintvalue.- Parameters:
value- the value to be represented by theModifiableIntegerobject.
-
-
Method Detail
-
setValue
public void setValue(int value)
Sets a new value for this modifiable integer.- Parameters:
value- the new value to set.
-
getValue
public int getValue()
Returns the value of this object, similarly tointValue(). This getter is NOT redundant. It is used for serialization by java.beans.XMLEncoder.- Returns:
- the value.
-
increment
public void increment()
Adds one to the value of this modifiable integer.
-
decrement
public void decrement()
Subtracts one from the value of this modifiable integer.
-
compareTo
public int compareTo(ModifiableInteger anotherInteger)
Compares twoModifiableIntegerobjects numerically.- Specified by:
compareToin interfacejava.lang.Comparable<ModifiableInteger>- Parameters:
anotherInteger- theModifiableIntegerto be compared.- Returns:
- the value
0if thisModifiableIntegeris equal to the argumentModifiableInteger; a value less than0if thisModifiableIntegeris numerically less than the argumentModifiableInteger; and a value greater than0if thisModifiableIntegeris numerically greater than the argumentModifiableInteger(signed comparison).
-
doubleValue
public double doubleValue()
- Specified by:
doubleValuein classjava.lang.Number- See Also:
Number.doubleValue()
-
equals
public boolean equals(java.lang.Object o)
Compares this object to the specified object. The result istrueif and only if the argument is notnulland is anModifiableIntegerobject that contains the sameintvalue as this object.- Overrides:
equalsin classjava.lang.Object- Parameters:
o- the object to compare with.- Returns:
trueif the objects are the same;falseotherwise.
-
floatValue
public float floatValue()
- Specified by:
floatValuein classjava.lang.Number- See Also:
Number.floatValue()
-
hashCode
public int hashCode()
Returns a hash code for thisModifiableInteger.- Overrides:
hashCodein classjava.lang.Object- Returns:
- a hash code value for this object, equal to the primitive
intvalue represented by thisModifiableIntegerobject.
-
intValue
public int intValue()
- Specified by:
intValuein classjava.lang.Number- See Also:
Number.intValue()
-
longValue
public long longValue()
- Specified by:
longValuein classjava.lang.Number- See Also:
Number.longValue()
-
toInteger
public java.lang.Integer toInteger()
Returns anIntegerobject representing thisModifiableInteger's value.- Returns:
- an
Integerrepresentation of the value of this object.
-
toString
public java.lang.String toString()
Returns aStringobject representing thisModifiableInteger's value. The value is converted to signed decimal representation and returned as a string, exactly as if the integer value were given as an argument to theInteger.toString(int)method.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representation of the value of this object in base 10.
-
-