- All Implemented Interfaces:
Serializable,Comparable<ModifiableInteger>
ModifiableInteger class wraps a value of the primitive type int in
an object, similarly to Integer. An object of type
ModifiableInteger contains a single field whose type is int.
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 a List of counters. You could use Integer but
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 Map or as values in a Set in a manner that affects
equals comparisons while the instances are keys in the map (or values in the set). For more see
documentation of Map and Set.
- Author:
- Barak Naveh
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.not really deprecated, just marked so to avoid mistaken use.ModifiableInteger(int value) Constructs a newly allocatedModifiableIntegerobject that represents the specifiedintvalue. -
Method Summary
Modifier and TypeMethodDescriptionintcompareTo(ModifiableInteger anotherInteger) Compares twoModifiableIntegerobjects numerically.voidSubtracts one from the value of this modifiable integer.doublebooleanCompares this object to the specified object.floatintgetValue()Returns the value of this object, similarly tointValue().inthashCode()Returns a hash code for thisModifiableInteger.voidAdds one to the value of this modifiable integer.intintValue()longvoidsetValue(int value) Sets a new value for this modifiable integer.Returns anIntegerobject representing thisModifiableInteger's value.toString()Returns aStringobject representing thisModifiableInteger's value.Methods inherited from class java.lang.Number
byteValue, shortValue
-
Field Details
-
value
public int valueThe int value represented by thisModifiableInteger.
-
-
Constructor Details
-
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 Details
-
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
Compares twoModifiableIntegerobjects numerically.- Specified by:
compareToin interfaceComparable<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 classNumber- See Also:
-
equals
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. -
floatValue
public float floatValue()- Specified by:
floatValuein classNumber- See Also:
-
hashCode
public int hashCode()Returns a hash code for thisModifiableInteger. -
intValue
public int intValue() -
longValue
public long longValue() -
toInteger
Returns anIntegerobject representing thisModifiableInteger's value.- Returns:
- an
Integerrepresentation of the value of this object.
-
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.
-