de.grogra.xl.util
public class ObjectList<E> extends java.util.AbstractList<E> implements java.util.RandomAccess, java.lang.Cloneable, java.io.Serializable, ObjectConsumer<E>, VoidToObjectGenerator<E>
ObjectList represents a list of Object values.
It provides list- and stack-oriented methods for insertion, addition,
and removal, of values. The methods are not thread-safe.| Modifier and Type | Field and Description |
|---|---|
java.lang.Object[] |
elements
The array holding the elements.
|
int |
size
The size of this list.
|
boolean |
useEquals
Determines whether comparisons between objects should be based
on the
equals-method or on the equality operator
==. |
| Constructor and Description |
|---|
ObjectList()
Constructs a new
ObjectList. |
ObjectList(E[] elements)
Constructs a new
ObjectList whose elements are
a copy of elements. |
ObjectList(int capacity)
Constructs a new
ObjectList with a given initial capacity. |
ObjectList(int capacity,
boolean useEquals)
Constructs a new
ObjectList with a given initial capacity. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E o)
Adds
o as last element to this list. |
void |
add(int index,
E o)
Inserts
o at position index to this list. |
boolean |
addAll(java.util.Collection<? extends E> v)
Appends all elements of
v to this list. |
ObjectList<E> |
addAll(java.lang.Object[] v,
int begin,
int length)
Appends
length components of v to this list,
starting at index begin. |
ObjectList<E> |
addAll(ObjectList<? extends E> v)
Appends all elements of
v to this list. |
void |
addIfNotContained(E o)
Adds
o as last element to this list if is not
yet contained as reported by contains(Object). |
void |
addInOrder(java.lang.Comparable<? super E> o)
Inserts
o into this ordered list. |
void |
addInOrder(E o,
java.util.Comparator<? super E> c)
Inserts
o into this ordered list, based on c. |
static void |
arraycopy(java.lang.Object[] src,
int srcIndex,
java.lang.Object[] dest,
int destIndex,
int length) |
void |
clear()
Removes all of the elements from this list.
|
static void |
clear(java.lang.Object[] array,
int index,
int length) |
java.lang.Object |
clone() |
void |
consume(E value)
Receives a value of type
T. |
boolean |
contains(java.lang.Object o)
Returns
true iff this list contains the given
element o. |
void |
ensureCapacity(int capacity)
Ensures a capacity of the internal array of at least
capacity. |
boolean |
equals(java.lang.Object o) |
void |
evaluateObject(ObjectConsumer<? super E> cons)
This generator method yields all values to
cons. |
E |
get(int index)
Returns the list element at
index. |
int |
hashCode() |
int |
indexOf(java.lang.Object o)
Returns the index of
o in this list. |
boolean |
isEmpty()
Returns if this list is empty, i.e., if its size is zero.
|
int |
lastIndexOf(java.lang.Object o)
Returns the last index of
o in this list. |
E |
peek(int index)
Returns the list element at
index as seen from
the top, i.e., at absolute position size - index. |
E |
pop()
Removes and returns the object at the top of this list.
|
ObjectList<E> |
push(E o)
Pushes
o on top of this list, i.e., as last element. |
ObjectList<E> |
push(E o1,
E o2)
Pushes
o1 and o2 on top of this list,
i.e., as last elements. |
ObjectList<E> |
push(E o1,
E o2,
E o3)
Pushes
o1 ... o3 on top of this list,
i.e., as last elements. |
E |
remove(int index)
Removes the element at position
index. |
boolean |
remove(java.lang.Object o)
Removes the element
o. |
E |
removeAt(int index)
Removes the element at position
index. |
E |
set(int index,
E o)
Sets the element at position
index to o. |
void |
setSize(int size)
Sets the size of this list to the given value.
|
int |
size()
Returns the size of this list.
|
java.lang.Object[] |
toArray()
Returns an array containing the elements of this list.
|
<T> T[] |
toArray(T[] array)
Returns an array containing the elements of this list.
|
void |
trimToSize()
Trims the capacity of this list to be its current size.
|
void |
values(ObjectConsumer<? super E> cons)
This method is an alias for
evaluateObject(de.grogra.xl.lang.ObjectConsumer super E>). |
addAll, iterator, listIterator, listIterator, removeRange, subListcontainsAll, removeAll, retainAll, toStringpublic transient java.lang.Object[] elements
size - 1 are valid. Direct operation on this
array has to be designed carefully to avoid inconsistencies.public int size
public boolean useEquals
equals-method or on the equality operator
==.public ObjectList()
ObjectList.public ObjectList(E[] elements)
ObjectList whose elements are
a copy of elements.elements - the initial elements of the listpublic ObjectList(int capacity)
ObjectList with a given initial capacity.capacity - the initial capacitypublic ObjectList(int capacity,
boolean useEquals)
ObjectList with a given initial capacity.capacity - the initial capacityuseEquals - the value for useEqualspublic boolean add(E o)
o as last element to this list.public void add(int index,
E o)
o at position index to this list.
If index is not less than size, the
list is enlarged and filled with null-values before.public boolean addAll(java.util.Collection<? extends E> v)
v to this list.public ObjectList<E> addAll(java.lang.Object[] v, int begin, int length)
length components of v to this list,
starting at index begin.v - the array of elements to addbegin - the array index to begin withlength - the number of elements to addpublic ObjectList<E> addAll(ObjectList<? extends E> v)
v to this list.v - the list of elements to addpublic void addIfNotContained(E o)
o as last element to this list if is not
yet contained as reported by contains(Object).o - the value to addpublic void addInOrder(java.lang.Comparable<? super E> o)
o into this ordered list.
This list has to be sorted in ascending order as defined by
o. o will then be added at a position
according to this order.o - the value to addpublic void addInOrder(E o, java.util.Comparator<? super E> c)
o into this ordered list, based on c.
This list has to be sorted in ascending order as defined by
c. o will then be added at a position
according to this order.o - the value to addc - the comparator which defines the orderpublic static void arraycopy(java.lang.Object[] src,
int srcIndex,
java.lang.Object[] dest,
int destIndex,
int length)
public void clear()
public static void clear(java.lang.Object[] array,
int index,
int length)
public java.lang.Object clone()
clone in class java.lang.Objectpublic void consume(E value)
ObjectConsumerT.consume in interface ObjectConsumer<E>public boolean contains(java.lang.Object o)
true iff this list contains the given
element o.public void ensureCapacity(int capacity)
capacity.capacity - the desired minimum capacitypublic boolean equals(java.lang.Object o)
public void evaluateObject(ObjectConsumer<? super E> cons)
cons.evaluateObject in interface VoidToObjectGenerator<E>cons - the consumer which receives the valuespublic E get(int index)
index. If
index is not less than size,
null is returned.public int hashCode()
public int indexOf(java.lang.Object o)
o in this list.public final boolean isEmpty()
public int lastIndexOf(java.lang.Object o)
o in this list.public E peek(int index)
index as seen from
the top, i.e., at absolute position size - index.
Thus, the topmost element has index 1.index - the position as seen from the toppublic E pop()
public final ObjectList<E> push(E o)
o on top of this list, i.e., as last element.o - the value to pushpublic final ObjectList<E> push(E o1, E o2)
o1 and o2 on top of this list,
i.e., as last elements. The effect is the same as the invocation
list.push(o1).push(o2).o1 - the first value to pusho2 - the second value to pushpublic final ObjectList<E> push(E o1, E o2, E o3)
o1 ... o3 on top of this list,
i.e., as last elements. The effect is the same as the invocation
list.push(o1).push(o2).push(o3).o1 - the first value to pusho2 - the second value to pusho3 - the third value to pushpublic E remove(int index)
index.public boolean remove(java.lang.Object o)
o. The last occurence of
o in this list is removed.public E removeAt(int index)
index.index - the position of the element to be removedpublic E set(int index, E o)
index to o.
If index is not less than size, the
list is enlarged and filled with null-values before.public void setSize(int size)
null-values.size - the new sizepublic final int size()
public java.lang.Object[] toArray()
public <T> T[] toArray(T[] array)
array. If this
list fits in the specified array,
it is returned therein. Otherwise,
a new array is allocated whose length is the size of this list's size,
the values of this list are copied into the new array, and this
array is returned.
If there is room for an additional element in the array,
a null-value is written behind the last copied element.
public void trimToSize()
public void values(ObjectConsumer<? super E> cons)
evaluateObject(de.grogra.xl.lang.ObjectConsumer super E>).