Javolution 6.0.0 java
javolution.util.Index Class Reference
Inheritance diagram for javolution.util.Index:
[legend]
Collaboration diagram for javolution.util.Index:
[legend]

Classes

class  Decimal
 

Public Member Functions

int compareTo (Index that)
 
int compareTo (int value)
 
Index copy ()
 
double doubleValue ()
 
boolean equals (Object obj)
 
float floatValue ()
 
int hashCode ()
 
int intValue ()
 
boolean isZero ()
 
long longValue ()
 
Index next ()
 
Index previous ()
 
String toString ()
 
Index value ()
 

Static Public Member Functions

static Index valueOf (int value)
 

Static Public Attributes

static final Configurable< Integer > UNIQUE
 
static final Index ZERO = new Index(0)
 

Protected Member Functions

final Object readResolve () throws ObjectStreamException
 

Static Package Functions

 [static initializer]
 

Private Member Functions

 Index (int value)
 

Private Attributes

final int value
 

Static Private Attributes

static final long serialVersionUID = 0x600L
 
static final Index[] INSTANCES = new Index[UNIQUE.get()]
 

Detailed Description

A non-negative number representing a position in an arrangement. For example: [code] class SparseVector<F> { FastMap<Index, F> elements = new FastMap<Index, F>(); ... }[/code]

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.

Author
Jean-Marie Dautelle
Version
5.1, July 26, 2007

Definition at line 43 of file Index.java.

Constructor & Destructor Documentation

◆ Index()

javolution.util.Index.Index ( int  value)
private

Creates an index having the specified value.

Definition at line 123 of file Index.java.

123  {
124  this.value = value;
125  }

Member Function Documentation

◆ [static initializer]()

javolution.util.Index.[static initializer]
staticpackage

◆ compareTo() [1/2]

int javolution.util.Index.compareTo ( Index  that)

Compares this index with the specified index for order. Returns a negative integer, zero, or a positive integer as this index is less than, equal to, or greater than the specified index.

Parameters
thatthe index to be compared.
Returns
a negative integer, zero, or a positive integer as this index is less than, equal to, or greater than the specified index.

Definition at line 136 of file Index.java.

136  {
137  return this.value - that.value;
138  }

References javolution.util.Index.value.

◆ compareTo() [2/2]

int javolution.util.Index.compareTo ( int  value)

Compares this index with the specified integer value for order. Returns a negative integer, zero, or a positive integer as this index is less than, equal to, or greater than the specified value.

Parameters
valuethe value to be compared.
Returns
a negative integer, zero, or a positive integer as this index is less than, equal to, or greater than the specified value.

Definition at line 149 of file Index.java.

149  {
150  return this.value - value;
151  }

◆ copy()

Index javolution.util.Index.copy ( )

Returns a copy of this index or this if the indexes is small (in permanent memory) in order to maintain unicity.

Definition at line 157 of file Index.java.

157  {
158  return value < INSTANCES.length ? this : new Index(value);
159  }

◆ doubleValue()

double javolution.util.Index.doubleValue ( )

Returns the index value as double.

Returns
the index value.

Definition at line 166 of file Index.java.

166  {
167  return (double) value;
168  }

◆ equals()

boolean javolution.util.Index.equals ( Object  obj)

Indicates if this index is equals to the one specified (for small indices this method is equivalent to ==).

Definition at line 175 of file Index.java.

175  {
176  return (this.value < INSTANCES.length) ? (this == obj)
177  : ((obj instanceof Index) ? (((Index) obj).value == value)
178  : false);
179  }

◆ floatValue()

float javolution.util.Index.floatValue ( )

Returns the index value as float.

Returns
the index value.

Definition at line 186 of file Index.java.

186  {
187  return (float) value;
188  }

◆ hashCode()

int javolution.util.Index.hashCode ( )

Returns the hash code for this index.

Definition at line 194 of file Index.java.

194  {
195  return value;
196  }

◆ intValue()

int javolution.util.Index.intValue ( )

Returns the index value as int.

Returns
the index value.

Definition at line 203 of file Index.java.

203  {
204  return value;
205  }

Referenced by javolution.util.internal.bitset.BitSetServiceImpl.add().

Here is the caller graph for this function:

◆ isZero()

boolean javolution.util.Index.isZero ( )

Indicates if this index is zero.

Returns
this == ZERO

Definition at line 212 of file Index.java.

212  {
213  return this == ZERO;
214  }

◆ longValue()

long javolution.util.Index.longValue ( )

Returns the index value as long.

Returns
the index value.

Definition at line 221 of file Index.java.

221  {
222  return value;
223  }

◆ next()

Index javolution.util.Index.next ( )

Returns the index after this one.

Definition at line 228 of file Index.java.

228  {
229  return Index.valueOf(value + 1);
230  }

References javolution.util.Index.valueOf().

Here is the call graph for this function:

◆ previous()

Index javolution.util.Index.previous ( )

Returns the index before this one.

Exceptions
IndexOutOfBoundsExceptionif (this == Index.ZERO)

Definition at line 237 of file Index.java.

237  {
238  return Index.valueOf(value - 1);
239  }

References javolution.util.Index.valueOf().

Here is the call graph for this function:

◆ readResolve()

final Object javolution.util.Index.readResolve ( ) throws ObjectStreamException
protected

Ensures index unicity during deserialization.

Definition at line 244 of file Index.java.

244  {
245  return Index.valueOf(value);
246  }

References javolution.util.Index.valueOf().

Here is the call graph for this function:

◆ toString()

String javolution.util.Index.toString ( )

Returns the String representation of this index.

Returns
TextContext.getFormat(Index.class).format(this)

Definition at line 254 of file Index.java.

254  {
255  return TextContext.getFormat(Index.class).format(this);
256  }

References javolution.text.TextContext.getFormat().

Here is the call graph for this function:

◆ value()

Index javolution.util.Index.value ( )

Returns

this

.

Implements javolution.lang.ValueType< T >.

Definition at line 259 of file Index.java.

259  {
260  return this;
261  }

◆ valueOf()

static Index javolution.util.Index.valueOf ( int  value)
static

Returns the index for the specified

int

non-negative value (returns a preallocated instance if the specified value is small).

Parameters
valuethe index value.
Returns
the corresponding index.
Exceptions
IndexOutOfBoundsExceptionif value < 0

Definition at line 111 of file Index.java.

111  {
112  return (value < INSTANCES.length) ? INSTANCES[value] : new Index(value);
113  }

Referenced by javolution.util.internal.bitset.BitSetIteratorImpl.next(), javolution.util.Index.next(), javolution.util.Index.Decimal.parse(), javolution.util.Index.previous(), javolution.util.Index.readResolve(), and javolution.xml.XMLReferenceResolver.writeReference().

Here is the caller graph for this function:

Member Data Documentation

◆ INSTANCES

final Index [] javolution.util.Index.INSTANCES = new Index[UNIQUE.get()]
staticprivate

Definition at line 94 of file Index.java.

◆ serialVersionUID

final long javolution.util.Index.serialVersionUID = 0x600L
staticprivate

Definition at line 93 of file Index.java.

◆ UNIQUE

final Configurable<Integer> javolution.util.Index.UNIQUE
static
Initial value:
= new Configurable<Integer>() {
@Override
protected Integer getDefault() {
return 1024;
}
@Override
protected Integer initialized(Integer value) {
return MathLib.min(value, 65536);
}
@Override
protected Integer reconfigured(Integer oldCount, Integer newCount) {
throw new UnsupportedOperationException(
"Unicity reconfiguration not supported.");
}
}

Holds the number of unique preallocated instances (default

1024

). This number is configurable, for example with

-Djavolution.util.Index#UNIQUE=0

there is no unique instance.

Definition at line 69 of file Index.java.

◆ value

final int javolution.util.Index.value
private

Holds the index value.

Definition at line 118 of file Index.java.

Referenced by javolution.util.Index.compareTo().

◆ ZERO

final Index javolution.util.Index.ZERO = new Index(0)
static

Holds the index zero (value 0).

Definition at line 91 of file Index.java.


The documentation for this class was generated from the following file:
javolution.util.Index.Index
Index(int value)
Definition: Index.java:123
javolution.util.Index.UNIQUE
static final Configurable< Integer > UNIQUE
Definition: Index.java:69
javolution.util.Index.INSTANCES
static final Index[] INSTANCES
Definition: Index.java:94
javolution.util.Index.ZERO
static final Index ZERO
Definition: Index.java:91
javolution.util.Index.value
final int value
Definition: Index.java:118