public class TLcdModelList extends ALcdModel implements ILcdModelContainer, ILcdLockDependent
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
.
ILcdModel.Query
fModelEventSupport
FIRE_LATER, FIRE_NOW, NO_EVENT
Constructor and Description |
---|
TLcdModelList()
Constructs new, empty
TLcdModelList list with a TLcdEditableModelListDescriptor . |
TLcdModelList(ILcdModelDescriptor aModelDescriptor)
Constructs new, empty
TLcdModelList list with the specified ILcdModelDescriptor . |
Modifier and Type | Method and Description |
---|---|
void |
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 |
addModel(ILcdModel aModel)
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 an
ILcdModelContainerListener to this ILcdModelContainer . |
void |
addModelListener(ILcdModelListener aModelListener)
Registers the specified model listener to receive notifications of model changes on this model.
|
boolean |
canAddElement(Object aElement)
Returns
true if the specified element can be added to this model, false otherwise. |
boolean |
canAddModel(ILcdModel aModel)
Returns
true if the specified model can be added to this list, false otherwise. |
boolean |
canRemoveElement(Object aObject)
Returns
true 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.
|
Enumeration |
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 |
fireCollectedModelChanges()
Notifies all listeners that are registered on this model of all the changes that have been collected between the
previous notification and now.
|
List<Object> |
getDependentObjects()
Returns the objects that must be locked along with this object.
|
ILcdModel |
getModel(int aIndex)
Returns the
ILcdModel at the given index. |
int |
getModelCount()
Returns the number of models in this model list.
|
ILcdModelReference |
getModelReference()
Returns the
ILcdModelReference 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)
Returns
true if the specified element is contained in the specified model, false otherwise. |
int |
modelCount()
Returns the number of
ILcdModel objects contained in this
ILcdModelContainer . |
void |
modelProduced(TLcdModelProducerEvent aModelProducerEvent)
Notifies this ILcdModelProducerListener of a produced model.
|
Enumeration |
models()
Returns an
Enumeration of the ILcdModel objects contained in
this ILcdModelContainer . |
<T> Stream<T> |
query(ILcdModel.Query aQuery)
Provides a
Stream of all elements in this model that match the given query. |
void |
removeAllElements(int aFireEventMode)
Removes all elements from this model.
|
void |
removeAllModels()
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 an
ILcdModel from this ILcdModelContainer . |
void |
removeModelContainerListener(ILcdModelContainerListener aModelContainerListener)
Removes an
ILcdModelContainerListener from this ILcdModelContainer . |
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. It is recommended to use the
standard Java logging framework directly.
|
void |
setModelReference(ILcdModelReference aModelReference)
Sets the model reference.
|
allElementsChanged, allElementsRemoved, elementAdded, elementRemoved, elementsAdded, elementsRemoved, getModelDescriptor, getModelEncoder, getModelMetadata, initializeTransientValues, isClassTraceOn, isTraceOn, setModelDescriptor, setModelDisposer, setModelEncoder, setModelMetadataFunction, setTraceOn
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getModels
close
public TLcdModelList()
TLcdModelList
list with a TLcdEditableModelListDescriptor
.public TLcdModelList(ILcdModelDescriptor aModelDescriptor)
TLcdModelList
list with the specified ILcdModelDescriptor
.aModelDescriptor
- The modeldescriptor for this model listpublic static void setClassTraceOn(boolean aClassTraceOn)
true
then all log messages are recorded, otherwise only
the informative, warning and error messages are recorded.aClassTraceOn
- if true then all log messages are recorded,
otherwise only the informative, warning and error messages are recorded.public boolean addModel(ILcdModel aModel)
addModel
in interface ILcdModelContainer
aModel
- the model to be added.true
if this collection of models changed as a result of the callNullPointerException
- if the specified model is null
.IllegalArgumentException
- if the specified model cannot be added to this model list
(!canAddModel(aModel)
.public boolean addModel(ILcdModel aModel, ILcdFilter aObjectInModelFilter)
aModel
- the model to be added.aObjectInModelFilter
- a filter that only accepts elements from the specified model.true
if this collection of models changed as a result of the callNullPointerException
- if the specified model is null
.IllegalArgumentException
- if the specified model cannot be added to this model list
(!canAddModel(aModel)
.public boolean insertModelAt(ILcdModel aModel, ILcdFilter aObjectInModelFilter, int aIndex)
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.true
if this collection of models changed as a result of the callNullPointerException
- if the specified model is null
.IllegalArgumentException
- if the specified model cannot be added to this model list
(!canAddModel(aModel)
.IndexOutOfBoundsException
- if aIndex < 0 || aIndex > modelCount()
public boolean canAddModel(ILcdModel aModel)
true
if the specified model can be added to this list, false
otherwise.
A model can only be added if either:
setModelReference(com.luciad.model.ILcdModelReference)
)aModel
- the model to be added to this model list.true
if the specified model can be added to this list, false
otherwise.public int getModelCount()
public ILcdModel getModel(int aIndex)
ILcdModel
at the given index.getModel
in interface ILcdModelContainer
aIndex
- a valid index in this ILcdModelContainer
.ILcdModel
at the given index.IndexOutOfBoundsException
- if aIndex < 0 || aIndex >= getModelCount()
public boolean removeModel(ILcdModel aModel)
ILcdModel
from this ILcdModelContainer
.removeModel
in interface ILcdModelContainer
aModel
- the model to be removed.true
if a model was removed as a result of this callNullPointerException
- if the specified model is null
.public void removeAllModels()
public ILcdModelReference getModelReference()
ILcdModelReference
describing how the geometry of the elements contained in this
model should be interpreted.
The model reference is determined in this way:
setModelReference(com.luciad.model.ILcdModelReference)
, this will be returnednull
is returnedgetModelReference
in interface ILcdModel
getModelReference
in class ALcdModel
null
if there are no models and no explicit model reference is setALcdModel.setModelReference(ILcdModelReference)
public void setModelReference(ILcdModelReference aModelReference)
If not set, the the model reference of the first model will be used, or null
if
there are no models.
setModelReference
in class ALcdModel
aModelReference
- A model referencegetModelReference()
public <T> Stream<T> query(ILcdModel.Query aQuery)
ILcdModel
Stream
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:
filter
is applied first (if any).sorting
is applied second (if any).limit
is applied last (if any).condition
and sort-by
must never change after creation.
Examples:
query
(all
());query
(filter
(new TLcdOGCBBoxOperator(...)));query
(filter
(eq(property("name"), literal("Leuven")));query
(all
().sorted
(comparing(property("population"), DESC));query
(all
().limit
(150));query
(filter
(and(bboxCondition, ogcCondition)).sorted
(sortByPopulation).limit
(120));
A stream
is closeable
, 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 ILcd2DBoundsIndexedModel
, this method will invoke applyOnInteract2DBounds()
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 using instanceof
on the various condition classes.
query
in interface ILcdModel
aQuery
- The query, cannot be null
. Pass ILcdModel.all()
if you want all elements.TLcdOGCFilterFactory to easily create conditions
,
TLcdOGCSortBy "comparing" and "thenComparing" factory methods to easily create sorting orders
public Enumeration elements()
ILcdModel
public void addElement(Object aElement, int aFireEventMode) throws IllegalArgumentException
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.
addElement
in interface ILcdModel
addElement
in class ALcdModel
aElement
- the element to be added to this model.aFireEventMode
- the mode for sending out the model change event. This can be FIRE_LATER
or NO_EVENT
.IllegalArgumentException
ILcdModel.canAddElement(Object)
public boolean canAddElement(Object aElement)
true
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.
canAddElement
in interface ILcdModel
canAddElement
in class ALcdModel
aElement
- the element to be verified.true
if the specified element can be added to this model, false
otherwise.public void addElements(Vector aElements, int aFireEventMode)
ILcdBounded
. 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 mode NO_EVENT
if the
specified event mode is NO_EVENT
, FIRE_LATER
otherwise.
If the specified event mode is FIRE_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.
addElements
in interface ILcdModel
addElements
in class ALcdModel
aElements
- the vector of elements to be added to this model.aFireEventMode
- the mode for sending the model change events This can be FIRE_LATER
or NO_EVENT
.ILcdModel.canAddElement(Object)
public void removeElement(Object aObject, int aFireEventMode) throws IllegalArgumentException
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.
removeElement
in interface ILcdModel
removeElement
in class ALcdModel
aObject
- the element to be removed from this model.aFireEventMode
- the mode for sending out the model change event. This can be FIRE_LATER
or NO_EVENT
.IllegalArgumentException
ILcdModel.canRemoveElement(Object)
public boolean canRemoveElement(Object aObject)
true
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.
canRemoveElement
in interface ILcdModel
canRemoveElement
in class ALcdModel
aObject
- the element to be verified.true
if the specified element can be removed from this model, false
otherwise.public void removeElements(Vector aVector, int aFireEventMode)
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 mode NO_EVENT
if the
specified event mode is NO_EVENT
, FIRE_LATER
otherwise.
If the specified event mode is FIRE_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.
removeElements
in interface ILcdModel
removeElements
in class ALcdModel
aVector
- the vector of elements to be removed from this model.aFireEventMode
- the mode for sending out the model change event. This can be FIRE_LATER
or NO_EVENT
.ILcdModel.canRemoveElement(Object)
public void removeAllElements(int aFireEventMode)
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 mode NO_EVENT
if the
specified event mode is NO_EVENT
, FIRE_LATER
otherwise.
If the specified event mode is FIRE_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.
removeAllElements
in interface ILcdModel
removeAllElements
in class ALcdModel
aFireEventMode
- the mode for sending out the model change event. This can be FIRE_LATER
or NO_EVENT
.protected boolean isObjectInModel(Object aElement, ILcdModel aModel)
true
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, the TLcdDefaultObjectInModelFilter
filter is used.aElement
- the element to be tested.aModel
- the model to be tested.true
if the specified element is contained in the specified model, false
otherwise.public void elementChanged(Object aObject, int aEventMode)
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.
elementChanged
in interface ILcdModel
elementChanged
in class ALcdModel
aObject
- the element that has changed.aEventMode
- the mode for sending out the model change event. This can be FIRE_LATER
or NO_EVENT
.public void elementsChanged(Vector aObjects, int aEventMode)
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 mode NO_EVENT
if the specified
event mode is NO_EVENT
, FIRE_LATER
otherwise.
If the specified event mode is FIRE_NOW
, fireCollectedModelChanges()
is called afterwards.
elementsChanged
in interface ILcdModel
elementsChanged
in class ALcdModel
aObjects
- the vector of elements that have changed.aEventMode
- the mode for sending out the model change event. This can be FIRE_LATER
or NO_EVENT
.public void fireCollectedModelChanges()
ALcdModel
This implementation calls #TLcdModelChangedEventSupport#fireCollectedModelChanges()
.
fireCollectedModelChanges
in interface ILcdModel
fireCollectedModelChanges
in class ALcdModel
ILcdModelListener.modelChanged(TLcdModelChangedEvent)
public void addModelListener(ILcdModelListener aModelListener)
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)
.
addModelListener
in interface ILcdModel
addModelListener
in class ALcdModel
aModelListener
- the ILcdModelListener
to register on this model.ILcdModel.removeModelListener(com.luciad.model.ILcdModelListener)
,
ILcdModelListener
public void removeModelListener(ILcdModelListener aModelListener)
ALcdModel
This implementation calls TLcdModelChangedEventSupport#removeModelListener(ILcdModelListener)
.
removeModelListener
in interface ILcdModel
removeModelListener
in class ALcdModel
aModelListener
- the ILcdModelListener
to remove.ILcdModel.addModelListener(com.luciad.model.ILcdModelListener)
,
ILcdModelListener
public void dispose()
ALcdModel
finalize
) 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()
.
dispose
in interface ILcdModel
dispose
in interface ILcdDisposable
dispose
in class ALcdModel
ALcdModel.setModelDisposer(Consumer)
public int modelCount()
ILcdModelContainer
ILcdModel
objects contained in this
ILcdModelContainer
.modelCount
in interface ILcdModelContainer
ILcdModel
objects contained in this
ILcdModelContainer
.public Enumeration models()
ILcdModelContainer
Enumeration
of the ILcdModel
objects contained in
this ILcdModelContainer
.models
in interface ILcdModelContainer
Enumeration
of the ILcdModel
objects contained in
this ILcdModelContainer
.public List<Object> getDependentObjects()
ILcdLockDependent
TLcdLockUtil
first locks all objects
returned by this method before locking this object.getDependentObjects
in interface ILcdLockDependent
public void addModelContainerListener(ILcdModelContainerListener aModelContainerListener)
ILcdModelContainer
ILcdModelContainerListener
to this ILcdModelContainer
.addModelContainerListener
in interface ILcdModelContainer
aModelContainerListener
- the listener to be added.ILcdModelContainer.removeModelContainerListener(com.luciad.model.ILcdModelContainerListener)
public void removeModelContainerListener(ILcdModelContainerListener aModelContainerListener)
ILcdModelContainer
ILcdModelContainerListener
from this ILcdModelContainer
.removeModelContainerListener
in interface ILcdModelContainer
aModelContainerListener
- the listener to be removed.ILcdModelContainer.addModelContainerListener(com.luciad.model.ILcdModelContainerListener)
public void modelProduced(TLcdModelProducerEvent aModelProducerEvent)
ILcdModelProducerListener
modelProduced
in interface ILcdModelProducerListener
aModelProducerEvent
- the event describing the changes to a ILcdModelProducer
.