|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectca.odell.glazedlists.AbstractEventList<E>
ca.odell.glazedlists.TransformedList
ca.odell.glazedlists.io.CachingList
public class CachingList
An EventList
that caches elements from its source EventList
.
It is useful in cases when the get(int)
method of an
EventList
is expensive. It can also be used when there are too many
elements to keep in memory simultaneously. For caching to be effective, object
access must be clustered.
This EventList
caches the most recently requested n elements.
By overriding the preFetch(int)
method, you can modify this
CachingList to do predictive lookups for higher performance.
EventList Overview | |
Writable: | yes |
Concurrency: | thread ready, not thread safe |
Performance: | reads: O(log N), writes O(log N) |
Memory: | O(N) |
Unit Tests: | N/A |
Issues: | 22 32 43 262 |
Field Summary |
---|
Fields inherited from class ca.odell.glazedlists.TransformedList |
---|
source |
Fields inherited from class ca.odell.glazedlists.AbstractEventList |
---|
publisher, readWriteLock, updates |
Constructor Summary | |
---|---|
CachingList(EventList source,
int maxSize)
Creates a CachingList that caches elements from the specified source
EventList . |
Method Summary | |
---|---|
protected Object |
fetch(int index,
boolean recordHitsOrMisses)
Fetches a particular element. |
Object |
get(int index)
Returns the element at the specified position in this list. |
float |
getCacheHitRatio()
Gets the ratio of cache hits to cache misses. |
int |
getCacheHits()
Gets the total number of times that this list has fetched its result from the cache rather than from the source list. |
int |
getCacheMisses()
Gets the total number of times that this list has fetched its result from the source list rather than the cache. |
protected boolean |
isWritable()
Gets whether the source EventList is writable via this API. |
void |
listChanged(ListEvent listChanges)
When the underlying list changes, this notification allows the object to repaint itself or update itself as necessary. |
protected void |
preFetch(int index)
Pre-fetches a set of data given the index that was directly requested. |
int |
size()
Returns the number of elements in this list. |
Methods inherited from class ca.odell.glazedlists.TransformedList |
---|
add, addAll, clear, dispose, getSourceIndex, remove, removeAll, retainAll, set |
Methods inherited from class ca.odell.glazedlists.AbstractEventList |
---|
add, addAll, addListEventListener, contains, containsAll, equals, getPublisher, getReadWriteLock, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeListEventListener, subList, toArray, toArray, toString |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public CachingList(EventList source, int maxSize)
CachingList
that caches elements from the specified source
EventList
.
source
- The source list to use to get values frommaxSize
- The maximum size of the cacheMethod Detail |
---|
public final int size()
size
in interface Collection
size
in interface List
size
in class TransformedList
public final Object get(int index)
get
in interface List
get
in class TransformedList
index
- index of element to return.
protected final Object fetch(int index, boolean recordHitsOrMisses)
This might seem redundant with the existence of get(int)
.
However, the goals of the methods are different. This method exists
to be called by get(int)
or preFetch(int)
.
This distinction allows users overriding this class a means of entry
retrieval which does not implicitly execute a pre-fetch. This is
particularly key for users overriding preFetch(int)
index
- The index of the value to retrieverecordHitsOrMisses
- Whether to increment the hit/miss counters
(this should always be false
when called from
preFetch(int)
).
protected void preFetch(int index)
Each application that wishes to take advantage of pre-fetching should implement this method in a way which best fits their particular use cases. As such, no default pre-fetch behaviour could really be defined, and thus this method is empty by default.
Because pre-fetching can modify the cache, child classes of CachingList should use careful consideration of locking when implementing this method.
index
- The index that was requested from the cacheprotected boolean isWritable()
EventList
is writable via this API.
Extending classes must override this method in order to make themselves writable.
isWritable
in class TransformedList
public final int getCacheHits()
public final int getCacheMisses()
public final float getCacheHitRatio()
public final void listChanged(ListEvent listChanges)
It is mandatory that the calling thread has obtained the write lock on the source list. This is because the calling thread will have written to the source list to cause this event. This condition guarantees that no writes can occur while the listener is handling this event. It is an error to write to the source list while processing an event.
listChanged
in interface ListEventListener
listChanged
in class TransformedList
listChanges
- a ListEvent
describing the changes to the list
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |