public final class Index extends Number implements Comparable, 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:[code]
class SparseVector
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 |
INITIAL_FIRST
Holds the initial first index value (default
-1 ). |
static Configurable |
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(Object that) |
double |
doubleValue()
Returns the index value as
int . |
boolean |
equals(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 List |
rangeOf(int start,
int end)
Returns all the indices greater or equal to
start
but less than end . |
protected 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.
|
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). |
byteValue, shortValue
public static final Index ZERO
0
).public static final Configurable INITIAL_FIRST
-1
).public static final Configurable INITIAL_LAST
31
).public static void setMinimumRange(int first, int last)
first
- the first index value.last
- the last index value.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 List rangeOf(int start, int end)
start
but less than end
.start
- the start index.end
- the end index.[start .. end[
public int intValue()
int
.public long longValue()
long
.public float floatValue()
float
.floatValue
in class Number
public double doubleValue()
int
.doubleValue
in class Number
public String toString()
String
representation of this index.public final boolean equals(Object obj)
==
).public final int hashCode()
protected final Object readResolve() throws ObjectStreamException
ObjectStreamException
public final int compareTo(Object that)
compareTo
in interface Comparable
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–2015 Javolution. All rights reserved.