JIDE 3.5.15

com.jidesoft.utils
Class CachedArrayList<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<E>
              extended by com.jidesoft.utils.CachedArrayList<E>
All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, List<E>, RandomAccess

public class CachedArrayList<E>
extends ArrayList<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.

See Also:
Serialized Form

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)
          Deprecated. no longer being invoked since 3.4.0
 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()
           
protected  void markDirtyIfNecessary(int index)
          Marks the entire cache dirty if necessary depends on where the index is.
 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

CachedArrayList

public CachedArrayList()

CachedArrayList

public CachedArrayList(Collection<? extends E> c)

CachedArrayList

public CachedArrayList(int initialCapacity)
Method Detail

indexOf

public int indexOf(Object elem)
Specified by:
indexOf in interface List<E>
Overrides:
indexOf in class ArrayList<E>

adjustCache

@Deprecated
protected void adjustCache(int index,
                                      int increase)
Deprecated. no longer being invoked since 3.4.0

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 Map<Object,Integer> createCache()

cacheIt

public void cacheIt(Object o,
                    int index)
Caches the index of the element.

Parameters:
o - the element
index - the index.

markDirtyIfNecessary

protected void markDirtyIfNecessary(int index)
Marks the entire cache dirty if necessary depends on where the index is.

By default, the cache is marked dirty when the index is smaller than half of the size.

Parameters:
index - the index that is changing.
Since:
3.4.0

uncacheIt

public void uncacheIt(Object o)
Uncaches the index of the element.

Parameters:
o - the element

add

public boolean add(E o)
Specified by:
add in interface Collection<E>
Specified by:
add in interface List<E>
Overrides:
add in class ArrayList<E>

add

public void add(int index,
                E element)
Specified by:
add in interface List<E>
Overrides:
add in class ArrayList<E>

remove

public E remove(int index)
Specified by:
remove in interface List<E>
Overrides:
remove in class ArrayList<E>

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection<E>
Specified by:
remove in interface List<E>
Overrides:
remove in class ArrayList<E>

removeAll

public boolean removeAll(Collection<?> c)
Specified by:
removeAll in interface Collection<E>
Specified by:
removeAll in interface List<E>
Overrides:
removeAll in class AbstractCollection<E>

clear

public void clear()
Specified by:
clear in interface Collection<E>
Specified by:
clear in interface List<E>
Overrides:
clear in class ArrayList<E>

addAll

public boolean addAll(Collection<? extends E> c)
Specified by:
addAll in interface Collection<E>
Specified by:
addAll in interface List<E>
Overrides:
addAll in class ArrayList<E>

addAll

public boolean addAll(int index,
                      Collection<? extends E> c)
Specified by:
addAll in interface List<E>
Overrides:
addAll in class ArrayList<E>

set

public E set(int index,
             E element)
Specified by:
set in interface List<E>
Overrides:
set in class ArrayList<E>

invalidateCache

public void invalidateCache()
Invalidated the whole cache.


uncacheAll

public void uncacheAll()
Uncache the whole cache. It is the same as invalidateCache().


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 class ArrayList<E>

JIDE 3.5.15