|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectca.odell.glazedlists.AbstractEventList
ca.odell.glazedlists.TransformedList
ca.odell.glazedlists.UniqueList
public final class UniqueList
An EventList that shows the unique elements from its source
EventList.
This EventList supports all write operations.
Warning: This class
breaks the contract required by List. See EventList
for an example.
| EventList Overview | |
| Writable: | yes |
| Concurrency: | thread ready, not thread safe |
| Performance: | reads: O(log N), writes O(log N) |
| Memory: | 72 bytes per element, plus 52 bytes per element ocurring 2 or more times |
| Unit Tests: | N/A |
| Issues: | N/A |
| Field Summary |
|---|
| Fields inherited from class ca.odell.glazedlists.TransformedList |
|---|
source |
| Fields inherited from class ca.odell.glazedlists.AbstractEventList |
|---|
publisher, readWriteLock, updates |
| Constructor Summary | |
|---|---|
UniqueList(EventList source)
Creates a UniqueList that determines uniqueness via the
Comparable interface. |
|
UniqueList(EventList source,
Comparator comparator)
Creates a UniqueList that determines uniqueness using the specified
Comparator. |
|
| Method Summary | |
|---|---|
boolean |
contains(Object object)
Returns true if this list contains the specified element. |
void |
dispose()
Releases the resources consumed by this TransformedList so that it
may eventually be garbage collected. |
List |
getAll(int index)
Gets a List of the duplicates of the value at the specified index. |
List |
getAll(Object value)
Gets a List of the duplicates of the specified value. |
int |
getCount(int index)
Gets the number of duplicates of the value found at the specified index. |
int |
getCount(Object value)
Gets the number of duplicates of the specified value. |
protected int |
getSourceIndex(int index)
Gets the index in the source EventList that corresponds to the
specified index. |
int |
indexOf(Object object)
Returns the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element. |
protected boolean |
isWritable()
Gets whether the source EventList is writable via this API. |
int |
lastIndexOf(Object object)
Returns the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element. |
void |
listChanged(ListEvent listChanges)
When the underlying list changes, this notification allows the object to repaint itself or update itself as necessary. The receiving class must iterate through all of the changes in
the list change event or else the change objects will remain
in memory indefinitely. The easiest way to iterate through the
changes is in a while loop like this:
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. |
Object |
remove(int index)
Removes the element at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list. |
boolean |
remove(Object toRemove)
Removes the first occurrence in this list of the specified element (optional operation). If this list does not contain the element, it is unchanged. More formally, removes the element with the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))) (if such an element exists). |
void |
replaceAll(SortedSet revision)
Replaces the contents of this UniqueList with the contents of the
specified SortedSet. |
Object |
set(int index,
Object value)
Replaces the element at the specified position in this list with the specified element (optional operation). |
int |
size()
Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE. |
| Methods inherited from class ca.odell.glazedlists.TransformedList |
|---|
add, add, addAll, addAll, clear, get, removeAll, retainAll |
| Methods inherited from class ca.odell.glazedlists.AbstractEventList |
|---|
addListEventListener, containsAll, equals, getPublisher, getReadWriteLock, hashCode, isEmpty, iterator, listIterator, listIterator, removeListEventListener, subList, toArray, toArray, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public UniqueList(EventList source,
Comparator comparator)
UniqueList that determines uniqueness using the specified
Comparator.
source - The EventList containing duplicates to remove.comparator - The Comparator used to determine equality.public UniqueList(EventList source)
UniqueList that determines uniqueness via the
Comparable interface. All elements of the source EventList
must impelement Comparable.
| Method Detail |
|---|
public int size()
size in interface Collectionsize in interface Listsize in class TransformedListprotected int getSourceIndex(int index)
EventList that corresponds to the
specified index. More formally, returns the index such that
this.get(i) == source.get(getSourceIndex(i)) for all
legal values of i.
getSourceIndex in class TransformedListprotected boolean isWritable()
EventList is writable via this API.
Extending classes must override this method in order to make themselves writable.
isWritable in class TransformedListpublic void listChanged(ListEvent listChanges)
The receiving class must iterate through all of the changes in
the list change event or else the change objects will remain
in memory indefinitely. The easiest way to iterate through the
changes is in a while loop like this:
while(listChanges.next()) {
// get the current change info
int unsortedIndex = listChanges.getIndex();
int changeType = listChanges.getType();
// handle change with the specified index and type
}
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 ListEventListenerlistChanged in class TransformedListpublic int getCount(int index)
public int getCount(Object value)
public List getAll(int index)
List of the duplicates of the value at the specified index.
Warning: the returned List is only valid until
the next list change occurs. If this UniqueList is shared between
multiple threads, it is necessary to have aquired the ReadWriteLock
while accessing the returned List.
public List getAll(Object value)
List of the duplicates of the specified value.
Warning: the returned List is only valid until
the next list change occurs. If this UniqueList is shared between
multiple threads, it is necessary to have aquired the ReadWriteLock
while accessing the returned List.
public Object remove(int index)
remove in interface Listremove in class TransformedListindex - the index of the element to removed.
public boolean remove(Object toRemove)
remove in interface Collectionremove in interface Listremove in class TransformedListtoRemove - element to be removed from this list, if present.
public Object set(int index,
Object value)
set in interface Listset in class TransformedListindex - index of element to replace.value - element to be stored at the specified position.
public void replaceAll(SortedSet revision)
UniqueList with the contents of the
specified SortedSet. If this UniqueList uses a Comparator
to determine equality of elements, the specified SortedList must use
an equal Comparator.
Warning: This method is
thread ready but not thread safe. See EventList for an example
of thread safe code.
public boolean contains(Object object)
contains in interface Collectioncontains in interface Listcontains in class AbstractEventListobject - element whose presence in this list is to be tested.
public int indexOf(Object object)
indexOf in interface ListindexOf in class AbstractEventListobject - element to search for.
public int lastIndexOf(Object object)
lastIndexOf in interface ListlastIndexOf in class AbstractEventListobject - element to search for.
public void dispose()
TransformedList so that it
may eventually be garbage collected.
A TransformedList will be garbage collected without a call to
TransformedList.dispose(), but not before its source EventList is garbage
collected. By calling TransformedList.dispose(), you allow the TransformedList
to be garbage collected before its source EventList. This is
necessary for situations where a TransformedList is short-lived but
its source EventList is long-lived.
Warning: It is an error
to call any method on a TransformedList after it has been disposed.
dispose in class TransformedList
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||