I
- the "input" type; the type of the wrapped collectionO
- the "output" type; the type of elements in this collectionpublic static class TransformingCollection.Bidi<I,O> extends TransformingCollection<I,O>
add(Object)
and addAll(Collection)
.
Several methods are overridden to use the reverse function before delegating to the
underlying list. Since some of these interface methods actually accept any type of object
(instead of requiring the list's element type), this implementation could result in
ClassCastException
s if objects with incorrect types are passed to them. These
methods are contains(Object)
, containsAll(Collection)
,
remove(Object)
, removeAll(Collection)
, and retainAll(Collection)
.
TransformingCollection.Bidi<I,O>, TransformingCollection.ReadOnly<I,O>
Constructor and Description |
---|
Bidi(Collection<I> collection,
Function<? super I,? extends O> function1,
Function<? super O,? extends I> function2)
Constructs a new bidirectional transforming collection.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(O e) |
boolean |
addAll(Collection<? extends O> c) |
boolean |
contains(Object o) |
boolean |
containsAll(Collection<?> c) |
protected Function<? super O,? extends I> |
inverseFunction()
Gets the function used to transform elements from the "output" domain to the "input"
domain.
|
boolean |
remove(Object o) |
boolean |
removeAll(Collection<?> c) |
boolean |
retainAll(Collection<?> c) |
protected I |
unapply(Object input)
Transforms "output" elements into "input" elements.
|
protected Collection<I> |
unapplyAll(Collection<?> c)
Transforms a collection of "output" elements into "input" elements.
|
clear, internal, isEmpty, size, toArray, toArray, toString
apply, function, iterator
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
equals, hashCode, iterator, parallelStream, removeIf, spliterator, stream
public Bidi(Collection<I> collection, Function<? super I,? extends O> function1, Function<? super O,? extends I> function2)
i
in the input domain,
i
must equal function2.apply(function1.apply(i))
. Similarly, for
any object o
in the output domain, o
must equal
function1.apply(function2.apply(o))
.collection
- the wrapped collectionfunction1
- transforms elements; "input" -> "output"function2
- the inverse of function1
; "output" -> "input"protected Function<? super O,? extends I> inverseFunction()
TransformingIterable.function()
.protected I unapply(Object input)
TransformingIterable.apply(Object)
.input
- the object to transform, which should be of type O
protected Collection<I> unapplyAll(Collection<?> c)
c
- the collection to transform, whose elements should be of type O
public boolean add(O e)
add
in interface Collection<O>
add
in class TransformingCollection<I,O>
public boolean remove(Object o)
remove
in interface Collection<O>
remove
in class TransformingCollection<I,O>
public boolean contains(Object o)
contains
in interface Collection<O>
contains
in class TransformingCollection<I,O>
public boolean containsAll(Collection<?> c)
containsAll
in interface Collection<O>
containsAll
in class TransformingCollection<I,O>
public boolean removeAll(Collection<?> c)
removeAll
in interface Collection<O>
removeAll
in class TransformingCollection<I,O>
public boolean retainAll(Collection<?> c)
retainAll
in interface Collection<O>
retainAll
in class TransformingCollection<I,O>
public boolean addAll(Collection<? extends O> c)
addAll
in interface Collection<O>
addAll
in class TransformingCollection<I,O>