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:
java.io.Serializable,java.lang.Cloneable,java.lang.Iterable<E>,java.util.Collection<E>,java.util.List<E>,java.util.RandomAccess
public class CachedVector<E> extends java.util.Vector<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,
CachedArrayListis not synchronized.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCachedVector.IntegerWrapper
-
Constructor Summary
Constructors Constructor Description CachedVector()CachedVector(int initialCapacity)CachedVector(java.util.Collection<? extends E> c)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, E element)booleanadd(E element)booleanaddAll(int index, java.util.Collection<? extends E> c)booleanaddAll(java.util.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.voidcacheIt(java.lang.Object o, int index)Caches the index of the element.voidclear()protected java.util.Map<java.lang.Object,CachedVector.IntegerWrapper>createCache()intindexOf(java.lang.Object elem)voidinvalidateCache()Invalidated the whole cache.booleanisLazyCaching()Eremove(int index)booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection<?> c)protected voidremoveRange(int fromIndex, int toIndex)Eset(int index, E element)voidsetLazyCaching(boolean lazyCaching)voiduncacheAll()Uncache the whole cache.voiduncacheIt(java.lang.Object o)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
-
-
-
-
Constructor Detail
-
CachedVector
public CachedVector()
-
CachedVector
public CachedVector(java.util.Collection<? extends E> c)
-
CachedVector
public CachedVector(int initialCapacity)
-
-
Method Detail
-
indexOf
public int indexOf(java.lang.Object elem)
-
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
protected java.util.Map<java.lang.Object,CachedVector.IntegerWrapper> createCache()
-
cacheIt
public void cacheIt(java.lang.Object o, int index)Caches the index of the element.- Parameters:
o- the elementindex- the index.
-
uncacheIt
public void uncacheIt(java.lang.Object o)
Uncaches the index of the element.- Parameters:
o- the element
-
add
public boolean add(E element)
-
add
public void add(int index, E element)
-
remove
public E remove(int index)
-
remove
public boolean remove(java.lang.Object o)
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
-
clear
public void clear()
-
addAll
public boolean addAll(java.util.Collection<? extends E> c)
-
addAll
public boolean addAll(int index, java.util.Collection<? extends E> c)
-
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 classjava.util.Vector<E>
-
-