T - the type of the Java objects that back each Item in the containerpublic abstract class AbstractUnsizedContainer<T> extends AbstractQueryContainer<T>
AbstractQueryContainer that doesn't require up-front knowledge of the underlying data's size.
Subclasses only need support retrieving a contiguous window of fixed size from the underlying data
via queryWindow(); when the requested window goes beyond the end of the underlying data,
a short or empty result is returned. Based on just this information, this class maintains an estimate of
the size of the underlying data. Each time that size estimate changes, handleSizeChange() is invoked
to schedule a (non-reentrant) property set change notification. Once the end of the underlying data is reached,
the size is known.
If the actual size of the underlying data is constant, this class will eventually find it. If the
actual size of the underlying data can change (either up or down), this class will adapt accordingly,
but only when it learns of the new size through an invocation of queryWindow();
as this depends on how the container is used, this may not occur for a long time.
When used to back a Vaadin table, the user will see a table that automatically grows as the user scrolls downward, until the actual end of the data is detected.
AbstractQueryContainer,
Serialized FormAbstractContainer.BaseItemSetChangeEvent, AbstractContainer.BasePropertySetChangeEventContainer.Indexed.ItemAddEvent, Container.Indexed.ItemRemoveEventContainer.Editor, Container.Filter, Container.Filterable, Container.Hierarchical, Container.Indexed, Container.ItemSetChangeEvent, Container.ItemSetChangeListener, Container.ItemSetChangeNotifier, Container.Ordered, Container.PropertySetChangeEvent, Container.PropertySetChangeListener, Container.PropertySetChangeNotifier, Container.SimpleFilterable, Container.Sortable, Container.Viewer| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_WINDOW_SIZE |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractUnsizedContainer()
Convenience constructor.
|
protected |
AbstractUnsizedContainer(Class<? super T> type)
Convenience constructor.
|
protected |
AbstractUnsizedContainer(Collection<? extends PropertyDef<?>> propertyDefs)
Convenience constructor.
|
protected |
AbstractUnsizedContainer(int windowSize)
Constructor.
|
protected |
AbstractUnsizedContainer(int windowSize,
Class<? super T> type)
Constructor.
|
protected |
AbstractUnsizedContainer(int windowSize,
Collection<? extends PropertyDef<?>> propertyDefs)
Constructor.
|
protected |
AbstractUnsizedContainer(int windowSize,
PropertyExtractor<? super T> propertyExtractor)
Constructor.
|
protected |
AbstractUnsizedContainer(int windowSize,
PropertyExtractor<? super T> propertyExtractor,
Collection<? extends PropertyDef<?>> propertyDefs)
Constructor.
|
protected |
AbstractUnsizedContainer(PropertyExtractor<? super T> propertyExtractor)
Convenience constructor.
|
protected |
AbstractUnsizedContainer(PropertyExtractor<? super T> propertyExtractor,
Collection<? extends PropertyDef<?>> propertyDefs)
Convenience constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
fireItemSetChange(Container.ItemSetChangeEvent event) |
long |
getCurrentSizeEstimate()
Get the current size estimate for the underlying data.
|
protected long |
getLargerEstimate(long lowerBound)
Estimate the size of the underlying data given that
lowerBound is a lower bound. |
protected long |
getSmallerEstimate(long upperBound)
Handle the case where the underlying data's size has suddenly shrunk, so we need to estimate the new size.
|
int |
getWindowSize()
Get the window size configured at construction time.
|
protected abstract void |
handleSizeChange()
Emit a property set change notification.
|
protected QueryList<T> |
query(long hint)
Perform a query to (re)generate the list of Java objects backing this container.
|
protected abstract List<? extends T> |
queryWindow(long offset,
int length)
Query the underlying data for a window of items in the given range.
|
addContainerProperty, addItem, addItem, addItemAfter, addItemAfter, addItemAt, addItemAt, addItemSetChangeListener, addListener, addListener, addPropertySetChangeListener, connect, containsId, createBackedItem, disconnect, ensureList, firstItemId, getContainerProperty, getContainerPropertyIds, getIdByIndex, getItem, getItemIds, getItemIds, getJavaObject, getPropertyExtractor, getPropertyValue, getType, indexOfId, invalidate, isFirstId, isLastId, lastItemId, nextItemId, prevItemId, reload, removeAllItems, removeContainerProperty, removeItem, removeItemSetChangeListener, removeListener, removeListener, removePropertySetChangeListener, setProperties, setPropertyExtractor, sizefireContainerPropertySetChange, fireContainerPropertySetChange, fireItemSetChange, getItemSetChangeListeners, getListeners, getPropertySetChangeListeners, setItemSetChangeListeners, setPropertySetChangeListenerspublic static final int DEFAULT_WINDOW_SIZE
protected AbstractUnsizedContainer()
AbstractUnsizedContainer(DEFAULT_WINDOW_SIZE)
After using this constructor, subsequent invocations of setPropertyExtractor()
and setProperties() are required to define the properties of this container
and how to extract them.
protected AbstractUnsizedContainer(PropertyExtractor<? super T> propertyExtractor)
AbstractUnsizedContainer(DEFAULT_WINDOW_SIZE, propertyExtractor)
After using this constructor, a subsequent invocation of setProperties() is required
to define the properties of this container.
propertyExtractor - used to extract properties from the underlying Java objects;
may be null but then container is not usable until one is configured via
setPropertyExtractor()protected AbstractUnsizedContainer(Collection<? extends PropertyDef<?>> propertyDefs)
AbstractUnsizedContainer(DEFAULT_WINDOW_SIZE, propertyDefs)
After using this constructor, a subsequent invocation of setPropertyExtractor()
is required to define how to extract the properties of this container; alternately, subclasses can override
getPropertyValue().
propertyDefs - container property definitions; null is treated like the empty setprotected AbstractUnsizedContainer(PropertyExtractor<? super T> propertyExtractor, Collection<? extends PropertyDef<?>> propertyDefs)
AbstractUnsizedContainer(DEFAULT_WINDOW_SIZE, propertyExtractor, propertyDefs)
propertyExtractor - used to extract properties from the underlying Java objects;
may be null but then container is not usable until one is configured via
setPropertyExtractor()propertyDefs - container property definitions; null is treated like the empty setprotected AbstractUnsizedContainer(int windowSize)
After using this constructor, subsequent invocations of setPropertyExtractor()
and setProperties() are required to define the properties of this container
and how to extract them.
windowSize - size of the query windowIllegalArgumentException - if windowSize is less than 1protected AbstractUnsizedContainer(int windowSize,
PropertyExtractor<? super T> propertyExtractor)
After using this constructor, a subsequent invocation of setProperties() is required
to define the properties of this container.
windowSize - size of the query windowpropertyExtractor - used to extract properties from the underlying Java objects;
may be null but then container is not usable until one is configured via
setPropertyExtractor()IllegalArgumentException - if windowSize is less than 1protected AbstractUnsizedContainer(int windowSize,
Collection<? extends PropertyDef<?>> propertyDefs)
After using this constructor, a subsequent invocation of setPropertyExtractor()
is required to define how to extract the properties of this container; alternately, subclasses can override
getPropertyValue().
windowSize - size of the query windowpropertyDefs - container property definitions; null is treated like the empty setIllegalArgumentException - if windowSize is less than 1protected AbstractUnsizedContainer(int windowSize,
PropertyExtractor<? super T> propertyExtractor,
Collection<? extends PropertyDef<?>> propertyDefs)
windowSize - size of the query window (how big of a chunk we query at one time)propertyExtractor - used to extract properties from the underlying Java objects;
may be null but then container is not usable until one is configured via
setPropertyExtractor()propertyDefs - container property definitions; null is treated like the empty setIllegalArgumentException - if windowSize is less than 1protected AbstractUnsizedContainer(Class<? super T> type)
AbstractUnsizedContainer(DEFAULT_WINDOW_SIZE, type)
type - class to introspect for @ProvidesProperty-annotated fields and methodsIllegalArgumentException - if type is nullIllegalArgumentException - if type has two @ProvidesProperty
or @ProvidesPropertySort annotated methods for the same propertyIllegalArgumentException - if a @ProvidesProperty-annotated method with no
property name specified has a name which cannot be interpreted as a bean
property "getter" methodProvidesProperty,
ProvidesPropertySort,
ProvidesPropertyScannerprotected AbstractUnsizedContainer(int windowSize,
Class<? super T> type)
Properties will be determined by the @ProvidesProperty and
@ProvidesPropertySort annotated methods in the given class.
windowSize - size of the query windowtype - class to introspect for annotated methodsIllegalArgumentException - if type is nullIllegalArgumentException - if type has two @ProvidesProperty
or @ProvidesPropertySort annotated methods for the same propertyIllegalArgumentException - if a @ProvidesProperty-annotated method with no
property name specified has a name which cannot be interpreted as a bean
property "getter" methodProvidesProperty,
ProvidesPropertySort,
ProvidesPropertyScannerprotected QueryList<T> query(long hint)
AbstractQueryContainer
The particular position in the list we are interested in is given as a hint by the hint parameter.
That is, an invocation of QueryList.get(long)(hint) is likely immediately after this method
returns and if so it must complete without throwing an exception, unless hint is out of range.
The hint can be used to implement a highly scalable query list containing external objects
(such as from a database) where only a small "window" of objects is actually kept in memory at any one time.
Of course, implementations are also free to ignore hint. However, the returned QueryList
must at least tolerate one invocation of get(hint) without throwing an exception
when hint is less that the size() of the returned QueryList.
query in class AbstractQueryContainer<T>hint - index of the list element we are interested inpublic int getWindowSize()
public long getCurrentSizeEstimate()
protected long getSmallerEstimate(long upperBound)
upperBound or less.
This method should guess at the new value and, when called repeatedly, should converge rapidly to zero.
Note: this situation will not occur if the underlying data's size never decreases.
The implementation in AbstractUnsizedContainer returns upperBound * 0.75.
upperBound - an upper bound on the size of the underlying dataprotected long getLargerEstimate(long lowerBound)
lowerBound is a lower bound.
This effectively determines how much data will appear to be "beyond" the current window.
The implementation in AbstractUnsizedContainer returns lowerBound * 1.25.
lowerBound - a lower bound on the size of the underlying dataprotected void fireItemSetChange(Container.ItemSetChangeEvent event)
fireItemSetChange in class AbstractContainerprotected abstract List<? extends T> queryWindow(long offset, int length)
offset and having at least length length, or else however many remain.
If offset is greater than or equal to the size of the underlying data, an empty list should be returned.offset - starting offset for windowlength - window size, always greater than zerolength items in the window starting at offset offset; or less than
length items if offset + length is greater than the size of the underlying dataprotected abstract void handleSizeChange()
Subclasses are required to implement this so that size changes are detected.
Note: to avoid re-entrancy problems, this method should not send out any notifications itself; instead, it must schedule notifications to be delivered later (perhaps in a different thread).
handleSizeChange in class AbstractQueryContainer<T>Copyright © 2017. All rights reserved.