|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.ArrayList<E>
com.jidesoft.utils.CachedArrayList<E>
public class CachedArrayList<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 CachedVector
.
Field Summary |
---|
Fields inherited from class java.util.AbstractList |
---|
modCount |
Constructor Summary | |
---|---|
CachedArrayList()
|
|
CachedArrayList(Collection<? extends E> c)
|
|
CachedArrayList(int initialCapacity)
|
Method Summary | |
---|---|
boolean |
add(E o)
|
void |
add(int index,
E element)
|
boolean |
addAll(Collection<? extends E> c)
|
boolean |
addAll(int index,
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 |
cacheIt(Object o,
int index)
Caches the index of the element. |
void |
clear()
|
protected Map<Object,Integer> |
createCache()
|
int |
indexOf(Object elem)
|
void |
invalidateCache()
Invalidated the whole cache. |
boolean |
isLazyCaching()
|
E |
remove(int index)
|
boolean |
remove(Object o)
|
boolean |
removeAll(Collection<?> c)
|
protected void |
removeRange(int fromIndex,
int toIndex)
|
E |
set(int index,
E element)
|
void |
setLazyCaching(boolean lazyCaching)
|
void |
uncacheAll()
Uncache the whole cache. |
void |
uncacheIt(Object o)
Uncaches the index of the element. |
Methods inherited from class java.util.ArrayList |
---|
clone, contains, ensureCapacity, get, isEmpty, lastIndexOf, size, toArray, toArray, trimToSize |
Methods inherited from class java.util.AbstractList |
---|
equals, hashCode, iterator, listIterator, listIterator, subList |
Methods inherited from class java.util.AbstractCollection |
---|
containsAll, retainAll, toString |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.List |
---|
containsAll, equals, hashCode, iterator, listIterator, listIterator, retainAll, subList |
Constructor Detail |
---|
public CachedArrayList()
public CachedArrayList(Collection<? extends E> c)
public CachedArrayList(int initialCapacity)
Method Detail |
---|
public int indexOf(Object elem)
indexOf
in interface List<E>
indexOf
in class ArrayList<E>
protected void adjustCache(int index, int increase)
index
- the index. All values above this index will be changed.increase
- a positive number to increase or a negative number to decrease.protected Map<Object,Integer> createCache()
public void cacheIt(Object o, int index)
o
- the elementindex
- the index.public void uncacheIt(Object o)
o
- the elementpublic boolean add(E o)
add
in interface Collection<E>
add
in interface List<E>
add
in class ArrayList<E>
public void add(int index, E element)
add
in interface List<E>
add
in class ArrayList<E>
public E remove(int index)
remove
in interface List<E>
remove
in class ArrayList<E>
public boolean remove(Object o)
remove
in interface Collection<E>
remove
in interface List<E>
remove
in class ArrayList<E>
public boolean removeAll(Collection<?> c)
removeAll
in interface Collection<E>
removeAll
in interface List<E>
removeAll
in class AbstractCollection<E>
public void clear()
clear
in interface Collection<E>
clear
in interface List<E>
clear
in class ArrayList<E>
public boolean addAll(Collection<? extends E> c)
addAll
in interface Collection<E>
addAll
in interface List<E>
addAll
in class ArrayList<E>
public boolean addAll(int index, Collection<? extends E> c)
addAll
in interface List<E>
addAll
in class ArrayList<E>
public E set(int index, E element)
set
in interface List<E>
set
in class ArrayList<E>
public void invalidateCache()
public void uncacheAll()
invalidateCache()
.
public void cacheAll()
public boolean isLazyCaching()
public void setLazyCaching(boolean lazyCaching)
protected void removeRange(int fromIndex, int toIndex)
removeRange
in class ArrayList<E>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |