T
- the type of element contained by the Snapshot
.@FunctionalInterface public interface Snapshot<T> extends Iterable<T>
Set
of results aware of its context.
This is a functional interface whose functional method is unfilteredStream()
.
Modifier and Type | Interface and Description |
---|---|
static class |
Snapshot.ChangeType |
static class |
Snapshot.IndexedElement<T>
Helper class whose instances contain an element of type T and an int index.
|
static class |
Snapshot.TaggedElement<T,U> |
Modifier and Type | Method and Description |
---|---|
default boolean |
contains(Object o)
Returns
true if this snapshot contains the specified element. |
default boolean |
containsAll(Collection<?> c)
Returns
true if this snapshot contains all of the elements in the specified snapshot. |
static <T> Snapshot<T> |
empty()
Returns an empty Snapshot.
|
default Snapshot<T> |
filter(IndexFilter filter)
A new Snapshot filtered with the given
IndexFilter . |
default Snapshot<T> |
filter(List<IndexFilter> filters)
A new Snapshot filtered with the given
IndexFilter s. |
default Snapshot<T> |
filter(Predicate<T> predicate)
Returns a new Snapshot containing only the elements matching the given
Predicate . |
default T |
first()
Returns the first element of this snapshot or
null if this snapshot is empty. |
default io.reactivex.Observable<Optional<T>> |
firstOnChanged()
Returns an
Observable emitting Optional s with the first element of the Snapshot. |
static <T> Snapshot<T> |
fromCollection(Collection<T> elements)
Returns a Snapshot containing the elements of the given Collection.
|
default T |
get(Object o)
Returns the first element in this snapshot equals to the specified object or
null if no element in this snapshot is equal to the specified object. |
default io.reactivex.Observable<T> |
getAdds()
Returns an
Observable emitting the items added to the Snapshot after it was created. |
default T |
getByIndex(int index)
Returns the Snapshot’s element with the given index.
|
default Comparator<T> |
getComparator()
Returns the
Comparator for this Snapshot. |
default IndexFilter |
getFilter()
Returns the
IndexFilter to apply to the parent to build this Snapshot. |
default io.reactivex.Observable<Snapshot.IndexedElement<T>> |
getIndexedElements()
Returns an
Observable emitting each element of the Snapshot with its index. |
default Snapshot<T> |
getParent()
Returns this Snapshot’s parent.
|
default io.reactivex.Observable<T> |
getRemovals()
Returns an
Observable emitting the items deleted from the Snapshot after it was created. |
default String |
info()
Returns a
String representation of all vertices contained in this snapshot. |
default boolean |
isEmpty()
Returns
true if this snapshot contains no elements. |
default Iterator<T> |
iterator()
Returns an Iterator over the elements of this Snapshot.
|
default io.reactivex.Observable<List<T>> |
listOnChanged()
Returns an
Observable emitting a List representing the Snapshot after each change. |
default <U> Snapshot<U> |
map(io.reactivex.functions.Function<T,U> mapper)
Applies a transformation to each element of the Snapshot.
|
default io.reactivex.Observable<Set<T>> |
setOnChanged()
Returns an
Observable emitting a Set representing the Snapshot after each change. |
static <T> Snapshot<T> |
singleton(T element)
Returns a Snapshot containing only an element.
|
default int |
size()
Returns the number of elements in this snapshot.
|
default Snapshot<T> |
sort(Comparator<T> comparator)
Returns a new Snapshot sorted with the given
Comparator . |
default Snapshot<T> |
sorted()
Returns a new Snapshot sorted according to the natural order.
|
default Stream<T> |
stream()
Returns a
Stream of this Snapshot . |
default List<T> |
toList()
Returns a List representation of the Snapshot.
|
default javafx.collections.ObservableList<T> |
toObservableList()
Deprecated.
|
default Set<T> |
toSet() |
Stream<T> |
unfilteredStream()
Defines a Stream of this Snapshot.
|
forEach, spliterator
static <T> Snapshot<T> empty()
T
- Type of the elements of the Snapshot.static <T> Snapshot<T> singleton(T element)
T
- Type of the elements of the Snapshot.element
- The returned Snapshot’s element.static <T> Snapshot<T> fromCollection(Collection<T> elements)
T
- Type of the elements of the Snapshot.elements
- The returned Snapshot’s elements.default Snapshot<T> getParent()
getFilter()
’s return value is not null.default IndexFilter getFilter()
IndexFilter
to apply to the parent to build this Snapshot.
The return value must be non-null iff getParent()
’s return value is not null.default Stream<T> stream()
Stream
of this Snapshot
.
This method builds this Snapshot’s stream(), taking into account
the values of getFilter()
and getParent()
if any.
It must not be overridden. To define the Snapshot contents, override
the methods unfilteredStream()
, getAdds()
and getRemovals()
.Stream
of this Snapshot
.Stream<T> unfilteredStream()
getFilter()
’s method returns null
, the return value of
stream()
is the same as the return value of unfilteredStream().
This method must be overridden when defining a new Snapshot that can then be filtered
with filter(IndexFilter)
However, to obtain a Stream of any Snapshot,
stream()
should be used, never unfilteredStream()
.default int size()
default boolean isEmpty()
true
if this snapshot contains no elements.true
if this snapshot contains no elements.default boolean contains(Object o)
true
if this snapshot contains the specified element.o
- element whose presence in this snapshot is to be tested.true
if this snapshot contains the specified element.default boolean containsAll(Collection<?> c)
true
if this snapshot contains all of the elements in the specified snapshot.c
- collection to be checked for containment in this snapshot.true
if this snapshot contains all of the elements in the specified snapshot.default T get(Object o)
null
if no element in this snapshot is equal to the specified object.o
- object to be tested for equality.null
if no element in this snapshot is equal to the specified object.default String info()
String
representation of all vertices contained in this snapshot.String
representation of all vertices contained in this snapshot.default T first()
null
if this snapshot is empty.null
if this snapshot is empty.default T getByIndex(int index)
iterator()
. If there is no such element, returns null
.index
- The index of the wanted element.null
if there is no
element at that index.default io.reactivex.Observable<T> getAdds()
Observable
emitting the items added to the Snapshot after it was created.
This must be overridden if these updates are necessary, e.g. to update a view of the Snapshot’s contents.Observable
emitting the elements added to the Snapshot after its creation.
An empty Observable by default.default io.reactivex.Observable<T> getRemovals()
Observable
emitting the items deleted from the Snapshot after it was created.
This must be overridden if these updates are necessary, e.g. to update a view of the Snapshot’s contents.Observable
emitting the elements removed from the Snapshot since its creation.
An empty Observable by default.default Comparator<T> getComparator()
Comparator
for this Snapshot. This is used only to determine the indices of the elements
in getIndexedElements()
, and to order the emitted sets in setOnChanged()
.
The Comparator provided must be consistent with equals (see Comparator
).null
by default.default io.reactivex.Observable<Snapshot.IndexedElement<T>> getIndexedElements()
Observable
emitting each element of the Snapshot with its index.
Returns an Observable that emits Snapshot.IndexedElement
s corresponding to:
getAdds()
, with an index corresponding to their position
in a List representing the Snapshot.
getRemovals()
, with an index of -1.
Warning: Although this method returns indices as though the Snapshot was represented by a List, it uses a Set internally to forbid duplicates.
If getComparator()
returns a non-null value, the provided Comparator
is used to order
the elements of the Snapshot.
Observable
emitting the indexed elements of this Snapshot.default io.reactivex.Observable<Set<T>> setOnChanged()
Observable
emitting a Set
representing the Snapshot after each change.
If getComparator()
provides a Comparator
to use for this Snapshot, the emitted set
is ordered with the given comparator.Observable
emitting a Set
representing the Snapshot after each change.default io.reactivex.Observable<List<T>> listOnChanged()
Observable
emitting a List
representing the Snapshot after each change.
The emitted lists contain no duplicates.
If getComparator()
provides a Comparator
to use for this Snapshot, the emitted list
is ordered with the given comparator.Observable
emitting a List
representing the Snapshot after each change.default io.reactivex.Observable<Optional<T>> firstOnChanged()
Observable
emitting Optional
s with the first element of the Snapshot.
Emits an Optional containing the first element of the Snapshot when that element changes.
Emits an empty Optional if the Snapshot is empty.default Snapshot<T> sort(Comparator<T> comparator)
Comparator
.comparator
- The Comparator
to use for the new Snapshot.default Snapshot<T> sorted()
Comparable
, the new Snapshot uses
this implementation to sort the elements. Otherwise, the elements are sorted according
to the Strings returned by toString(), using the Collator
for the current
default Locale.default Snapshot<T> filter(Predicate<T> predicate)
Predicate
.
If getComparator()
defines a Comparator
for the current Snapshot, the sort order
is kept for the returned Snapshot.predicate
- The predicate used to filter the Snapshot.default Snapshot<T> filter(IndexFilter filter)
IndexFilter
.
The returned Snapshot is a child of the current Snapshot.
If getComparator()
defines a Comparator
for the current Snapshot, the sort order
is kept for the returned Snapshot.filter
- The filter to use to select the elements to keep.default Snapshot<T> filter(List<IndexFilter> filters)
IndexFilter
s.
If getComparator()
defines a Comparator
for the current Snapshot, the sort order
is kept for the returned Snapshot.filters
- The filters to use to select the elements to keep.default <U> Snapshot<U> map(io.reactivex.functions.Function<T,U> mapper)
getComparator()
defines a Comparator
for the current Snapshot, the sort order
is kept for the returned Snapshot.U
- Type of the elements of the returned Snapshot.mapper
- The transformation to apply to the Snapshot’s elements.default List<T> toList()
@Deprecated default javafx.collections.ObservableList<T> toObservableList()
getAdds()
and getRemovals()
.Copyright © 2022. All rights reserved.