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
fModelEventSupport
Fields inherited from interface com.luciad.model.ILcdModel
FIRE_LATER, FIRE_NOW, NO_EVENT
-
Constructor Summary
ConstructorDescriptionConstructs new, emptyTLcdModelList
list with aTLcdEditableModelListDescriptor
.TLcdModelList
(ILcdModelDescriptor aModelDescriptor) Constructs new, emptyTLcdModelList
list with the specifiedILcdModelDescriptor
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addElement
(Object aElement, int aFireEventMode) Adds the specified element to this model.void
addElements
(Vector aElements, int aFireEventMode) Adds all of the elements in the specified vector to this model.boolean
Adds the specified model to this model list, without a filter.boolean
addModel
(ILcdModel aModel, ILcdFilter aObjectInModelFilter) Adds the specified model to this model list.void
addModelContainerListener
(ILcdModelContainerListener aModelContainerListener) Adds anILcdModelContainerListener
to thisILcdModelContainer
.void
addModelListener
(ILcdModelListener aModelListener) Registers the specified model listener to receive notifications of model changes on this model.boolean
canAddElement
(Object aElement) Returnstrue
if the specified element can be added to this model,false
otherwise.boolean
canAddModel
(ILcdModel aModel) Returnstrue
if the specified model can be added to this list,false
otherwise.boolean
canRemoveElement
(Object aObject) Returnstrue
if the specified element can be removed from this model,false
otherwise.void
dispose()
Disposes of this model and allows it to release any system resources that it is holding.void
elementChanged
(Object aObject, int aEventMode) Notifies this model that the specified element has changed.elements()
Returns an enumeration over all elements of this model.void
elementsChanged
(Vector aObjects, int aEventMode) Notifies this model that the elements in the specified vector have changed.void
Notifies 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 theILcdModel
at the given index.int
Returns the number of models in this model list.Returns theILcdModelReference
describing how the geometry of the elements contained in this model should be interpreted.boolean
insertModelAt
(ILcdModel aModel, ILcdFilter aObjectInModelFilter, int aIndex) Inserts the specified model in this model list at the given index.protected boolean
isObjectInModel
(Object aElement, ILcdModel aModel) Returnstrue
if the specified element is contained in the specified model,false
otherwise.int
Returns the number ofILcdModel
objects contained in thisILcdModelContainer
.void
modelProduced
(TLcdModelProducerEvent aModelProducerEvent) Notifies this ILcdModelProducerListener of a produced model.models()
Returns anEnumeration
of theILcdModel
objects contained in thisILcdModelContainer
.<T> Stream
<T> query
(ILcdModel.Query aQuery) Provides aStream
of all elements in this model that match the given query.void
removeAllElements
(int aFireEventMode) Removes all elements from this model.void
Removes all models from this model list.void
removeElement
(Object aObject, int aFireEventMode) Removes the specified element from this model.void
removeElements
(Vector aVector, int aFireEventMode) Removes all of the elements in the specified vector from this model.boolean
removeModel
(ILcdModel aModel) Removes anILcdModel
from thisILcdModelContainer
.void
removeModelContainerListener
(ILcdModelContainerListener aModelContainerListener) Removes anILcdModelContainerListener
from thisILcdModelContainer
.void
removeModelListener
(ILcdModelListener aModelListener) Unregisters the specified model listener so that it no longer receives notifications of model changes on this model.static void
setClassTraceOn
(boolean aClassTraceOn) Deprecated.This method has been deprecated.void
setModelReference
(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, setTraceOn
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.luciad.util.ILcdDisposable
close
Methods inherited from interface com.luciad.model.ILcdModelContainer
getModels
-
Constructor Details
-
TLcdModelList
public TLcdModelList()Constructs new, emptyTLcdModelList
list with aTLcdEditableModelListDescriptor
. -
TLcdModelList
Constructs new, emptyTLcdModelList
list 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 istrue
then 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:
addModel
in interfaceILcdModelContainer
- Parameters:
aModel
- the model to be added.- Returns:
true
if 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:
true
if 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:
true
if 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
Returnstrue
if the specified model can be added to this list,false
otherwise. 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:
true
if the specified model can be added to this list,false
otherwise.
- 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 theILcdModel
at the given index.- Specified by:
getModel
in interfaceILcdModelContainer
- Parameters:
aIndex
- a valid index in thisILcdModelContainer
.- Returns:
- the
ILcdModel
at the given index. - Throws:
IndexOutOfBoundsException
- ifaIndex < 0 || aIndex >= getModelCount()
-
removeModel
Removes anILcdModel
from thisILcdModelContainer
.- Specified by:
removeModel
in interfaceILcdModelContainer
- Parameters:
aModel
- the model to be removed.- Returns:
true
if 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 theILcdModelReference
describing 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,
null
is returned
- Specified by:
getModelReference
in interfaceILcdModel
- Overrides:
getModelReference
in classALcdModel
- Returns:
- A model reference,
null
if 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
null
if there are no models.- Overrides:
setModelReference
in classALcdModel
- Parameters:
aModelReference
- A model reference- See Also:
-
query
Description copied from interface:ILcdModel
Provides aStream
of 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
filter
is applied first (if any). - The query
sorting
is applied second (if any). - The query
limit
is applied last (if any).
condition
andsort-by
must 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
stream
iscloseable
, 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 usinginstanceof
on the various condition classes.- Specified by:
query
in 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:ILcdModel
Returns 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:
addElement
in interfaceILcdModel
- Overrides:
addElement
in classALcdModel
- Parameters:
aElement
- the element to be added to this model.aFireEventMode
- the mode for sending out the model change event. This can beFIRE_LATER
orNO_EVENT
.- Throws:
IllegalArgumentException
- See Also:
-
canAddElement
Returnstrue
if the specified element can be added to this model,false
otherwise.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:
canAddElement
in interfaceILcdModel
- Overrides:
canAddElement
in classALcdModel
- Parameters:
aElement
- the element to be verified.- Returns:
true
if the specified element can be added to this model,false
otherwise.
-
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_EVENT
if the specified event mode isNO_EVENT
,FIRE_LATER
otherwise. 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:
addElements
in interfaceILcdModel
- Overrides:
addElements
in 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_LATER
orNO_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:
removeElement
in interfaceILcdModel
- Overrides:
removeElement
in classALcdModel
- Parameters:
aObject
- the element to be removed from this model.aFireEventMode
- the mode for sending out the model change event. This can beFIRE_LATER
orNO_EVENT
.- Throws:
IllegalArgumentException
- See Also:
-
canRemoveElement
Returnstrue
if the specified element can be removed from this model,false
otherwise. 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:
canRemoveElement
in interfaceILcdModel
- Overrides:
canRemoveElement
in classALcdModel
- Parameters:
aObject
- the element to be verified.- Returns:
true
if the specified element can be removed from this model,false
otherwise.
-
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_EVENT
if the specified event mode isNO_EVENT
,FIRE_LATER
otherwise. 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:
removeElements
in interfaceILcdModel
- Overrides:
removeElements
in 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_LATER
orNO_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_EVENT
if the specified event mode isNO_EVENT
,FIRE_LATER
otherwise. 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:
removeAllElements
in interfaceILcdModel
- Overrides:
removeAllElements
in classALcdModel
- Parameters:
aFireEventMode
- the mode for sending out the model change event. This can beFIRE_LATER
orNO_EVENT
.
-
isObjectInModel
Returnstrue
if the specified element is contained in the specified model,false
otherwise. 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, theTLcdDefaultObjectInModelFilter
filter is used.- Parameters:
aElement
- the element to be tested.aModel
- the model to be tested.- Returns:
true
if the specified element is contained in the specified model,false
otherwise.
-
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:
elementChanged
in interfaceILcdModel
- Overrides:
elementChanged
in classALcdModel
- Parameters:
aObject
- the element that has changed.aEventMode
- the mode for sending out the model change event. This can beFIRE_LATER
orNO_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_EVENT
if the specified event mode isNO_EVENT
,FIRE_LATER
otherwise. If the specified event mode isFIRE_NOW
,fireCollectedModelChanges()
is called afterwards.- Specified by:
elementsChanged
in interfaceILcdModel
- Overrides:
elementsChanged
in classALcdModel
- Parameters:
aObjects
- the vector of elements that have changed.aEventMode
- the mode for sending out the model change event. This can beFIRE_LATER
orNO_EVENT
.
-
fireCollectedModelChanges
public void fireCollectedModelChanges()Description copied from class:ALcdModel
Notifies 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:
fireCollectedModelChanges
in interfaceILcdModel
- Overrides:
fireCollectedModelChanges
in classALcdModel
- See Also:
-
addModelListener
Description copied from class:ALcdModel
Registers 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
ILcdFireEventMode
that 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
ALcdWeakModelListener
instance as model listener.This implementation calls
TLcdModelChangedEventSupport#addModelListener(ILcdModelListener)
.- Specified by:
addModelListener
in interfaceILcdModel
- Overrides:
addModelListener
in classALcdModel
- Parameters:
aModelListener
- theILcdModelListener
to register on this model.- See Also:
-
removeModelListener
Description copied from class:ALcdModel
Unregisters 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:
removeModelListener
in interfaceILcdModel
- Overrides:
removeModelListener
in classALcdModel
- Parameters:
aModelListener
- theILcdModelListener
to remove.- See Also:
-
dispose
public void dispose()Description copied from class:ALcdModel
Disposes 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:ILcdModelContainer
Returns the number ofILcdModel
objects contained in thisILcdModelContainer
.- Specified by:
modelCount
in interfaceILcdModelContainer
- Returns:
- the number of
ILcdModel
objects contained in thisILcdModelContainer
.
-
models
Description copied from interface:ILcdModelContainer
Returns anEnumeration
of theILcdModel
objects contained in thisILcdModelContainer
.- Specified by:
models
in interfaceILcdModelContainer
- Returns:
- an
Enumeration
of theILcdModel
objects contained in thisILcdModelContainer
.
-
getDependentObjects
Description copied from interface:ILcdLockDependent
Returns the objects that must be locked along with this object.TLcdLockUtil
first locks all objects returned by this method before locking this object.- Specified by:
getDependentObjects
in interfaceILcdLockDependent
- Returns:
- the objects that must be locked along with this object.
-
addModelContainerListener
Description copied from interface:ILcdModelContainer
Adds anILcdModelContainerListener
to thisILcdModelContainer
.- Specified by:
addModelContainerListener
in interfaceILcdModelContainer
- Parameters:
aModelContainerListener
- the listener to be added.- See Also:
-
removeModelContainerListener
Description copied from interface:ILcdModelContainer
Removes anILcdModelContainerListener
from thisILcdModelContainer
.- Specified by:
removeModelContainerListener
in interfaceILcdModelContainer
- Parameters:
aModelContainerListener
- the listener to be removed.- See Also:
-
modelProduced
Description copied from interface:ILcdModelProducerListener
Notifies this ILcdModelProducerListener of a produced model.- Specified by:
modelProduced
in interfaceILcdModelProducerListener
- Parameters:
aModelProducerEvent
- the event describing the changes to aILcdModelProducer
.
-