public class XBooleanLinkedList extends XBooleanCollectionBase implements XBooleanList
This class represents a linked list with real-time behavior; smooth capacity increase and no memory allocation as long as the list size does not exceed its initial capacity.
All of the operations perform as could be expected for a doubly-linked
list (insertion/deletion
at the end of the list are nonetheless the fastest).
Operations that index into the list will traverse the list from
the begining or the end whichever is closer to the specified index.
Random access operations can be significantly accelerated by
splitting the list into smaller ones.
XBooleanLinkedList (as for any XCollection sub-class) supports
fast iterations without using iterators.[code]
XLinkedList
Alternatively The list can be iterated over using XBooleanCollectionBase.reusableIterator(). Utilization of
these iterators does not introduce garbage because they are created once. However,
these iterators may not be used concurrently by multiple threads as they are
single instance by nature.
Custom list implementations may override the newNode() method
in order to return their own XBooleanLinkedList.BooleanNode implementation (with
additional fields for example).
This class was based on collections code from http://javolution.org, but modified for use outside of realtime jvms.
| Modifier and Type | Class and Description |
|---|---|
static class |
XBooleanLinkedList.BooleanNode
This class represents a
XBooleanLinkedList node; it allows for direct
iteration over the list values. |
| Constructor and Description |
|---|
XBooleanLinkedList()
Creates a list of small initial capacity.
|
XBooleanLinkedList(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).
|
XBooleanLinkedList(XBooleanCollection values)
Creates a list containing the specified values, in the order they
are returned by the collection's iterator.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(boolean value)
Appends the specified value to the end of this list
(equivalent to
addLast(boolean)). |
void |
add(int index,
boolean value)
Inserts the specified value at the specified position in this list.
|
boolean |
addAll(int index,
XBooleanCollection values)
Inserts all of the values in the specified collection into this
list at the specified position.
|
void |
addBefore(XBooleanLinkedList.BooleanNode next,
boolean value)
Inserts the specified value before the specified Node.
|
void |
addFirst(boolean value)
Inserts the specified value at the beginning of this list.
|
void |
addLast(boolean 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(boolean value)
Indicates if this collection contains the specified value.
|
void |
delete(XCollection.Record record)
Deletes the specified record from this collection.
|
boolean |
get(int index)
Returns the value at the specified position in this list.
|
boolean |
getFirst()
Returns the first value of this list.
|
boolean |
getLast()
Returns the last value of this list.
|
XBooleanLinkedList.BooleanNode |
head()
Returns the head record of this collection; it is the record such as
head().getNext() holds the first collection value. |
int |
indexOf(boolean 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.
|
XBooleanIterator |
iterator()
Returns a simple iterator over the elements in this list
|
int |
lastIndexOf(boolean 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.
|
XBooleanListIterator |
listIterator()
Returns a list iterator over the elements in this list.
|
XBooleanListIterator |
listIterator(int index)
Returns a list iterator from the specified position
The specified index indicates the first value that would be returned by
an initial call to the
next method. |
static XBooleanLinkedList |
newInstance()
Returns a new list instance.
|
boolean |
remove(int index)
Removes the value at the specified position in this list.
|
boolean |
removeFirst()
Removes and returns the first value of this list.
|
boolean |
removeLast()
Removes and returns the last value of this list (fast).
|
void |
reset() |
boolean |
set(int index,
boolean value)
Replaces the value at the specified position in this list with the
specified value.
|
int |
size()
Returns the number of values in this collection.
|
XBooleanList |
subList(int fromIndex,
int toIndex)
Returns a view of the portion of this list between the specified
indexes
If the specified indexes are equal, the returned list is empty.
|
XBooleanLinkedList.BooleanNode |
tail()
Returns the tail record of this collection; it is the record such as
tail().getPrevious() holds the last collection value. |
XBooleanList |
unmodifiable()
Returns the unmodifiable view associated to this collection.
|
boolean |
valueOf(XCollection.Record record)
Returns the collection value for the specified record.
|
addAll, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, reusableIterator, shared, supportsIteratorModifications, toArray, toArray, toStringaddAll, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, toArray, toArrayreusableIterator, shared, supportsIteratorModificationspublic XBooleanLinkedList()
public XBooleanLinkedList(int capacity)
capacity - the initial capacity.public XBooleanLinkedList(XBooleanCollection values)
values - the values to be placed into this list.public static XBooleanLinkedList newInstance()
public final boolean add(boolean value)
addLast(boolean)).add in interface XBooleanCollectionadd in interface XBooleanListadd in class XBooleanCollectionBasevalue - the value to be appended to this list.true (as per the general contract of the
Collection.add method).public final boolean get(int index)
get in interface XBooleanListindex - the index of value to return.IndexOutOfBoundsException - if (index < 0) ||
(index >= size())public final boolean set(int index,
boolean value)
set in interface XBooleanListindex - the index of value to replace.value - the value to be stored at the specified position.IndexOutOfBoundsException - if (index < 0) ||
(index >= size())public final void add(int index,
boolean value)
add in interface XBooleanListindex - 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 boolean addAll(int index,
XBooleanCollection values)
addAll in interface XBooleanListindex - 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 boolean remove(int index)
remove in interface XBooleanListindex - the index of the value to removed.IndexOutOfBoundsException - if (index < 0) ||
(index >= size())public final int indexOf(boolean value)
indexOf in interface XBooleanListvalue - the value to search for.public final int lastIndexOf(boolean value)
lastIndexOf in interface XBooleanListvalue - the value to search for.public XBooleanIterator iterator()
iterator in interface XBooleanCollectioniterator in interface XBooleanListiterator in class XBooleanCollectionBasepublic XBooleanListIterator listIterator()
listIterator in interface XBooleanListpublic XBooleanListIterator listIterator(int index)
next method. An initial call to
the previous method would return the value with the
specified index minus one.listIterator in interface XBooleanListindex - 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 XBooleanList subList(int fromIndex, int toIndex)
list.subList(from, to).clear();
Similar idioms may be constructed for 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 XBooleanListfromIndex - 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 boolean getFirst()
NoSuchElementException - if this list is empty.public final boolean getLast()
NoSuchElementException - if this list is empty.public final void addFirst(boolean value)
value - the value to be inserted.public void addLast(boolean value)
value - the value to be inserted.public final boolean removeFirst()
NoSuchElementException - if this list is empty.public final boolean removeLast()
NoSuchElementException - if this list is empty.public final void addBefore(XBooleanLinkedList.BooleanNode next, boolean value)
next - the Node before which this value is inserted.value - the value to be inserted.public final XBooleanLinkedList.BooleanNode head()
XBooleanCollectionBasehead().getNext() holds the first collection value.head in interface XBooleanCollectionhead in class XBooleanCollectionBasepublic final XBooleanLinkedList.BooleanNode tail()
XBooleanCollectionBasetail().getPrevious() holds the last collection value.tail in interface XBooleanCollectiontail in class XBooleanCollectionBasepublic final boolean valueOf(XCollection.Record record)
XBooleanCollectionBasevalueOf in interface XBooleanCollectionvalueOf in class XBooleanCollectionBaserecord - the record whose current value is returned.public final void delete(XCollection.Record record)
XBooleanCollectionBaseImplementation 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 XBooleanCollectiondelete in class XBooleanCollectionBaserecord - the record to be removed.public final boolean contains(boolean value)
XBooleanCollectionBasecontains in interface XBooleanCollectioncontains in interface XBooleanListcontains in class XBooleanCollectionBasevalue - the value whose presence in this collection
is to be tested.true if this collection contains the specified
value;false otherwise.public final int size()
XBooleanCollectionBasesize in interface XBooleanCollectionsize in interface XBooleanListsize in class XBooleanCollectionBasepublic final void clear()
XBooleanCollectionBaseclear in interface XBooleanCollectionclear in interface XBooleanListclear in class XBooleanCollectionBasepublic XBooleanList unmodifiable()
XBooleanCollectionBaseUnsupportedOperationException being thrown.unmodifiable in interface XBooleanCollectionunmodifiable in class XBooleanCollectionBasepublic void reset()
Copyright © 2019 Neeve Research, LLC. All Rights Reserved.