Class TLcdModelList
- All Implemented Interfaces:
ILcdModel,ILcdModelContainer,ILcdModelProducerListener,ILcdLockDependent,ILcdDisposable,Serializable,AutoCloseable,EventListener
- Direct Known Subclasses:
TLcd2DBoundsIndexedModelList
ILcdModel that is composed of an ordered list of other ILcdModel objects.
This model has as elements the union of all the elements contained in its submodels. The order in which the
elements() enumeration iterates over the elements corresponds to the order of the submodels in this model:
first all elements of the first submodel are iterated over, then the elements of the second submodel, etcetera.
Using a TLcdModelList has several advantages over copying all elements of the submodels into a new, flat
model. A model list does not flatten the data structure which allows, for example, fast reordening of the submodels
after the model list has been created. Additionally, each submodel can also keep its own (more detailed) model
descriptor, next to the model descriptor of the model list.
Since a model list is also an ILcdModel, all of its submodels should share the same model reference.
This model itself is not editable; adding or removing elements from this model is not allowed. The elements are contained in the submodels and should be added and removed from those models.
Some methods require this model to retrieve the submodel in which an element is contained. This is done by
iterating over all submodels and calling the isObjectInModel(Object, ILcdModel) method for each submodel.
By default, this method uses a TLcdDefaultObjectInModelFilter to determine whether the
specified element is contained in a submodel. Users of this class may use the
addModel(ILcdModel, com.luciad.util.ILcdFilter) method to provide a more performant filter. Especially when
dealing with lazily-loaded submodels, it is important to use a proper filter, to avoid unnecessary loading of
submodels.
Any model descriptor can be set on this model. If an TLcdEditableModelListDescriptor is used, the
descriptor will be automatically updated whenever a submodel is added to or removed from this model.
If all submodels implement ILcd2DBoundsIndexedModel, one should consider using
TLcd2DBoundsIndexedModelList instead of this model, to preserve the ability the perform
spatial queries on this model list. The package documentation provides a detailed overview
of all model implementations that are available in this package, and their usage.
An alternative for grouping models is an ILcdModelTreeNode.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.luciad.model.ILcdModel
ILcdModel.Query -
Field Summary
Fields inherited from class com.luciad.model.ALcdModel
fModelEventSupportFields inherited from interface com.luciad.model.ILcdModel
FIRE_LATER, FIRE_NOW, NO_EVENT -
Constructor Summary
ConstructorsConstructorDescriptionConstructs new, emptyTLcdModelListlist with aTLcdEditableModelListDescriptor.TLcdModelList(ILcdModelDescriptor aModelDescriptor) Constructs new, emptyTLcdModelListlist with the specifiedILcdModelDescriptor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddElement(Object aElement, int aFireEventMode) Adds the specified element to this model.voidaddElements(Vector aElements, int aFireEventMode) Adds all of the elements in the specified vector to this model.booleanAdds the specified model to this model list, without a filter.booleanaddModel(ILcdModel aModel, ILcdFilter aObjectInModelFilter) Adds the specified model to this model list.voidaddModelContainerListener(ILcdModelContainerListener aModelContainerListener) Adds anILcdModelContainerListenerto thisILcdModelContainer.voidaddModelListener(ILcdModelListener aModelListener) Registers the specified model listener to receive notifications of model changes on this model.booleancanAddElement(Object aElement) Returnstrueif the specified element can be added to this model,falseotherwise.booleancanAddModel(ILcdModel aModel) Returnstrueif the specified model can be added to this list,falseotherwise.booleancanRemoveElement(Object aObject) Returnstrueif the specified element can be removed from this model,falseotherwise.voiddispose()Disposes of this model and allows it to release any system resources that it is holding.voidelementChanged(Object aObject, int aEventMode) Notifies this model that the specified element has changed.elements()Returns an enumeration over all elements of this model.voidelementsChanged(Vector aObjects, int aEventMode) Notifies this model that the elements in the specified vector have changed.voidNotifies all listeners that are registered on this model of all the changes that have been collected between the previous notification and now.Returns the objects that must be locked along with this object.getModel(int aIndex) Returns theILcdModelat the given index.intReturns the number of models in this model list.Returns theILcdModelReferencedescribing how the geometry of the elements contained in this model should be interpreted.booleaninsertModelAt(ILcdModel aModel, ILcdFilter aObjectInModelFilter, int aIndex) Inserts the specified model in this model list at the given index.protected booleanisObjectInModel(Object aElement, ILcdModel aModel) Returnstrueif the specified element is contained in the specified model,falseotherwise.intReturns the number ofILcdModelobjects contained in thisILcdModelContainer.voidmodelProduced(TLcdModelProducerEvent aModelProducerEvent) Notifies this ILcdModelProducerListener of a produced model.models()Returns anEnumerationof theILcdModelobjects contained in thisILcdModelContainer.<T> Stream<T> query(ILcdModel.Query aQuery) Provides aStreamof all elements in this model that match the given query.voidremoveAllElements(int aFireEventMode) Removes all elements from this model.voidRemoves all models from this model list.voidremoveElement(Object aObject, int aFireEventMode) Removes the specified element from this model.voidremoveElements(Vector aVector, int aFireEventMode) Removes all of the elements in the specified vector from this model.booleanremoveModel(ILcdModel aModel) Removes anILcdModelfrom thisILcdModelContainer.voidremoveModelContainerListener(ILcdModelContainerListener aModelContainerListener) Removes anILcdModelContainerListenerfrom thisILcdModelContainer.voidremoveModelListener(ILcdModelListener aModelListener) Unregisters the specified model listener so that it no longer receives notifications of model changes on this model.static voidsetClassTraceOn(boolean aClassTraceOn) Deprecated.This method has been deprecated.voidsetModelReference(ILcdModelReference aModelReference) Sets the model reference.Methods inherited from class com.luciad.model.ALcdModel
allElementsChanged, allElementsRemoved, elementAdded, elementRemoved, elementsAdded, elementsRemoved, getModelDescriptor, getModelEncoder, getModelMetadata, initializeTransientValues, isClassTraceOn, isTraceOn, setModelDescriptor, setModelDisposer, setModelEncoder, setModelMetadataFunction, setTraceOnMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.luciad.util.ILcdDisposable
closeMethods inherited from interface com.luciad.model.ILcdModelContainer
getModels
-
Constructor Details
-
TLcdModelList
public TLcdModelList()Constructs new, emptyTLcdModelListlist with aTLcdEditableModelListDescriptor. -
TLcdModelList
Constructs new, emptyTLcdModelListlist with the specifiedILcdModelDescriptor.- Parameters:
aModelDescriptor- The modeldescriptor for this model list
-
-
Method Details
-
setClassTraceOn
public static void setClassTraceOn(boolean aClassTraceOn) Deprecated.This method has been deprecated. It is recommended to use the standard Java logging framework directly.Enables tracing for all instances of this class. If the argument istruethen all log messages are recorded, otherwise only the informative, warning and error messages are recorded.- Parameters:
aClassTraceOn- if true then all log messages are recorded, otherwise only the informative, warning and error messages are recorded.
-
addModel
Adds the specified model to this model list, without a filter.- Specified by:
addModelin interfaceILcdModelContainer- Parameters:
aModel- the model to be added.- Returns:
trueif this collection of models changed as a result of the call- Throws:
NullPointerException- if the specified model isnull.IllegalArgumentException- if the specified model cannot be added to this model list (!canAddModel(aModel).
-
addModel
Adds the specified model to this model list. The specified filter should only accept objects which are in the model.- Parameters:
aModel- the model to be added.aObjectInModelFilter- a filter that only accepts elements from the specified model.- Returns:
trueif this collection of models changed as a result of the call- Throws:
NullPointerException- if the specified model isnull.IllegalArgumentException- if the specified model cannot be added to this model list (!canAddModel(aModel).
-
insertModelAt
Inserts the specified model in this model list at the given index. The specified filter should only accept objects which are in the model.- Parameters:
aModel- the model to be added.aObjectInModelFilter- a filter that only accepts elements from the specified model.aIndex- the index the model should have in the list.- Returns:
trueif this collection of models changed as a result of the call- Throws:
NullPointerException- if the specified model isnull.IllegalArgumentException- if the specified model cannot be added to this model list (!canAddModel(aModel).IndexOutOfBoundsException- ifaIndex < 0 || aIndex > modelCount()
-
canAddModel
Returnstrueif the specified model can be added to this list,falseotherwise. A model can only be added if either:- it has the same model reference as the models already contained in this model list (or explicitly set through
setModelReference(com.luciad.model.ILcdModelReference)) - or this model list does not contain any models yet.
- Parameters:
aModel- the model to be added to this model list.- Returns:
trueif the specified model can be added to this list,falseotherwise.
- it has the same model reference as the models already contained in this model list (or explicitly set through
-
getModelCount
public int getModelCount()Returns the number of models in this model list.- Returns:
- the number of models in this model list.
-
getModel
Returns theILcdModelat the given index.- Specified by:
getModelin interfaceILcdModelContainer- Parameters:
aIndex- a valid index in thisILcdModelContainer.- Returns:
- the
ILcdModelat the given index. - Throws:
IndexOutOfBoundsException- ifaIndex < 0 || aIndex >= getModelCount()
-
removeModel
Removes anILcdModelfrom thisILcdModelContainer.- Specified by:
removeModelin interfaceILcdModelContainer- Parameters:
aModel- the model to be removed.- Returns:
trueif a model was removed as a result of this call- Throws:
NullPointerException- if the specified model isnull.
-
removeAllModels
public void removeAllModels()Removes all models from this model list. An event will fired for every model that has been removed. -
getModelReference
Returns theILcdModelReferencedescribing how the geometry of the elements contained in this model should be interpreted.The model reference is determined in this way:
- If a model reference is set by
setModelReference(com.luciad.model.ILcdModelReference), this will be returned - If not, the model reference of the first model will be returned
- Otherwise,
nullis returned
- Specified by:
getModelReferencein interfaceILcdModel- Overrides:
getModelReferencein classALcdModel- Returns:
- A model reference,
nullif there are no models and no explicit model reference is set - See Also:
- If a model reference is set by
-
setModelReference
Sets the model reference. All models in this model list have to use this reference.If not set, the the model reference of the first model will be used, or
nullif there are no models.- Overrides:
setModelReferencein classALcdModel- Parameters:
aModelReference- A model reference- See Also:
-
query
Description copied from interface:ILcdModelProvides aStreamof all elements in this model that match the given query.The query aspects are applied in this specific order, regardless of the order used to create the query:
- The query
filteris applied first (if any). - The query
sortingis applied second (if any). - The query
limitis applied last (if any).
conditionandsort-bymust never change after creation.Examples:
- model.
query(all()); - model.
query(filter(new TLcdOGCBBoxOperator(...))); - model.
query(filter(eq(property("name"), literal("Leuven"))); - model.
query(all().sorted(comparing(property("population"), DESC)); - model.
query(all().limit(150)); - model.
query(filter(and(bboxCondition, ogcCondition)).sorted(sortByPopulation).limit(120));
A
streamiscloseable, and it depends on the implementation whether the stream has to be closed or not.
You should use this template to ensure proper model locking and stream closing:try (TLcdLockUtil.Lock autoUnlock = TLcdLockUtil.readLock(model); Stream elements = model.query(all())) { elements.forEach(System.err::println); }Model implementations:
By default, this method will invoke
elements(), loop over all elements and apply the filter, sorting and limit.For
Overriding:ILcd2DBoundsIndexedModel, this method will invokeapplyOnInteract2DBounds()if the condition contains a spatial component (either a bounding-box operator, or a spatial operator), and apply the rest of the filter on those elements.Model implementers can override this method to apply the query more efficiently on their back-end format.
For example, if your back-end is a service or database that accepts certain queries, you can override this method and transform the condition into a query on that service.
You can inspect the condition usinginstanceofon the various condition classes.- Specified by:
queryin interfaceILcdModel- Parameters:
aQuery- The query, cannot benull. PassILcdModel.all()if you want all elements.- Returns:
- a stream of the retained model elements
- See Also:
- The query
-
elements
Description copied from interface:ILcdModelReturns an enumeration over all elements of this model. The order in which the elements are enumerated is unspecified by default. -
addElement
Adds the specified element to this model.Models that support this operation may place limitations on what elements may be added to this model. For example, implementations that are based on a spatial indexing structure will require that elements implement
ILcdBounded.When adding an element, the user should make sure that
canAddElement(aElement)holds, and that the element's geometry is expressed in the same model reference as this model. It is generally undefined what happens if an invalid element is added.Implementations of this interface should clearly specify in their documentation any restrictions on what elements may be added. Although it is unspecified what happens if the preconditions are not met, implementations are encouraged to throw meaningful exceptions (for example,
NullPointerException, IllegalArgumentException, ClassCastException, UnsupportedOperationException), whenever possible.This implementation always throws an
UnsupportedOperationException.This implementations always throws an
UnsupportedOperationException. Elements cannot be added directly to this model list, but should be added to the sub models instead.- Specified by:
addElementin interfaceILcdModel- Overrides:
addElementin classALcdModel- Parameters:
aElement- the element to be added to this model.aFireEventMode- the mode for sending out the model change event. This can beFIRE_LATERorNO_EVENT.- Throws:
IllegalArgumentException- See Also:
-
canAddElement
Returnstrueif the specified element can be added to this model,falseotherwise.Note that this method generally does not validate whether the specified element is expressed in the same model reference as this model. It is the responsibility of the user of this model to make sure this precondition is fulfilled when an element is added to this model.
This implementation always returns
false.This implementation always returns
false. Elements cannot be added directly to this model list, but should be added to the sub models instead.- Specified by:
canAddElementin interfaceILcdModel- Overrides:
canAddElementin classALcdModel- Parameters:
aElement- the element to be verified.- Returns:
trueif the specified element can be added to this model,falseotherwise.
-
addElements
Adds all of the elements in the specified vector to this model. Models that support this operation may place limitations on what elements may be added to this model. For example, implementations that are based on a spatial indexing structure will require that elements implementILcdBounded. Implementations of this interface should clearly specify in their documentation any restrictions on what elements may be added.The behavior of this operation is undefined if the specified vector is modified while the operation is in progress.
The specified elements will be added to this model in the order they are specified in the vector. If an element cannot be added, this method will return at the first failure. Succeeding elements won't be added.
Although it is unspecified what happens if the preconditions are not met, implementations are encouraged to throw meaningful exceptions (for example,
NullPointerException, IllegalArgumentException, ClassCastException, UnsupportedOperationException), whenever possible.This implementation iterates over all elements in the specified vector, and calls
addElement(Object, int)for each element to be added, using event modeNO_EVENTif the specified event mode isNO_EVENT,FIRE_LATERotherwise. If the specified event mode isFIRE_NOW,fireCollectedModelChanges()is called afterwards.This implementations always throws an
UnsupportedOperationException. Elements cannot be added directly to this model list, but should be added to the sub models instead.- Specified by:
addElementsin interfaceILcdModel- Overrides:
addElementsin classALcdModel- Parameters:
aElements- the vector of elements to be added to this model.aFireEventMode- the mode for sending the model change events This can beFIRE_LATERorNO_EVENT.- See Also:
-
removeElement
Removes the specified element from this model. If the specified element is not contained in this model, this method has no effect.Although it is unspecified what happens if the preconditions are not met, implementations are encouraged to throw meaningful exceptions (for example,
NullPointerException, IllegalArgumentException, ClassCastException, UnsupportedOperationException), whenever possible.This implementation always throws an
UnsupportedOperationException.This implementations always throws an
UnsupportedOperationException. Elements cannot be removed directly from this model list, but should be removed from the sub models instead.- Specified by:
removeElementin interfaceILcdModel- Overrides:
removeElementin classALcdModel- Parameters:
aObject- the element to be removed from this model.aFireEventMode- the mode for sending out the model change event. This can beFIRE_LATERorNO_EVENT.- Throws:
IllegalArgumentException- See Also:
-
canRemoveElement
Returnstrueif the specified element can be removed from this model,falseotherwise. Note that this method generally does not check whether the specified element is actually contained in this model.This implementation always returns
false.This implementations always returns
false. Elements cannot be removed directly from this model list, but should be removed from the sub models instead.- Specified by:
canRemoveElementin interfaceILcdModel- Overrides:
canRemoveElementin classALcdModel- Parameters:
aObject- the element to be verified.- Returns:
trueif the specified element can be removed from this model,falseotherwise.
-
removeElements
Removes all of the elements in the specified vector from this model. If one of the elements in the specified vector is not contained in this model, this element will be ignored.The behavior of this operation is undefined if the specified vector is modified while the operation is in progress.
The specified elements will be removed from this model in the order they are specified in the vector. If an element cannot be removed, this method will return at the first failure. Succeeding elements won't be removed.
Although it is unspecified what happens if the preconditions are not met, implementations are encouraged to throw meaningful exceptions (for example,
NullPointerException, IllegalArgumentException, ClassCastException, UnsupportedOperationException), whenever possible.This implementation iterates over all elements in the specified vector, and calls
removeElement(Object, int)for each element to be removed, using event modeNO_EVENTif the specified event mode isNO_EVENT,FIRE_LATERotherwise. If the specified event mode isFIRE_NOW,fireCollectedModelChanges()is called afterwards.This implementations always throws an
UnsupportedOperationException. Elements cannot be removed directly from this model list, but should be removed from the sub models instead.- Specified by:
removeElementsin interfaceILcdModel- Overrides:
removeElementsin classALcdModel- Parameters:
aVector- the vector of elements to be removed from this model.aFireEventMode- the mode for sending out the model change event. This can beFIRE_LATERorNO_EVENT.- See Also:
-
removeAllElements
public void removeAllElements(int aFireEventMode) Removes all elements from this model.If an element cannot be removed, this method will return at the first failure. Succeeding elements won't be removed.
Although it is unspecified what happens if the preconditions are not met, implementations are encouraged to throw meaningful exceptions (for example,
NullPointerException, IllegalArgumentException, ClassCastException, UnsupportedOperationException), whenever possible.This implementation iterates over all elements in the model, and calls
removeElement(Object, int)for each element to be removed, using event modeNO_EVENTif the specified event mode isNO_EVENT,FIRE_LATERotherwise. If the specified event mode isFIRE_NOW,fireCollectedModelChanges()is called afterwards.This implementations always throws an
UnsupportedOperationException. Elements cannot be removed directly from this model list, but should be removed from the sub models instead.- Specified by:
removeAllElementsin interfaceILcdModel- Overrides:
removeAllElementsin classALcdModel- Parameters:
aFireEventMode- the mode for sending out the model change event. This can beFIRE_LATERorNO_EVENT.
-
isObjectInModel
Returnstrueif the specified element is contained in the specified model,falseotherwise. If a filter was provided for the specified model, this filter is used to determine whether the element is in the model or not. Otherwise, theTLcdDefaultObjectInModelFilterfilter is used.- Parameters:
aElement- the element to be tested.aModel- the model to be tested.- Returns:
trueif the specified element is contained in the specified model,falseotherwise.
-
elementChanged
Notifies this model that the specified element has changed.This implementation calls
TLcdModelChangedEventSupport#elementChanged(Object, int).This implementation calls
isObjectInModel(Object, ILcdModel)for each model in this model list to determine in which model the object is contained. If a model is found, the change is delegated to this model.- Specified by:
elementChangedin interfaceILcdModel- Overrides:
elementChangedin classALcdModel- Parameters:
aObject- the element that has changed.aEventMode- the mode for sending out the model change event. This can beFIRE_LATERorNO_EVENT.
-
elementsChanged
Notifies this model that the elements in the specified vector have changed.This implementation calls
TLcdModelChangedEventSupport#elementsChanged(java.util.Vector, int).This implementation iterates over all elements in the specified vector, and calls
elementChanged(Object, int)for each element , using event modeNO_EVENTif the specified event mode isNO_EVENT,FIRE_LATERotherwise. If the specified event mode isFIRE_NOW,fireCollectedModelChanges()is called afterwards.- Specified by:
elementsChangedin interfaceILcdModel- Overrides:
elementsChangedin classALcdModel- Parameters:
aObjects- the vector of elements that have changed.aEventMode- the mode for sending out the model change event. This can beFIRE_LATERorNO_EVENT.
-
fireCollectedModelChanges
public void fireCollectedModelChanges()Description copied from class:ALcdModelNotifies all listeners that are registered on this model of all the changes that have been collected between the previous notification and now.This implementation calls
#TLcdModelChangedEventSupport#fireCollectedModelChanges().- Specified by:
fireCollectedModelChangesin interfaceILcdModel- Overrides:
fireCollectedModelChangesin classALcdModel- See Also:
-
addModelListener
Description copied from class:ALcdModelRegisters the specified model listener to receive notifications of model changes on this model.
Model changes are sent out when an element has been added, removed or changed. Model changes can be sent out individually, grouped or silently applied without notifications, depending on the
ILcdFireEventModethat was specified with the change.In case you need to register a listener which keeps a reference to an object with a shorter life-time than this model, you can use a
ALcdWeakModelListenerinstance as model listener.This implementation calls
TLcdModelChangedEventSupport#addModelListener(ILcdModelListener).- Specified by:
addModelListenerin interfaceILcdModel- Overrides:
addModelListenerin classALcdModel- Parameters:
aModelListener- theILcdModelListenerto register on this model.- See Also:
-
removeModelListener
Description copied from class:ALcdModelUnregisters the specified model listener so that it no longer receives notifications of model changes on this model.This implementation calls
TLcdModelChangedEventSupport#removeModelListener(ILcdModelListener).- Specified by:
removeModelListenerin interfaceILcdModel- Overrides:
removeModelListenerin classALcdModel- Parameters:
aModelListener- theILcdModelListenerto remove.- See Also:
-
dispose
public void dispose()Description copied from class:ALcdModelDisposes of this model and allows it to release any system resources that it is holding. The result of calling any other method (other thanfinalize) on this model subsequent to a call to this method is undefined.When a model disposer has been provided it is called, otherwise this method does nothing. When overriding this method it is recommended to call
super.dispose(). -
modelCount
public int modelCount()Description copied from interface:ILcdModelContainerReturns the number ofILcdModelobjects contained in thisILcdModelContainer.- Specified by:
modelCountin interfaceILcdModelContainer- Returns:
- the number of
ILcdModelobjects contained in thisILcdModelContainer.
-
models
Description copied from interface:ILcdModelContainerReturns anEnumerationof theILcdModelobjects contained in thisILcdModelContainer.- Specified by:
modelsin interfaceILcdModelContainer- Returns:
- an
Enumerationof theILcdModelobjects contained in thisILcdModelContainer.
-
getDependentObjects
Description copied from interface:ILcdLockDependentReturns the objects that must be locked along with this object.TLcdLockUtilfirst locks all objects returned by this method before locking this object.- Specified by:
getDependentObjectsin interfaceILcdLockDependent- Returns:
- the objects that must be locked along with this object.
-
addModelContainerListener
Description copied from interface:ILcdModelContainerAdds anILcdModelContainerListenerto thisILcdModelContainer.- Specified by:
addModelContainerListenerin interfaceILcdModelContainer- Parameters:
aModelContainerListener- the listener to be added.- See Also:
-
removeModelContainerListener
Description copied from interface:ILcdModelContainerRemoves anILcdModelContainerListenerfrom thisILcdModelContainer.- Specified by:
removeModelContainerListenerin interfaceILcdModelContainer- Parameters:
aModelContainerListener- the listener to be removed.- See Also:
-
modelProduced
Description copied from interface:ILcdModelProducerListenerNotifies this ILcdModelProducerListener of a produced model.- Specified by:
modelProducedin interfaceILcdModelProducerListener- Parameters:
aModelProducerEvent- the event describing the changes to aILcdModelProducer.
-