de.grogra.xl.util
public class IntList extends java.lang.Object implements java.lang.Cloneable, java.io.Serializable, IntConsumer, VoidToIntGenerator
IntList represents a list of int 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 |
|---|---|
int[] |
elements
The array holding the elements.
|
int |
size
The size of this list.
|
| Constructor and Description |
|---|
IntList()
Constructs a new
IntList. |
IntList(int capacity)
Constructs a new
IntList with a given initial capacity. |
IntList(int[] elements)
Constructs a new
IntList whose elements are
a copy of elements. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(int o)
Adds
o as last element to this list. |
void |
add(int index,
int o)
Inserts
o at position index to this list. |
IntList |
addAll(int[] v,
int begin,
int length)
Appends
length components of v to this list,
starting at index begin. |
IntList |
addAll(IntList v)
Appends all elements of
v to this list. |
void |
addIfNotContained(int o)
Adds
o as last element to this list if is not
yet contained as reported by contains(int). |
static void |
arraycopy(int[] src,
int srcIndex,
int[] dest,
int destIndex,
int length) |
int |
binarySearch(int value)
Searches this list for the specified value using
the binary search algorithm.
|
static int |
binarySearch(int[] array,
int value) |
static int |
binarySearch(int[] array,
int value,
int fromIndex,
int toIndex) |
void |
clear()
Removes all of the elements from this list.
|
static void |
clear(int[] array,
int index,
int length) |
java.lang.Object |
clone() |
void |
consume(int value)
Receives a value of type
int. |
boolean |
contains(int 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 |
evaluateInt(IntConsumer cons)
This generator method yields all values to
cons. |
int |
get(int index)
Returns the list element at
index. |
int |
hashCode() |
int |
indexOf(int 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(int o)
Returns the last index of
o in this list. |
int |
peek(int index)
Returns the list element at
index as seen from
the top, i.e., at absolute position size - index. |
int |
pop()
Removes and returns the object at the top of this list.
|
IntList |
push(int o)
Pushes
o on top of this list, i.e., as last element. |
IntList |
push(int o1,
int o2)
Pushes
o1 and o2 on top of this list,
i.e., as last elements. |
IntList |
push(int o1,
int o2,
int o3)
Pushes
o1 ... o3 on top of this list,
i.e., as last elements. |
boolean |
remove(int o)
Removes the element
o. |
int |
removeAt(int index)
Removes the element at position
index. |
int |
set(int index,
int 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.
|
int[] |
toArray()
Returns an array containing the elements of this list.
|
int[] |
toArray(int[] array)
Returns an array containing the elements of this list.
|
java.lang.String |
toString() |
void |
trimToSize()
Trims the capacity of this list to be its current size.
|
void |
values(IntConsumer cons)
This method is an alias for
evaluateInt(de.grogra.xl.lang.IntConsumer). |
void |
writeTo(java.nio.IntBuffer out) |
public transient int[] elements
size - 1 are valid. Direct operation on this
array has to be designed carefully to avoid inconsistencies.public int size
public IntList()
IntList.public IntList(int capacity)
IntList with a given initial capacity.capacity - the initial capacitypublic IntList(int[] elements)
IntList whose elements are
a copy of elements.elements - the initial elements of the listpublic boolean add(int o)
o as last element to this list.o - the value to addtruepublic void add(int index,
int o)
o at position index to this list.
If index is not less than size, the
list is enlarged and filled with 0-values before.index - the insert positiono - the value to insertpublic IntList addAll(int[] 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 IntList addAll(IntList v)
v to this list.v - the list of elements to addpublic void addIfNotContained(int o)
o as last element to this list if is not
yet contained as reported by contains(int).o - the value to addpublic static void arraycopy(int[] src,
int srcIndex,
int[] dest,
int destIndex,
int length)
public int binarySearch(int value)
value - the value to be searched for(-(insertion point) - 1). The
insertion point is defined as the point at which the
value would be inserted into the list: the index of the first
element greater than the value, or size(), if all
elements in the list are less than the specified value.public static int binarySearch(int[] array,
int value)
public static int binarySearch(int[] array,
int value,
int fromIndex,
int toIndex)
public void clear()
public static void clear(int[] array,
int index,
int length)
public java.lang.Object clone()
clone in class java.lang.Objectpublic void consume(int value)
IntConsumerint.consume in interface IntConsumerpublic boolean contains(int o)
true iff this list contains the given
element o.o - a valuetrue iff o is containedpublic void ensureCapacity(int capacity)
capacity.capacity - the desired minimum capacitypublic boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic void evaluateInt(IntConsumer cons)
cons.evaluateInt in interface VoidToIntGeneratorcons - the consumer which receives the valuespublic int get(int index)
index. If
index is not less than size,
0 is returned.index - the positionindexpublic int hashCode()
hashCode in class java.lang.Objectpublic int indexOf(int o)
o in this list.o - a valueo, or -1 of o is not containedpublic final boolean isEmpty()
true iff this list is emptypublic int lastIndexOf(int o)
o in this list.o - a valueo, or -1 of o is not containedpublic int 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 int pop()
public final IntList push(int o)
o on top of this list, i.e., as last element.o - the value to pushpublic final IntList push(int o1, int 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 IntList push(int o1, int o2, int 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 boolean remove(int o)
o. The last occurence of
o in this list is removed.o - the element to be removedtrue iff o was found and removed from the listpublic int removeAt(int index)
index.index - the position of the element to be removedpublic int set(int index,
int o)
index to o.
If index is not less than size, the
list is enlarged and filled with 0-values before.index - the positiono - the new valueindexpublic void setSize(int size)
0-values.size - the new sizepublic final int size()
public int[] toArray()
public int[] toArray(int[] 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 0-value is written behind the last copied element.
array - an array to usepublic java.lang.String toString()
toString in class java.lang.Objectpublic void trimToSize()
public void values(IntConsumer cons)
evaluateInt(de.grogra.xl.lang.IntConsumer).public void writeTo(java.nio.IntBuffer out)