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 TypeMethodDescriptionvoid
boolean
boolean
addAll
(int index, Collection<? extends E> c) boolean
addAll
(Collection<? extends E> c) 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.void
cacheAll()
Cache all the element index.void
Caches the index of the element.void
clear()
protected Map
<Object, CachedArrayList.IntegerWrapper> int
void
Invalidated the whole cache.boolean
remove
(int index) boolean
boolean
removeAll
(Collection<?> c) protected void
removeRange
(int fromIndex, int toIndex) void
setLazyCaching
(boolean lazyCaching) void
Uncache the whole cache.void
Uncaches 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, trimToSize
Methods inherited from class java.util.AbstractCollection
containsAll, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, stream, toArray
Methods 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:
removeRange
in classArrayList<E>
-