public class FixedArrayList<E> extends Object implements Collection<E>, 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(Collection<? extends E> c) |
void |
clear() |
boolean |
contains(Object o) |
boolean |
containsAll(Collection<?> c) |
boolean |
equals(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() |
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(Object e)
Remove the element
e. |
boolean |
removeAll(Collection<?> c) |
boolean |
retainAll(Collection<?> c) |
int |
size()
Number of elements in the array.
|
Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
E |
unsafeGet(int i)
I-th element.
|
getClass, hashCode, notify, notifyAll, toString, wait, wait, waithashCodepublic FixedArrayList()
public FixedArrayList(int capacity)
public int size()
size in interface Collection<E>public int realSize()
unsafeGet(int)public boolean isEmpty()
isEmpty in interface 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(Object o)
contains in interface Collection<E>public boolean containsAll(Collection<?> c)
containsAll in interface Collection<E>public boolean equals(Object o)
equals in interface Collection<E>equals in class Objectpublic int getLastIndex()
add(Object) method.public int getNextAddIndex()
public Object[] toArray()
toArray in interface Collection<E>public <T> T[] toArray(T[] a)
toArray in interface Collection<E>public boolean add(E element) throws NullPointerException
element in the array. The index used for inserting
the element is then available using getLastIndex().add in interface Collection<E>element - The element to add.NullPointerException - If a null value is inserted.getLastIndex()public boolean addAll(Collection<? extends E> c) throws UnsupportedOperationException
addAll in interface Collection<E>UnsupportedOperationExceptionpublic E remove(int i)
i.i - Index of the element to remove.public boolean remove(Object e)
e.remove in interface Collection<E>e - The element to remove.public boolean removeAll(Collection<?> c)
removeAll in interface Collection<E>public boolean retainAll(Collection<?> c)
retainAll in interface Collection<E>public void clear()
clear in interface Collection<E>Copyright © 2015. All rights reserved.