Interface FilterModel.IncludedItems<T>
- Type Parameters:
T- the item type
- All Superinterfaces:
MultiSelection.IndexedItems<T>,Observable<List<T>>,Observer<List<T>>
- Enclosing interface:
FilterModel<T>
The included items, the ones passing the FilterModel.IncludePredicate, in their current order.
Notifications, Observer.observer() and added(), are delivered once a mutation has completed
and the selection has been restored, so a listener may read the selection while responding to one - it
never sees the selection a mutation momentarily empties. A mutation notifies once, not once per internal
step: a refresh, which clears and re-adds the items, notifies a single time.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceProvides a way to respond to changes to the included items.Nested classes/interfaces inherited from interface is.codion.common.reactive.observer.Observer
Observer.Builder<T,B extends Observer.Builder<T, B>> -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(int index, Collection<T> items) Adds the given items at the given index and sorts the included items if sorting is enabled.booleanAdds the given item at the given index and sorts the included items if sorting is enabled.added()Notified when items have been added to the ones already included, with the items added.booleanReturns true if the given item is includedget()Returns an unmodifiable snapshot, stable and safe to iterate; it does not reflect subsequent changes to the model.get(int index) remove(int index) Removes from this model the included element at the given indexremove(int fromIndex, int toIndex) Removes from this model all included elements whose index is betweenfromIndex, inclusive andtoIndex, exclusivebooleanSets the item at the given index.voidsort()Sorts the included items using thisFilterModel.Sortinstance, preserving the selection.Methods inherited from interface is.codion.common.model.selection.MultiSelection.IndexedItems
indexOf, sizeMethods inherited from interface is.codion.common.reactive.observer.Observable
changed, getOrThrow, getOrThrow, is, isNot, isNull, isNullable, optionalMethods inherited from interface is.codion.common.reactive.observer.Observer
addConsumer, addListener, addWeakConsumer, addWeakListener, observer, removeConsumer, removeListener, removeWeakConsumer, removeWeakListener, when, when
-
Method Details
-
get
Returns an unmodifiable snapshot, stable and safe to iterate; it does not reflect subsequent changes to the model. Useget(int)andMultiSelection.IndexedItems.size()for indexed access, which avoids the copy.- Specified by:
getin interfaceMultiSelection.IndexedItems<T>- Specified by:
getin interfaceObservable<T>- Returns:
- the included items or an empty list if all items are filtered
-
predicate
FilterModel.IncludePredicate<T> predicate()- Returns:
- the
FilterModel.IncludePredicatecontrolling which items should be included
-
added
Observer<Collection<T>> added()Notified when items have been added to the ones already included, with the items added.
Not notified when the items are replaced wholesale via
FilterModel.Items.set(Collection), a refresh for example - those are the model's new contents rather than additions to it, and are reported byObservable.changed().- Returns:
- an
Observernotified when items have been added - See Also:
-
selection
SingleSelection<T> selection()- Returns:
- the
SingleSelectioninstance for these items
-
contains
Returns true if the given item is included- Parameters:
item- the item- Returns:
- true if the item is included
-
get
- Specified by:
getin interfaceMultiSelection.IndexedItems<T>- Parameters:
index- the row index- Returns:
- the item at the given index in this model
- Throws:
IndexOutOfBoundsException- in case the index is out of bounds
-
add
Adds the given item at the given index and sorts the included items if sorting is enabled.
Note that if the item does not pass the
predicate()it is filtered right away and the method returns false.- Parameters:
index- the indexitem- the item to add- Returns:
- true if the item was added to the included items
- Throws:
IndexOutOfBoundsException- in case the index is out of bounds
-
add
Adds the given items at the given index and sorts the included items if sorting is enabled.
Note that if an item does not pass the
predicate()it is filtered right away.- Parameters:
index- the index at which to add the itemsitems- the items to add- Returns:
- true if one or more of the items was added to the included items
- Throws:
IndexOutOfBoundsException- in case the index is out of bounds
-
set
Sets the item at the given index. Note that sorting is NOT performed after the item has been set.
Note that if the item does not pass the
predicate()this method has no effect.- Parameters:
index- the indexitem- the item- Returns:
- true if the item was set, false if it did not pass the
predicate() - Throws:
IndexOutOfBoundsException- in case the index is out of bounds- See Also:
-
remove
Removes from this model the included element at the given index
- Parameters:
index- the index of the row to be removed- Returns:
- the removed item
- Throws:
IndexOutOfBoundsException- in case the index is out of bounds
-
remove
Removes from this model all included elements whose index is between
fromIndex, inclusive andtoIndex, exclusive- Parameters:
fromIndex- index of first row to be removedtoIndex- index after last row to be removed- Returns:
- the removed items
- Throws:
IndexOutOfBoundsException- in case the indexes are out of bounds
-
sort
void sort()Sorts the included items using thisFilterModel.Sortinstance, preserving the selection.- See Also:
-