Class ShrinkableArrayList<E>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
org.nasengolem.util.datastructures.ShrinkableArrayList<E>
Type Parameters:
E - the type of the elements in this list
All Implemented Interfaces:
Iterable<E>, Collection<E>, List<E>, RandomAccess, SequencedCollection<E>

public class ShrinkableArrayList<E> extends AbstractList<E> implements List<E>, RandomAccess
Random-Access List implementation, that has a custom capacity and allows custom resizing. Implements all optional list operations and permits all elements, including null. The main feature of this list is, that it can be resized to a smaller size. After resizing, the Array behaves as if it was of the new size and all elements after the new size are removed. Additionally, the list is capped, meaning that it can never store more elements than its fixed capacity.

The resize, add, addLast, size, isEmpty, get, set, getFirst, getLast, removeLast, iterator, listIterator, and reversed operations run in constant time. All the operations run in linear time (roughly speaking).

Each CappedResizableList instance has a fixed capacity. The capacity is the maximum number of elements the list can store. However, the list does not need to store that many elements. The actual amount of elements stored in the list is called the size of the list. The size of the list is always less than or equal to the capacity. Unlike the capacity, the size of the list isn't fixed. It changes when elements are added or removed from the list or when the list is resized.

Like the ArrayList, the CappedResizableList is not synchronized and its iterator is fail-fast. Read the documentation of the ArrayList for more information about these topics.

Author:
Paul Steinbach
See Also: