public final class FunctionList<S,E> extends TransformedList<S,E> implements RandomAccess
FunctionList.Function
that must be supplied at the time of
construction but can be changed afterward using setForwardFunction(org.jadice.util.glazedlists.FunctionList.Function<S, E>)
. This
FunctionList.Function
is called the forward function because it creates elements in this
FunctionList
from elements that have been added or mutated within the source list. The
forward function may be an implementation of either FunctionList.Function
or FunctionList.AdvancedFunction
.
An optional reverse FunctionList.Function
which is capable of mapping the elements of this
FunctionList back to the corresponding source element may be supplied in order to use the
following mutating methods:
FunctionList.Function
is not supplied then callers of those methods will receive an
IllegalStateException
explaining that those operations are not available without the
reverse FunctionList.Function
.
If specified, the reverse FunctionList.Function
should do its best to maintain the invariant:
o.equals(reverseFunction.evaluate(forwardFunction.evaluate(o))) for any o that is non-null.
Note: if two source elements share the same identity (i.e. source.get(i) ==
source.get(j) when i != j), it is up to author of the FunctionList.Function
to decide
if and how to preserve the relationship of their identities after
their transformation.
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(1), writes O(1) amortized |
Memory: | |
Unit Tests: | FunctionList |
Issues: | 282 |
Modifier and Type | Class and Description |
---|---|
static interface |
FunctionList.AdvancedFunction<A,B>
An AdvancedFunction is an extension of the simple Function interface which provides more hooks
in the lifecycle of the transformation of a source element.
|
static interface |
FunctionList.Function<A,B>
A Function encapsulates the logic for transforming a list element into any kind of Object.
|
source
publisher, readWriteLock, updates
Constructor and Description |
---|
FunctionList(EventList<S> source,
FunctionList.Function<S,E> forward)
Construct a
FunctionList which stores the result of transforming each source element
using the given forward FunctionList.Function . |
FunctionList(EventList<S> source,
FunctionList.Function<S,E> forward,
FunctionList.Function<E,S> reverse)
Construct a
FunctionList which stores the result of transforming each source element
using the given forward FunctionList.Function . |
Modifier and Type | Method and Description |
---|---|
void |
add(int index,
E value)
Inserts the specified element at the specified position in this list (optional operation).
|
E |
get(int index)
Returns the element at the specified position in this list.
|
FunctionList.Function<S,E> |
getForwardFunction() |
FunctionList.Function<E,S> |
getReverseFunction() |
protected boolean |
isWritable()
Gets whether the source
EventList is writable via this API. |
void |
listChanged(ListEvent<S> 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 |
setForwardFunction(FunctionList.Function<S,E> forward)
Changes the
FunctionList.Function that evaluates source elements to produce mapped elements. |
void |
setReverseFunction(FunctionList.Function<E,S> reverse)
Changes the
FunctionList.Function that evaluates FunctionList elements to produce the original
source element with which it corresponds. |
addAll, clear, dispose, getSourceIndex, removeAll, retainAll, size
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 FunctionList(EventList<S> source, FunctionList.Function<S,E> forward)
FunctionList
which stores the result of transforming each source element
using the given forward FunctionList.Function
. No reverse FunctionList.Function
will be specified
implying that AbstractEventList.add(Object)
, add(int, Object)
and set(int, Object)
will throw IllegalArgumentException
if they are called.source
- the EventList to decorate with a function transformationforward
- the function to execute on each source elementpublic FunctionList(EventList<S> source, FunctionList.Function<S,E> forward, FunctionList.Function<E,S> reverse)
FunctionList
which stores the result of transforming each source element
using the given forward FunctionList.Function
. If the reverse FunctionList.Function
is not null,
AbstractEventList.add(Object)
, add(int, Object)
and set(int, Object)
will execute as
expected.
Note: an FunctionList.AdvancedFunction
can be specified for the forward FunctionList.Function
which
allows the implementor a chance to examine the prior value that was mapped to a source element
when it must be remapped due to a modification (from a call to List.set(int, E)
).
source
- the EventList to decorate with a function transformationforward
- the function to execute on each source elementreverse
- the function to map elements of FunctionList back to element values in the
source listpublic FunctionList.Function<S,E> getForwardFunction()
FunctionList.Function
which maps source elements to elements stored within this
FunctionList
. The FunctionList.Function
is guaranteed to be non-null.public void setForwardFunction(FunctionList.Function<S,E> forward)
FunctionList.Function
that evaluates source elements to produce mapped elements. Calling
this method with a different forward
Function will cause all elements in this
FunctionList to be reevaluated.
Callers of this method typically also want to update the reverse function using
setReverseFunction(org.jadice.util.glazedlists.FunctionList.Function<E, S>)
if one exists.
public FunctionList.Function<E,S> getReverseFunction()
FunctionList.Function
which maps elements stored within this FunctionList
back
to elements within the source list or null
if no such FunctionList.Function
was
specified.public void setReverseFunction(FunctionList.Function<E,S> reverse)
FunctionList.Function
that evaluates FunctionList elements to produce the original
source element with which it corresponds. The reverse Function will be used in all subsequent
calls to:
This method should typically be called at the same time the forward function is changed using
setForwardFunction(org.jadice.util.glazedlists.FunctionList.Function<S, E>)
.protected boolean isWritable()
EventList
is writable via this API.
Extending classes must override this method in order to make themselves writable.
isWritable
in class TransformedList<S,E>
public void listChanged(ListEvent<S> 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<S>
listChanged
in class TransformedList<S,E>
listChanges
- a ListEvent
describing the changes to the listpublic E get(int index)
public E remove(int index)
public E set(int index, E value)
public void add(int index, E value)
Copyright © 2024 levigo holding gmbh. All rights reserved.