Class PopularityList<E>
- java.lang.Object
-
- ca.odell.glazedlists.AbstractEventList<E>
-
- ca.odell.glazedlists.TransformedList<E,E>
-
- ca.odell.glazedlists.PopularityList<E>
-
- All Implemented Interfaces:
ListEventListener<E>
,EventList<E>
,java.lang.Iterable<E>
,java.util.Collection<E>
,java.util.EventListener
,java.util.List<E>
public final class PopularityList<E> extends TransformedList<E,E>
AnEventList
that shows the unique elements from its sourceEventList
ordered by the frequency of their appearance.This
EventList
supports all write operations.Warning: This class breaks the contract required by
List
. SeeEventList
for an example.Warning: This class is thread ready but not thread safe. See
EventList
for an example of thread safe code.EventList Overview Writable: yes Concurrency: thread ready, not thread safe Performance: reads: O(log N), writes O(log N) Memory: 196 bytes per element Unit Tests: N/A Issues: 104 - Author:
- Jesse Wilson
-
-
Field Summary
-
Fields inherited from class ca.odell.glazedlists.TransformedList
source
-
Fields inherited from class ca.odell.glazedlists.AbstractEventList
publisher, readWriteLock, updates
-
-
Constructor Summary
Constructors Constructor Description PopularityList(EventList<E> source)
Creates a newPopularityList
that provides frequency-ranking for the specifiedEventList
.PopularityList(EventList<E> source, java.util.Comparator<E> uniqueComparator)
Creates a newPopularityList
that provides frequency-ranking for the specifiedEventList
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <E extends java.lang.Comparable<? super E>>
PopularityList<E>create(EventList<E> source)
Creates a newPopularityList
that provides frequency-ranking for the specifiedEventList
.void
dispose()
Releases the resources consumed by thisTransformedList
so that it may eventually be garbage collected.protected boolean
isWritable()
Gets whether the sourceEventList
is writable via this API.void
listChanged(ListEvent<E> listChanges)
When the underlying list changes, this notification allows the object to repaint itself or update itself as necessary.-
Methods inherited from class ca.odell.glazedlists.TransformedList
add, addAll, clear, get, getSourceIndex, remove, removeAll, retainAll, set, size
-
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
-
-
-
-
Constructor Detail
-
PopularityList
public PopularityList(EventList<E> source)
Creates a newPopularityList
that provides frequency-ranking for the specifiedEventList
. All elements of the sourceEventList
must implementComparable
.Usage of factory method
create(EventList)
is preferable.
-
PopularityList
public PopularityList(EventList<E> source, java.util.Comparator<E> uniqueComparator)
Creates a newPopularityList
that provides frequency-ranking for the specifiedEventList
.- Parameters:
uniqueComparator
-Comparator
used to determine equality
-
-
Method Detail
-
create
public static <E extends java.lang.Comparable<? super E>> PopularityList<E> create(EventList<E> source)
Creates a newPopularityList
that provides frequency-ranking for the specifiedEventList
. All elements of the sourceEventList
must implementComparable
.
-
isWritable
protected boolean isWritable()
Gets whether the sourceEventList
is writable via this API.Extending classes must override this method in order to make themselves writable.
- Specified by:
isWritable
in classTransformedList<E,E>
-
listChanged
public void listChanged(ListEvent<E> listChanges)
When the underlying list changes, this notification allows the object to repaint itself or update itself as necessary.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.
- Specified by:
listChanged
in interfaceListEventListener<E>
- Specified by:
listChanged
in classTransformedList<E,E>
- Parameters:
listChanges
- aListEvent
describing the changes to the list
-
dispose
public void dispose()
Releases the resources consumed by thisTransformedList
so that it may eventually be garbage collected.A
TransformedList
will be garbage collected without a call toTransformedList.dispose()
, but not before its sourceEventList
is garbage collected. By callingTransformedList.dispose()
, you allow theTransformedList
to be garbage collected before its sourceEventList
. This is necessary for situations where aTransformedList
is short-lived but its sourceEventList
is long-lived.Warning: It is an error to call any method on a
TransformedList
after it has been disposed.
-
-