public final class UniqueList<E> extends TransformedList<E,E>
EventList
that shows the unique elements from its source EventList
. For
example, the source list {A, A, B, C, C, C, D} would be simplified to {A, B, C, D} by this
UniqueList.
Warning: This class breaks the contract required by
List
. See EventList
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: | |
Memory: | N/A |
Unit Tests: | N/A |
Issues: | 27 34 35 45 46 55 58 114 |
source
publisher, readWriteLock, updates
Constructor and Description |
---|
UniqueList(EventList<E> source)
Creates a
UniqueList that determines uniqueness via the Comparable interface. |
UniqueList(EventList<E> source,
Comparator<? super E> comparator)
Creates a
UniqueList that determines uniqueness using the specified Comparator . |
Modifier and Type | Method and Description |
---|---|
static <E extends Comparable<? super E>> |
create(EventList<E> source)
Creates a
UniqueList that determines uniqueness via the Comparable interface. |
void |
dispose()
Releases the resources consumed by this
TransformedList so that it may eventually be
garbage collected. |
List<E> |
getAll(E value)
Returns a List of all original elements represented by the given
value within this
UniqueList . |
List<E> |
getAll(int index)
Returns a List of all original elements represented by the value at the given
index within this UniqueList . |
int |
getCount(E value)
Returns the number of duplicates of the specified value.
|
int |
getCount(int index)
Returns the number of duplicates of the value found at the specified index.
|
protected int |
getSourceIndex(int index)
Gets the index in the source
EventList that corresponds to the specified index. |
int |
indexOf(Object element)
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. |
void |
listChanged(ListEvent<E> listChanges)
When the underlying list changes, this notification allows the object to repaint itself or
update itself as necessary.
|
E |
remove(int index)
Removes the element at the specified position in this list (optional operation).
|
E |
set(int index,
E value)
Replaces the element at the specified position in this list with the specified element
(optional operation).
|
void |
setComparator(Comparator<? super E> comparator)
Change the
Comparator which determines the unique elements of this List. |
int |
size()
Returns the number of elements in this list.
|
add, addAll, clear, get, removeAll, retainAll
add, addAll, addListEventListener, contains, containsAll, equals, getPublisher, getReadWriteLock, hashCode, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeListEventListener, subList, toArray, toArray, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
replaceAll, sort, spliterator
parallelStream, removeIf, stream
public UniqueList(EventList<E> source)
UniqueList
that determines uniqueness via the Comparable
interface.
All elements of the source EventList
must implement Comparable
.
Usage of factory method create(EventList)
is preferable.
source
- the EventList
containing duplicates to removepublic UniqueList(EventList<E> source, Comparator<? super E> comparator)
UniqueList
that determines uniqueness using the specified Comparator
.source
- the EventList
containing duplicates to removecomparator
- the Comparator
used to determine equalitypublic static <E extends Comparable<? super E>> UniqueList<E> create(EventList<E> source)
UniqueList
that determines uniqueness via the Comparable
interface.
All elements of the source EventList
must implement Comparable
.source
- the EventList
containing duplicates to removepublic void setComparator(Comparator<? super E> comparator)
Comparator
which determines the unique elements of this List.comparator
- the Comparator
used to determine groupings; null
will be
treated as GlazedLists.comparableComparator()
public int size()
Integer.MAX_VALUE
elements, returns Integer.MAX_VALUE
.size
in interface Collection<E>
size
in interface List<E>
size
in class TransformedList<E,E>
protected 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 TransformedList<E,E>
public E remove(int index)
public E set(int index, E value)
public int indexOf(Object element)
element
,
or -1 if this list does not contain this element
. More formally, returns the
lowest index i
such that uniqueListComparator.compare(get(i), element) == 0
,
or -1 if there is no such index.
Note: This is a departure from the contract for List.indexOf(java.lang.Object)
since it does not
guarantee that element.equals(get(i))
where i is a positive index returned from this
method.
indexOf
in interface List<E>
indexOf
in class AbstractEventList<E>
element
- the element to search for.ClassCastException
- if the type of the specified element is incompatible with this listprotected boolean isWritable()
EventList
is writable via this API.
Extending classes must override this method in order to make themselves writable.
isWritable
in class TransformedList<E,E>
public void listChanged(ListEvent<E> 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<E>
listChanged
in class TransformedList<E,E>
listChanges
- a ListEvent
describing the changes to the listpublic int getCount(int index)
public int getCount(E value)
public List<E> getAll(int index)
index
within this UniqueList
.public List<E> getAll(E value)
value
within this
UniqueList
.public void dispose()
TransformedList
so that it may eventually be
garbage collected.
A TransformedList
will be garbage collected without a call to dispose()
, but
not before its source EventList
is garbage collected. By calling #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.
Copyright © 2024 levigo holding gmbh. All rights reserved.