public class FixedArrayList<E>
extends java.lang.Object
implements java.util.Collection<E>, java.util.RandomAccess
A fixed array list is like an array list, but it ensures the property that
each element will always stay at the same index, even if elements are removed
in between. The counterpart of this property is that the array handles by
itself the insertion of new elements (since when an element is removed in the
middle, this position can be reused), and therefore indices cannot be chosen
(i.e. only the add(Object)
and addAll(Collection)
methods
are usable to insert new elements in the array).
This is the reason why this does not implement the List interface, because the add(int,E) method cannot be implemented.
Furthermore, this array cannot contain null values, because it marks unused positions within the array using the null value.
Constructor and Description |
---|
FixedArrayList() |
FixedArrayList(int capacity) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(E element)
Add one
element in the array. |
boolean |
addAll(java.util.Collection<? extends E> c) |
void |
clear() |
boolean |
contains(java.lang.Object o) |
boolean |
containsAll(java.util.Collection<?> c) |
boolean |
equals(java.lang.Object o) |
E |
get(int i)
I-th element.
|
int |
getLastIndex()
Last index used by the
add(Object) method. |
int |
getNextAddIndex()
The index that will be used in case of a next insertion in this array.
|
boolean |
isEmpty() |
java.util.Iterator<E> |
iterator() |
int |
realSize()
Real size of the array, counting elements that have been erased.
|
E |
remove(int i)
Remove the element at index
i . |
boolean |
remove(java.lang.Object e)
Remove the element
e . |
boolean |
removeAll(java.util.Collection<?> c) |
boolean |
retainAll(java.util.Collection<?> c) |
int |
size()
Number of elements in the array.
|
java.lang.Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
E |
unsafeGet(int i)
I-th element.
|
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public FixedArrayList()
public FixedArrayList(int capacity)
public int size()
size
in interface java.util.Collection<E>
public int realSize()
unsafeGet(int)
public boolean isEmpty()
isEmpty
in interface java.util.Collection<E>
public E get(int i)
i
- The element index.i
.public E unsafeGet(int i)
get(int)
method but it does not check the
element does not exists at the given index.i
- The element index.i
.public boolean contains(java.lang.Object o)
contains
in interface java.util.Collection<E>
public boolean containsAll(java.util.Collection<?> c)
containsAll
in interface java.util.Collection<E>
public boolean equals(java.lang.Object o)
equals
in interface java.util.Collection<E>
equals
in class java.lang.Object
public java.util.Iterator<E> iterator()
public int getLastIndex()
add(Object)
method.public int getNextAddIndex()
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection<E>
public <T> T[] toArray(T[] a)
toArray
in interface java.util.Collection<E>
public boolean add(E element) throws java.lang.NullPointerException
element
in the array. The index used for inserting the
element is then available using getLastIndex()
.add
in interface java.util.Collection<E>
element
- The element to add.java.lang.NullPointerException
- If a null value is inserted.getLastIndex()
public boolean addAll(java.util.Collection<? extends E> c) throws java.lang.UnsupportedOperationException
addAll
in interface java.util.Collection<E>
java.lang.UnsupportedOperationException
public E remove(int i)
i
.i
- Index of the element to remove.public boolean remove(java.lang.Object e)
e
.remove
in interface java.util.Collection<E>
e
- The element to remove.public boolean removeAll(java.util.Collection<?> c)
removeAll
in interface java.util.Collection<E>
public boolean retainAll(java.util.Collection<?> c)
retainAll
in interface java.util.Collection<E>
public void clear()
clear
in interface java.util.Collection<E>