Overview | Package | Class | Tree | Deprecated | Index | Help
| J avolution v5.2 (J2SE 1.5+)
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javolution.util
Class Index

    java.lang.Object
      java.lang.Number
          javolution.util.Index

All Implemented Interfaces:
  java.io.Serializable, java.lang.Comparable<Index>, Immutable, FastCollection.Record, XMLSerializable

    public final class Index

extends java.lang.Number
implements java.lang.Comparable<Index>, FastCollection.Record, Immutable, XMLSerializable

This class represents a unique index which can be used instead of `java.lang.Integer` for primitive data types collections. For example:``

             class SparseVector<F> {
                 FastMap<Index, F> _elements = new FastMap<Index, F>();
                 ...
             }

Unicity is guaranteed and direct equality (`==`) can be used in place of object equality (`Index.equals(Object)`).

Indices have no adverse effect on the garbage collector (persistent instances), but should not be used for large integer values as that would increase the permanent memory footprint significantly.

RTSJ: Instance of this classes are allocated in `ImmortalMemory`. Indices can be pre-allocated at start-up to avoid run-time allocation delays by configuring `INITIAL_FIRST` and/or `INITIAL_LAST` or through `setMinimumRange(int, int)`.

Version:
  5.1, July 26, 2007
Author:
  Jean-Marie Dautelle
See Also:
  Serialized Form

Field Summary
`static Configurable<java.lang.Integer>` | `INITIAL_FIRST` Holds the initial first index value (default `-1`).
`static Configurable<java.lang.Integer>` | `INITIAL_LAST` Holds the initial last index value (default `16`).
`static Index` | `ZERO` Holds the index zero (value `0`).

Method Summary
`int` | `compareTo(Index that)`
`double` | `doubleValue()` Returns the index value as `int`.
`boolean` | `equals(java.lang.Object obj)` Indicates if this index is equals to the one specified (unicity ensures that this method is equivalent to `==`).
`float` | `floatValue()` Returns the index value as `float`.
`FastCollection.Record` | `getNext()` Returns the record after this one.
`FastCollection.Record` | `getPrevious()` Returns the record before this one.
`int` | `hashCode()` Returns the hash code for this index.
`int` | `intValue()` Returns the index value as `int`.
`long` | `longValue()` Returns the index value as `long`.
`protected java.lang.Object` | `readResolve()` Ensures index unicity during deserialization.
`static void` | `setMinimumRange(int first, int last)` Creates the indices for the specified range of values if they don't exist.
`java.lang.String` | `toString()` Returns the `String` representation of this index.
`static Index` | `valueOf(int i)` Returns the unique index for the specified `int` value (creating it as well as the indices toward `zero` if they do not exist).

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

### INITIAL_FIRST

    public static final Configurable<java.lang.Integer> INITIAL_FIRST

  Holds the initial first index value (default `-1`).

### INITIAL_LAST

    public static final Configurable<java.lang.Integer> INITIAL_LAST

  Holds the initial last index value (default `16`).

### ZERO

    public static final Index ZERO

  Holds the index zero (value `0`).

Method Detail

### setMinimumRange

    public static void setMinimumRange(int first,
                                       int last)

  Creates the indices for the specified range of values if they don't exist.

  Parameters:
    `first` - the first index value.
    `last` - the last index value.
  Throws:
    `java.lang.IllegalArgumentException` - if `first > last`

### valueOf

    public static Index valueOf(int i)

  Returns the unique index for the specified `int` value (creating it as well as the indices toward `zero` if they do not exist).

  Parameters:
    `i` - the index value.
  Returns:
    the corresponding unique index.

### intValue

    public final int intValue()

  Returns the index value as `int`.

  Specified by:
    `intValue` in class `java.lang.Number`
  Returns:
    the index value.

### longValue

    public final long longValue()

  Returns the index value as `long`.

  Specified by:
    `longValue` in class `java.lang.Number`
  Returns:
    the index value.

### floatValue

    public final float floatValue()

  Returns the index value as `float`.

  Specified by:
    `floatValue` in class `java.lang.Number`
  Returns:
    the index value.

### doubleValue

    public final double doubleValue()

  Returns the index value as `int`.

  Specified by:
    `doubleValue` in class `java.lang.Number`
  Returns:
    the index value.

### toString

    public final java.lang.String toString()

  Returns the `String` representation of this index.

  Overrides:
    `toString` in class `java.lang.Object`
  Returns:
    this index value formatted as a string.

### equals

    public final boolean equals(java.lang.Object obj)

  Indicates if this index is equals to the one specified (unicity ensures that this method is equivalent to `==`).

  Overrides:
    `equals` in class `java.lang.Object`
  Returns:
    `this == obj`

### hashCode

    public final int hashCode()

  Returns the hash code for this index.

  Overrides:
    `hashCode` in class `java.lang.Object`
  Returns:
    the index value.

### readResolve

    protected final java.lang.Object readResolve()
                                          throws java.io.ObjectStreamException

  Ensures index unicity during deserialization.

  Returns:
    the unique instance for this deserialized index.
  Throws:
    `java.io.ObjectStreamException`

### compareTo

    public int compareTo(Index that)

  Specified by:
    `compareTo` in interface `java.lang.Comparable<Index>`

### getNext

    public final FastCollection.Record getNext()

  Description copied from interface: `FastCollection.Record`
  Returns the record after this one.

  Specified by:
    `getNext` in interface `FastCollection.Record`
  Returns:
    the next record.

### getPrevious

    public final FastCollection.Record getPrevious()

  Description copied from interface: `FastCollection.Record`
  Returns the record before this one.

  Specified by:
    `getPrevious` in interface `FastCollection.Record`
  Returns:
    the previous record.

Overview | Package | Class | Tree | Deprecated | Index | Help
| J avolution v5.2 (J2SE 1.5+)
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2005 - 2007 Javolution.