@Realtime @DefaultTextFormat(value=Index.Decimal.class) public final class Index extends Number implements Comparable<Index>, ValueType<Index>
A non-negative number representing a position in an arrangement. For example:
class SparseVector<F> { FastMap<Index, F> elements = new FastMap<Index, F>(); ... }
Index performance is on-par with the primitive int
type
for small values and similar to Integer
instances for large
values. Small indexes have no adverse effect on the garbage collector
and have fast equals
method due to their unicity.
Modifier and Type | Class and Description |
---|---|
static class |
Index.Decimal
Default text format for indices (decimal value representation).
|
Modifier and Type | Field and Description |
---|---|
static Configurable<Integer> |
UNIQUE
Holds the number of unique preallocated instances (default
1024 ). |
static Index |
ZERO
Holds the index zero (value
0 ). |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Index that)
Compares this index with the specified index for order.
|
int |
compareTo(int value)
Compares this index with the specified integer value for order.
|
Index |
copy()
Returns a copy of this index or
this if the indexes
is small (in permanent memory) in order to maintain unicity. |
double |
doubleValue()
Returns the index value as
double . |
boolean |
equals(Object obj)
Indicates if this index is equals to the one specified (for small
indices this method is equivalent to
== ). |
float |
floatValue()
Returns the index value as
float . |
int |
hashCode()
Returns the hash code for this index.
|
int |
intValue()
Returns the index value as
int . |
boolean |
isZero()
Indicates if this index is zero.
|
long |
longValue()
Returns the index value as
long . |
Index |
next()
Returns the index after this one.
|
Index |
previous()
Returns the index before this one.
|
protected Object |
readResolve()
Ensures index unicity during deserialization.
|
String |
toString()
Returns the
String representation of this index. |
Index |
value()
Returns
this . |
static Index |
valueOf(int value)
Returns the index for the specified
int non-negative
value (returns a preallocated instance if the specified value is
small). |
byteValue, shortValue
public static final Configurable<Integer> UNIQUE
1024
).
This number is configurable, for example with
-Djavolution.util.Index#UNIQUE=0
there is no unique instance.public static final Index ZERO
0
).public static Index valueOf(int value)
int
non-negative
value (returns a preallocated instance if the specified value is
small).value
- the index value.IndexOutOfBoundsException
- if value < 0
public int compareTo(Index that)
compareTo
in interface Comparable<Index>
that
- the index to be compared.public int compareTo(int value)
value
- the value to be compared.public Index copy()
this
if the indexes
is small (in permanent memory) in order to maintain unicity.public double doubleValue()
double
.doubleValue
in class Number
public boolean equals(Object obj)
==
).public float floatValue()
float
.floatValue
in class Number
public int hashCode()
public int intValue()
int
.public boolean isZero()
this == ZERO
public long longValue()
long
.public Index next()
public Index previous()
IndexOutOfBoundsException
- if (this == Index.ZERO)protected final Object readResolve() throws ObjectStreamException
ObjectStreamException
Copyright © 2005-2013 Javolution. All Rights Reserved.