Package com.jidesoft.utils
Class CachedArrayList<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.ArrayList<E>
com.jidesoft.utils.CachedArrayList<E>
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<E>,Collection<E>,List<E>,RandomAccess,SequencedCollection<E>
This is a fast access ArrayList that sacrifices memory for speed. It will reduce the speed of indexOf method from
O(n) to O(1). However it will at least double the memory used by ArrayList. So use it appropriately.
Just
like ArrayList, this implementation is not synchronized. If you want a thread safe implementation, you can
use CachedArrayList.
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionCachedArrayList(int initialCapacity) CachedArrayList(Collection<? extends E> c) -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanbooleanaddAll(int index, Collection<? extends E> c) booleanaddAll(Collection<? extends E> c) protected voidadjustCache(int index, int increase) Adjusts the cache so that all values that are greater than index will increase by the value specified by the increase parameter.voidcacheAll()Cache all the element index.voidCaches the index of the element.voidclear()protected Map<Object, CachedArrayList.IntegerWrapper> intvoidInvalidated the whole cache.booleanremove(int index) booleanbooleanremoveAll(Collection<?> c) protected voidremoveRange(int fromIndex, int toIndex) voidsetLazyCaching(boolean lazyCaching) voidUncache the whole cache.voidUncaches the index of the element.Methods inherited from class java.util.ArrayList
addFirst, addLast, clone, contains, ensureCapacity, equals, forEach, get, getFirst, getLast, hashCode, isEmpty, iterator, lastIndexOf, listIterator, listIterator, removeFirst, removeIf, removeLast, replaceAll, retainAll, size, sort, spliterator, subList, toArray, toArray, trimToSizeMethods inherited from class java.util.AbstractCollection
containsAll, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, stream, toArrayMethods inherited from interface java.util.List
containsAll, reversed
-
Constructor Details
-
CachedArrayList
public CachedArrayList() -
CachedArrayList
-
CachedArrayList
public CachedArrayList(int initialCapacity)
-
-
Method Details
-
indexOf
-
adjustCache
protected void adjustCache(int index, int increase) Adjusts the cache so that all values that are greater than index will increase by the value specified by the increase parameter.- Parameters:
index- the index. All values above this index will be changed.increase- a positive number to increase or a negative number to decrease.
-
createCache
-
cacheIt
Caches the index of the element.- Parameters:
o- the elementindex- the index.
-
uncacheIt
Uncaches the index of the element.- Parameters:
o- the element
-
add
-
add
-
remove
-
remove
-
removeAll
-
clear
public void clear() -
addAll
-
addAll
-
set
-
invalidateCache
public void invalidateCache()Invalidated the whole cache. -
uncacheAll
public void uncacheAll()Uncache the whole cache. It is the same asinvalidateCache(). -
cacheAll
public void cacheAll()Cache all the element index. -
isLazyCaching
public boolean isLazyCaching() -
setLazyCaching
public void setLazyCaching(boolean lazyCaching) -
removeRange
protected void removeRange(int fromIndex, int toIndex) - Overrides:
removeRangein classArrayList<E>
-