ca.odell.glazedlists

Class UniqueList<E>

Implemented Interfaces:
EventListener, EventList<E>, List, ListEventListener<E>

public final class UniqueList<E>
extends TransformedList<S,E>

An 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.

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
Authors:
Kevin Maltby
James Lemieux
Jesse Wilson

Field Summary

Fields inherited from class ca.odell.glazedlists.TransformedList<S,E>

source

Fields inherited from class ca.odell.glazedlists.AbstractEventList<E>

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

void
dispose()
List
getAll(E value)
Returns a List of all original elements represented by the given value within this UniqueList.
List
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)
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()
void
listChanged(ListEvent listChanges)
E
remove(int index)
E
set(int index, E value)
int
size()

Methods inherited from class ca.odell.glazedlists.TransformedList<S,E>

add, addAll, clear, dispose, get, getSourceIndex, isWritable, listChanged, remove, removeAll, retainAll, set, size

Methods inherited from class ca.odell.glazedlists.AbstractEventList<E>

T[] toArray, add, add, addAll, addAll, addListEventListener, clear, contains, containsAll, equals, get, getPublisher, getReadWriteLock, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeListEventListener, retainAll, set, size, subList, toArray, toString

Constructor Details

UniqueList

public UniqueList(EventList source)
Creates a UniqueList that determines uniqueness via the Comparable interface. All elements of the source EventList must implement Comparable.
Parameters:
source - the EventList containing duplicates to remove

UniqueList

public UniqueList(EventList source,
                  Comparator comparator)
Creates a UniqueList that determines uniqueness using the specified Comparator.
Parameters:
source - the EventList containing duplicates to remove
comparator - the Comparator used to determine equality

Method Details

dispose

public void dispose()
Overrides:
dispose in interface TransformedList<S,E>

getAll

public List getAll(E value)

getAll

public List getAll(int index)

getCount

public int getCount(E value)
Returns the number of duplicates of the specified value.

getCount

public int getCount(int index)
Returns the number of duplicates of the value found at the specified index.

getSourceIndex

protected int getSourceIndex(int index)
Overrides:
getSourceIndex in interface TransformedList<S,E>

indexOf

public 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. 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 since it does not guarantee that element.equals(get(i)) where i is a positive index returned from this method.

Overrides:
indexOf in interface AbstractEventList<E>
Parameters:
element - the element to search for.
Returns:
the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element

isWritable

protected boolean isWritable()
Overrides:
isWritable in interface TransformedList<S,E>

listChanged

public void listChanged(ListEvent listChanges)
Specified by:
listChanged in interface ListEventListener<E>

remove

public E remove(int index)
Overrides:
remove in interface TransformedList<S,E>

set

public E set(int index,
             E value)
Overrides:
set in interface TransformedList<S,E>

size

public int size()
Overrides:
size in interface TransformedList<S,E>

Glazed Lists, Copyright © 2003-2006 publicobject.com, O'Dell Engineering.
Documentation build by pbuilder at 2007-12-21 23:49