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, elementDataFields inherited from class java.util.AbstractList
modCount -
Constructor Summary
Constructors -
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, CachedVector.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.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, trimToSizeMethods 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
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:
removeRangein classVector<E>
-