public class ModifiableInteger extends Number implements 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
.
Modifier and Type | Field and Description |
---|---|
int |
value
The int value represented by this
ModifiableInteger . |
Constructor and Description |
---|
ModifiableInteger()
Deprecated.
not really deprecated, just marked so to avoid mistaken use.
|
ModifiableInteger(int value)
Constructs a newly allocated
ModifiableInteger object that represents the
specified int value. |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(ModifiableInteger anotherInteger)
Compares two
ModifiableInteger objects numerically. |
void |
decrement()
Subtracts one from the value of this modifiable integer.
|
double |
doubleValue() |
boolean |
equals(Object o)
Compares this object to the specified object.
|
float |
floatValue() |
int |
getValue()
Returns the value of this object, similarly to
intValue() . |
int |
hashCode()
Returns a hash code for this
ModifiableInteger . |
void |
increment()
Adds one to the value of this modifiable integer.
|
int |
intValue() |
long |
longValue() |
void |
setValue(int value)
Sets a new value for this modifiable integer.
|
Integer |
toInteger()
Returns an
Integer object representing this
ModifiableInteger 's value. |
String |
toString()
Returns a
String object representing this
ModifiableInteger 's value. |
byteValue, shortValue
@Deprecated public ModifiableInteger()
ModifiableInteger(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.
public ModifiableInteger(int value)
ModifiableInteger
object that represents the
specified int
value.value
- the value to be represented by the
ModifiableInteger
object.public void setValue(int value)
value
- the new value to set.public int getValue()
intValue()
. This getter is NOT
redundant. It is used for serialization by java.beans.XMLEncoder.public void increment()
public void decrement()
public int compareTo(ModifiableInteger anotherInteger)
ModifiableInteger
objects numerically.compareTo
in interface Comparable<ModifiableInteger>
anotherInteger
- the ModifiableInteger
to be compared.0
if this ModifiableInteger
is equal to the
argument ModifiableInteger
; a value less than 0
if this
ModifiableInteger
is numerically less than the argument
ModifiableInteger
; and a value greater than 0
if this
ModifiableInteger
is numerically greater than the argument
ModifiableInteger
(signed comparison).public double doubleValue()
doubleValue
in class Number
Number.doubleValue()
public boolean equals(Object o)
true
if and only if the argument is not null
and is an
ModifiableInteger
object that contains the same
int
value as this object.public float floatValue()
floatValue
in class Number
Number.floatValue()
public int hashCode()
ModifiableInteger
.public int intValue()
intValue
in class Number
Number.intValue()
public long longValue()
longValue
in class Number
Number.longValue()
public Integer toInteger()
Integer
object representing this
ModifiableInteger
's value.Integer
representation of the value of this object.public String toString()
String
object representing this
ModifiableInteger
'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 the
Integer.toString(int)
method.Copyright © 2018. All rights reserved.