Overview | Package | Class | Tree | Deprecated | Index | Help

PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.jgrapht.util
Class ModifiableInteger

    java.lang.Object
      java.lang.Number
          org.jgrapht.util.ModifiableInteger

All Implemented Interfaces:
  java.io.Serializable, java.lang.Comparable

    public class ModifiableInteger

extends java.lang.Number
implements java.lang.Comparable

The `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`.

Since:
  May 27, 2004
Author:
  Barak Naveh
See Also:
  Serialized Form

Field Summary
`int` | `value` The int value represented by this `ModifiableInteger`.

Constructor Summary
`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.

Method Summary
`int` | `compareTo(ModifiableInteger anotherInteger)` Compares two `ModifiableInteger` objects numerically.
`int` | `compareTo(java.lang.Object o)` Compares this `ModifiableInteger` object to another object.
`void` | `decrement()` Subtracts one from the value of this modifiable integer.
`double` | `doubleValue()`
`boolean` | `equals(java.lang.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.
`java.lang.Integer` | `toInteger()` Returns an `Integer` object representing this `ModifiableInteger`'s value.
`java.lang.String` | `toString()` Returns a `String` object representing this `ModifiableInteger`'s value.

Methods inherited from class java.lang.Number
`byteValue, shortValue`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Field Detail

### value

    public int value

  The int value represented by this `ModifiableInteger`.

Constructor Detail

### ModifiableInteger

    @Deprecated
    public ModifiableInteger()

  Deprecated. not really deprecated, just marked so to avoid mistaken use.

  !!! DON'T USE - Use the `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.

### ModifiableInteger

    public ModifiableInteger(int value)

  Constructs a newly allocated `ModifiableInteger` object that represents the specified `int` value.

  Parameters:
    `value` - the value to be represented by the `ModifiableInteger` object.

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 to `intValue()`. 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 two `ModifiableInteger` objects numerically.

  Parameters:
    `anotherInteger` - the `ModifiableInteger` to be compared.
  Returns:
    the value `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).

### compareTo

    public int compareTo(java.lang.Object o)

  Compares this `ModifiableInteger` object to another object. If the object is an `ModifiableInteger`, this function behaves like `compareTo(Integer)`. Otherwise, it throws a `ClassCastException` (as `ModifiableInteger` objects are only comparable to other `ModifiableInteger` objects).

  Specified by:
    `compareTo` in interface `java.lang.Comparable`
  Parameters:
    `o` - the `Object` to be compared.
  Returns:
    the value `0` if the argument is a `ModifiableInteger` numerically equal to this `ModifiableInteger`; a value less than `0` if the argument is a `ModifiableInteger` numerically greater than this `ModifiableInteger`; and a value greater than `0` if the argument is a `ModifiableInteger` numerically less than this `ModifiableInteger`.
  See Also:
    `Comparable.compareTo(java.lang.Object)`

### doubleValue

    public double doubleValue()

  Specified by:
    `doubleValue` in class `java.lang.Number`
  See Also:
    `Number.doubleValue()`

### equals

    public boolean equals(java.lang.Object o)

  Compares this object to the specified object. The result is `true` if and only if the argument is not `null` and is an `ModifiableInteger` object that contains the same `int` value as this object.

  Overrides:
    `equals` in class `java.lang.Object`
  Parameters:
    `o` - the object to compare with.
  Returns:
    `true` if the objects are the same; `false` otherwise.

### floatValue

    public float floatValue()

  Specified by:
    `floatValue` in class `java.lang.Number`
  See Also:
    `Number.floatValue()`

### hashCode

    public int hashCode()

  Returns a hash code for this `ModifiableInteger`.

  Overrides:
    `hashCode` in class `java.lang.Object`
  Returns:
    a hash code value for this object, equal to the primitive `int` value represented by this `ModifiableInteger` object.

### intValue

    public int intValue()

  Specified by:
    `intValue` in class `java.lang.Number`
  See Also:
    `Number.intValue()`

### longValue

    public long longValue()

  Specified by:
    `longValue` in class `java.lang.Number`
  See Also:
    `Number.longValue()`

### toInteger

    public java.lang.Integer toInteger()

  Returns an `Integer` object representing this `ModifiableInteger`'s value.

  Returns:
    an `Integer` representation of the value of this object.

### toString

    public java.lang.String toString()

  Returns a `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.

  Overrides:
    `toString` in class `java.lang.Object`
  Returns:
    a string representation of the value of this object in base 10.

Overview | Package | Class | Tree | Deprecated | Index | Help

PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD