|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.neeve.lang.XIntCollectionBase
com.neeve.lang.XIntIndexedList
public class XIntIndexedList
This class represents a random access collection with real-time behavior (smooth capacity increase) for a primitivive list of ints
This class has the following advantages over the widely used
java.util.ArrayList
:
int
and Long
.shared
. Iterations over the XIntIndexedList
values are faster when
performed using the get(int)
method rather than using collection
records or iterators:[code]
for (int i = 0, n = list.size(); i < n; i++) {
list.get(i);
}[/code]
This class was based on collections code from http://javolution.org, but modified for use outside of realtime jvms.
Constructor Summary | |
---|---|
XIntIndexedList()
Creates a list of small initial capacity. |
|
XIntIndexedList(int capacity)
Creates a list of specified initial capacity; unless the list size reaches the specified capacity, operations on this list will not allocate memory (no lazy object creation). |
|
XIntIndexedList(XIntCollection values)
Creates a list containing the specified values, in the order they are returned by the collection's iterator. |
Method Summary | |
---|---|
boolean |
add(int value)
Appends the specified value to the end of this list. |
void |
add(int index,
int value)
Inserts the specified value at the specified position in this list. |
boolean |
addAll(int index,
XIntCollection values)
Inserts all of the values in the specified collection into this list at the specified position. |
void |
addLast(int value)
Appends the specified value to the end of this list (fast). |
void |
clear()
Removes all of the values from this collection (optional operation). |
boolean |
contains(int value)
Indicates if this collection contains the specified value. |
void |
delete(XCollection.Record record)
Deletes the specified record from this collection. |
int |
get(int index)
Returns the element at the specified index. |
int |
getFirst()
Returns the first value of this list. |
int |
getLast()
Returns the last value of this list. |
XCollection.Record |
head()
Returns the head record of this collection; it is the record such as head().getNext() holds the first collection value. |
int |
indexOf(int value)
Returns the index in this list of the first occurrence of the specified value, or -1 if this list does not contain this value. |
XIntIterator |
iterator()
Returns an iterator over the elements in this list |
int |
lastIndexOf(int value)
Returns the index in this list of the last occurrence of the specified value, or -1 if this list does not contain this value. |
XIntListIterator |
listIterator()
Returns a list iterator over the elements in this list |
XIntListIterator |
listIterator(int index)
Returns a list iterator from the specified position |
static XIntIndexedList |
newInstance()
Returns a new, preallocated or recycled XIntIndexedList instance |
int |
removeIndex(int index)
Removes the value at the specified position from this list. |
int |
removeLast()
Removes and returns the last value of this list (fast). |
void |
removeRange(int fromIndex,
int toIndex)
Removes the values between [fromIndex..toIndex[ |
void |
reset()
|
int |
set(int index,
int value)
Replaces the value at the specified position in this list with the specified value. |
void |
setSize(int size)
Sets the size of this list. |
int |
size()
Returns the number of values in this collection. |
void |
sort(boolean ascending)
|
XIntList |
subList(int fromIndex,
int toIndex)
Returns a view of the portion of this list between the specified If the specified indexes are equal, the returned list is empty. |
XCollection.Record |
tail()
Returns the tail record of this collection; it is the record such as tail().getPrevious() holds the last collection value. |
void |
trimToSize()
Reduces the capacity of this list to the current size (minimize storage space). |
XIntList |
unmodifiable()
Returns the unmodifiable view associated to this collection. |
int |
valueOf(XCollection.Record record)
Returns the collection value for the specified record. |
Methods inherited from class com.neeve.lang.XIntCollectionBase |
---|
addAll, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, reusableIterator, shared, toArray, toArray, toString |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.neeve.lang.XIntList |
---|
addAll, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, toArray, toArray |
Methods inherited from interface com.neeve.lang.XIntCollection |
---|
reusableIterator, shared |
Constructor Detail |
---|
public XIntIndexedList()
public XIntIndexedList(int capacity)
capacity
- the initial capacity.public XIntIndexedList(XIntCollection values)
values
- the values to be placed into this list.Method Detail |
---|
public static XIntIndexedList newInstance()
XIntIndexedList
instance
XIntIndexedList
instance.public void setSize(int size)
null
elements are added; otherwise
the last elements are removed until the desired size is reached.
size
- the new size.public final int get(int index)
get
in interface XIntList
index
- index of value to return.
IndexOutOfBoundsException
- if (index < 0) ||
(index >= size())
public final int set(int index, int value)
set
in interface XIntList
index
- index of value to replace.value
- value to be stored at the specified position.
IndexOutOfBoundsException
- if (index < 0) ||
(index >= size())
public final boolean add(int value)
add
in interface XIntCollection
add
in interface XIntList
add
in class XIntCollectionBase
value
- the value to be appended to this list.
true
(as per the general contract of the
Collection.add
method).public final int getFirst()
NoSuchElementException
- if this list is empty.public final int getLast()
NoSuchElementException
- if this list is empty.public final void addLast(int value)
value
- the value to be added.public final int removeLast()
NoSuchElementException
- if this list is empty.public final void clear()
XIntCollectionBase
clear
in interface XIntCollection
clear
in interface XIntList
clear
in class XIntCollectionBase
public void reset()
public final boolean addAll(int index, XIntCollection values)
Note: If this method is used concurrent access must be synchronized (the list is no more thread-safe).
addAll
in interface XIntList
index
- the index at which to insert first value from the specified
collection.values
- the values to be inserted into this list.
true
if this list changed as a result of the call;
false
otherwise.
IndexOutOfBoundsException
- if (index < 0) ||
(index > size())
public final void add(int index, int value)
Note: If this method is used concurrent access must be synchronized (the list is no more thread-safe).
add
in interface XIntList
index
- the index at which the specified value is to be inserted.value
- the value to be inserted.
IndexOutOfBoundsException
- if (index < 0) ||
(index > size())
public final int removeIndex(int index)
Note: If this method is used concurrent access must be synchronized (the list is no more thread-safe).
removeIndex
in interface XIntList
index
- the index of the value to removed.
IndexOutOfBoundsException
- if (index < 0) ||
(index >= size())
public final void removeRange(int fromIndex, int toIndex)
[fromIndex..toIndex[ from
this list.
Note: If this method is used concurrent access must be synchronized
(the list is no more thread-safe).
- Parameters:
fromIndex
- the beginning index, inclusive.toIndex
- the ending index, exclusive.
- Throws:
IndexOutOfBoundsException
- if (fromIndex < 0) || (toIndex < 0)
|| (fromIndex > toIndex) || (toIndex > this.size())
public final int indexOf(int value)
indexOf
in interface XIntList
value
- the value to search for.
public final int lastIndexOf(int value)
lastIndexOf
in interface XIntList
value
- the value to search for.
public XIntIterator iterator()
iterator
in interface XIntCollection
iterator
in interface XIntList
iterator
in class XIntCollectionBase
public XIntListIterator listIterator()
listIterator
in interface XIntList
public XIntListIterator listIterator(int index)
listIterator
in interface XIntList
index
- the index of first value to be returned from the
list iterator (by a call to the next
method).
IndexOutOfBoundsException
- if the index is out of range
[code](index < 0 || index > size())[/code]public final XIntList subList(int fromIndex, int toIndex)
indexOf
and
lastIndexOf
, and all of the algorithms in the
Collections
class can be applied to a subList.
The semantics of the list returned by this method become undefined if
the backing list (i.e., this list) is structurally modified in
any way other than via the returned list (structural modifications are
those that change the size of this list, or otherwise perturb it in such
a fashion that iterations in progress may yield incorrect results).
subList
in interface XIntList
fromIndex
- low endpoint (inclusive) of the subList.toIndex
- high endpoint (exclusive) of the subList.
IndexOutOfBoundsException
- if [code](fromIndex < 0 ||
toIndex > size || fromIndex > toIndex)[/code]public final void trimToSize()
public void sort(boolean ascending)
public final int size()
XIntCollectionBase
size
in interface XIntCollection
size
in interface XIntList
size
in class XIntCollectionBase
public final XCollection.Record head()
XIntCollectionBase
head().getNext()
holds the first collection value.
head
in interface XIntCollection
head
in class XIntCollectionBase
public final XCollection.Record tail()
XIntCollectionBase
tail().getPrevious()
holds the last collection value.
tail
in interface XIntCollection
tail
in class XIntCollectionBase
public final int valueOf(XCollection.Record record)
XIntCollectionBase
valueOf
in interface XIntCollection
valueOf
in class XIntCollectionBase
record
- the record whose current value is returned.
public final void delete(XCollection.Record record)
XIntCollectionBase
Implementation must ensure that removing a record from the collection does not affect in any way the records preceding the record being removed (it might affect the next records though, e.g. in a list collection, the indices of the subsequent records will change).
delete
in interface XIntCollection
delete
in class XIntCollectionBase
record
- the record to be removed.public XIntList unmodifiable()
XIntCollectionBase
UnsupportedOperationException
being thrown.
unmodifiable
in interface XIntCollection
unmodifiable
in class XIntCollectionBase
public final boolean contains(int value)
XIntCollectionBase
contains
in interface XIntCollection
contains
in interface XIntList
contains
in class XIntCollectionBase
value
- the value whose presence in this collection
is to be tested.
true
if this collection contains the specified
value;false
otherwise.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |