public class CollectionList<S,E> extends TransformedList<S,E> implements ListEventListener<S>
The actual mapping from the parent list to the child list (album to songs in the above example)
is done by a CollectionList.Model
that is provided to the constructor.
Note that any EventList
s returned by the CollectionList.Model
must use the same
ListEventPublisher
and ReadWriteLock
as this CollectionList
. This is
necessary in order for CollectionList to operate correctly under mult-threaded conditions. An
IllegalArgumentException
will be raised if this invariant is violated.
Warning: This class is thread ready but not thread
safe. See EventList
for an example of thread safe code.
EventList Overview | |
Writable: | only set(int,Object) and remove(int) |
Concurrency: | thread ready, not thread safe |
Performance: | reads: O(log N), writes O(log N) |
Memory: | 96 bytes per element |
Unit Tests: | N/A |
Issues: | 96 162 257 265 |
CollectionList.Model
Modifier and Type | Class and Description |
---|---|
static interface |
CollectionList.Model<E,S>
Provides the logic to map a parent object (e.g.
|
source
publisher, readWriteLock, updates
Constructor and Description |
---|
CollectionList(EventList<S> source,
CollectionList.Model<S,E> model)
Create a
CollectionList with its contents being the children of the elements in the
specified source EventList . |
Modifier and Type | Method and Description |
---|---|
int |
childEndingIndex(int parentIndex)
Return the index of the last child in the CollectionList for the given parent index.
|
int |
childStartingIndex(int parentIndex)
Return the index of the first child in the CollectionList for the given parent index.
|
void |
dispose()
Releases the resources consumed by this
TransformedList so that it may eventually be
garbage collected. |
E |
get(int index)
Returns the element at the specified position in this list.
|
protected boolean |
isWritable()
Gets whether the source
EventList is writable via this API. |
void |
listChanged(ListEvent<S> listChanges)
Handle changes in the parent list.
|
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).
|
int |
size()
Returns the number of elements in this list.
|
add, addAll, clear, getSourceIndex, removeAll, retainAll
add, addAll, addListEventListener, contains, containsAll, equals, getPublisher, getReadWriteLock, hashCode, indexOf, 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 CollectionList(EventList<S> source, CollectionList.Model<S,E> model)
CollectionList
with its contents being the children of the elements in the
specified source EventList
.source
- an EventList of Objects from each of which the model
can extract
child elementsmodel
- the logic for extracting children from each source
elementprotected boolean isWritable()
TransformedList
EventList
is writable via this API.
Extending classes must override this method in order to make themselves writable.
isWritable
in class TransformedList<S,E>
false
because we cannot support TransformedList.add(int, Object)
; though we do
support set(int, Object)
and remove(int)
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<S,E>
public E get(int index)
public E set(int index, E value)
public E remove(int index)
public int childStartingIndex(int parentIndex)
childEndingIndex(int)
public int childEndingIndex(int parentIndex)
childStartingIndex(int)
public void listChanged(ListEvent<S> listChanges)
listChanged
in interface ListEventListener<S>
listChanged
in class TransformedList<S,E>
listChanges
- a ListEvent
describing the changes to the listpublic void dispose()
TransformedList
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.