Module com.iamsoft.util.ui
Class LazyObservableList<K,V>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
javafx.collections.ObservableListBase<E>
javafx.collections.transformation.TransformationList<javafx.concurrent.Task<V>,K>
com.iamsoft.util.ui.javafx.collections.LazyObservableList<K,V>
- Type Parameters:
K- Key type.V- Value type.
- All Implemented Interfaces:
Iterable<javafx.concurrent.Task<V>>,Collection<javafx.concurrent.Task<V>>,List<javafx.concurrent.Task<V>>,javafx.beans.Observable,javafx.collections.ObservableList<javafx.concurrent.Task<V>>
public class LazyObservableList<K,V>
extends javafx.collections.transformation.TransformationList<javafx.concurrent.Task<V>,K>
Observable list that fetches values from potentially slow resource. A 'viewport'
defines the range of values that should be retrieved. When values exit viewport,
they are immediately discarded and associated tasks are canceled. Thus,
LazyObservableList typically contains mostly nulls with a narrow band of 'task' objects.
Values are expected to be immutable. If change occurs, base ObservableList should simply
replace object. To simulate mutation, use a decorator on top of LazyObservableList.
- See Also:
-
Property Summary
Properties -
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionLazyObservableList(javafx.collections.ObservableList<K> pKeys, javafx.beans.value.ObservableValue<com.google.common.collect.Range<Integer>> pViewportRange, Function<com.google.common.collect.Range<Integer>, Map<K, javafx.concurrent.Task<V>>> pFetchFunction, Consumer<K> pUnsubscribeFunction) -
Method Summary
Modifier and TypeMethodDescriptionjavafx.concurrent.Task<V>get(int pIdx) static intGet lower endpoint (inclusive).intgetSourceIndex(int pIdx) static intGet upper endpoint (exclusive).intgetViewIndex(int pIdx) final booleanCan be used to determine whether a list change occurs due to viewport change.voidrefresh()Clears old values and re-fetches viewport values.protected voidintsize()protected voidsourceChanged(javafx.collections.ListChangeListener.Change<? extends K> pChg) final javafx.beans.property.ReadOnlyBooleanPropertyMethods inherited from class javafx.collections.transformation.TransformationList
getSource, getSourceIndexFor, isInTransformationChainMethods inherited from class javafx.collections.ObservableListBase
addAll, addListener, addListener, beginChange, endChange, fireChange, hasListeners, nextAdd, nextPermutation, nextRemove, nextRemove, nextReplace, nextSet, nextUpdate, remove, removeAll, removeListener, removeListener, retainAll, setAll, setAllMethods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subListMethods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
add, add, addAll, addAll, clear, contains, containsAll, equals, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, set, sort, spliterator, subList, toArray, toArrayMethods inherited from interface javafx.collections.ObservableList
filtered, sorted, sorted
-
Property Details
-
viewportChange
public final javafx.beans.property.ReadOnlyBooleanProperty viewportChangeProperty- See Also:
-
-
Constructor Details
-
LazyObservableList
public LazyObservableList(javafx.collections.ObservableList<K> pKeys, javafx.beans.value.ObservableValue<com.google.common.collect.Range<Integer>> pViewportRange, Function<com.google.common.collect.Range<Integer>, Map<K, javafx.concurrent.Task<V>>> pFetchFunction, Consumer<K> pUnsubscribeFunction) - Parameters:
pKeys- List of unique item identifiers.pViewportRange- Range (offset to length) within which data should be fetched and actively monitored. Range is allowed to extend beyond key list size.pFetchFunction- Function for retrieving actively-monitored remote data. Function is responsible for starting tasks. Where possible, it is encouraged to request all data with a single 'parent' request upon which child tasks depend. In this case, canceling all child tasks should cancel parent.pUnsubscribeFunction- Function to cease active monitoring of a value.
-
-
Method Details
-
viewportChangeProperty
public final javafx.beans.property.ReadOnlyBooleanProperty viewportChangeProperty()- See Also:
-
isViewportChange
public final boolean isViewportChange()Can be used to determine whether a list change occurs due to viewport change. -
get
-
size
public int size()- Specified by:
sizein interfaceCollection<K>- Specified by:
sizein interfaceList<K>- Specified by:
sizein classAbstractCollection<javafx.concurrent.Task<V>>
-
refresh
public void refresh()Clears old values and re-fetches viewport values. -
runLater
-
sourceChanged
-
getSourceIndex
public int getSourceIndex(int pIdx) -
getViewIndex
public int getViewIndex(int pIdx) -
getFrom
Get lower endpoint (inclusive). -
getTo
Get upper endpoint (exclusive).
-