E
- the type of element this list shall containpublic class PackedObjectArrayList<E> extends java.util.AbstractList<E> implements java.util.List<E>
PackedIntegerArrayList
.
All equal objects in the list are represented by the an integer number stored in the underlying list and
the methods reading and writing objects perform a conversion between these numbers and the concrete object
instances.
The compression method of this class works best of the list contains a limited set of different objects multiple times. If different equal object instances are add to this list only the object that was add first will be returned for all positions occupied by an equal object (which should not be a problem with equal objects.)
Due to the compression method the maximum number of expected different objects has to be specified when creating instances of this class. Each a new type of object is add to the list an specific integer value will be assigned to it. Note that such values will always remain associated with this object even if all objects of this kind (objects that are equal to each other) are removed from the list. So each additional object that differs from all previously added objects will contribute to the number of supported different objects that can be stored, no matter if any of these objects is removed again later on.
Constructor and Description |
---|
PackedObjectArrayList(int objectTypeCount,
int initialCapacity)
Creates a new instance of this class.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E e) |
void |
add(int index,
E element) |
E |
get(int index) |
int |
getMaxObjectTypeCount()
Returns the number of different objects this list can manage.
|
E |
remove(int index) |
protected void |
removeRange(int fromIndex,
int toIndex) |
E |
set(int index,
E element) |
int |
size() |
addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, subList
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
public PackedObjectArrayList(int objectTypeCount, int initialCapacity)
objectTypeCount
- the number of different objects that will be contained in the returned list at mostinitialCapacity
- the number of entries the list will be able to store before the underlying array will be resizedprotected void removeRange(int fromIndex, int toIndex)
removeRange
in class java.util.AbstractList<E>
public int size()
public int getMaxObjectTypeCount()
Example: A number of 12 different objects is passed to the constructor. 4 bits will be necessary to store 12 different values (0..11) 16 different values (0..15) would be possible in 4 bits. Therefore this method would return 16 instead of 12 in this case and the list could also manage 16 different objects.