public final class Index extends java.lang.Number implements java.lang.Comparable<Index>, FastCollection.Record, Realtime, 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)
.
Modifier and Type | Field and Description |
---|---|
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
31 ). |
static Index |
ZERO
Holds the index zero (value
0 ). |
Modifier and Type | Method and Description |
---|---|
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 . |
static java.util.List<Index> |
rangeOf(int start,
int end)
Returns all the indices greater or equal to
start
but less than end . |
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. |
Text |
toText()
Returns the textual representation of this real-time object
(equivalent to
toString except that the returned value
can be "stack" allocated and
supports fast concatenation). |
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). |
static java.util.List<Index> |
valuesOf(int... indices)
Returns the list of all the indices specified.
|
public static final Index ZERO
0
).public static final Configurable<java.lang.Integer> INITIAL_FIRST
-1
).public static final Configurable<java.lang.Integer> INITIAL_LAST
31
).public static void setMinimumRange(int first, int last)
first
- the first index value.last
- the last index value.java.lang.IllegalArgumentException
- if first > last
public static Index valueOf(int i)
int
value
(creating it as well as the indices toward zero
if they do not exist).i
- the index value.public static java.util.List<Index> rangeOf(int start, int end)
start
but less than end
.start
- the start index.end
- the end index.[start .. end[
public static java.util.List<Index> valuesOf(int... indices)
indices
- the indices values.{indices[0], indices[1], ...}
public int intValue()
int
.intValue
in class java.lang.Number
public long longValue()
long
.longValue
in class java.lang.Number
public float floatValue()
float
.floatValue
in class java.lang.Number
public double doubleValue()
int
.doubleValue
in class java.lang.Number
public java.lang.String toString()
String
representation of this index.toString
in class java.lang.Object
TextFormat.getInstance(Cursor.class).formatToString(_value)
public final boolean equals(java.lang.Object obj)
==
).equals
in class java.lang.Object
this == obj
public final int hashCode()
hashCode
in class java.lang.Object
protected final java.lang.Object readResolve() throws java.io.ObjectStreamException
java.io.ObjectStreamException
public final int compareTo(Index that)
compareTo
in interface java.lang.Comparable<Index>
public final FastCollection.Record getNext()
FastCollection.Record
getNext
in interface FastCollection.Record
public final FastCollection.Record getPrevious()
FastCollection.Record
getPrevious
in interface FastCollection.Record
Copyright © 2005 - 2007 Javolution.