Package com.jidesoft.utils
Class CachedVector<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.Vector<E>
com.jidesoft.utils.CachedVector<E>
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<E>
,Collection<E>
,List<E>
,RandomAccess
,SequencedCollection<E>
This is a fast access Vector 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 Vector. So use it appropriately.
Just like
Vector, this implementation is synchronized. In comparison, CachedArrayList
is not synchronized.
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
Constructors -
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, CachedVector.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.Vector
addElement, capacity, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, forEach, get, hashCode, indexOf, insertElementAt, isEmpty, iterator, lastElement, lastIndexOf, lastIndexOf, listIterator, listIterator, removeAllElements, removeElement, removeElementAt, removeIf, replaceAll, retainAll, setElementAt, setSize, size, sort, spliterator, subList, toArray, toArray, toString, trimToSize
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
addFirst, addLast, getFirst, getLast, removeFirst, removeLast, reversed
-
Constructor Details
-
CachedVector
public CachedVector() -
CachedVector
-
CachedVector
public CachedVector(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 classVector<E>
-