Interface ILcdModel
- All Superinterfaces:
AutoCloseable,ILcdDisposable,Serializable
- All Known Subinterfaces:
ILcd2DBoundsIndexedModel,ILcdDataObjectIndexedModel,ILcdFeatureIndexedAnd2DBoundsIndexedModel,ILcdFeatureIndexedModel,ILcdIntegerIndexedModel,ILcdMagneticNorthModel,ILcdModelTreeNode,ILcdMultiDimensionalModel
- All Known Implementing Classes:
ALcdModel,ALcdTransformingModel,ALfnTileStoreModel,TLcd2DBoundsIndexedModel,TLcd2DBoundsIndexedModelList,TLcd2DBoundsIndexedModelTreeNode,TLcd2DRegularTiledBoundsIndexedModel,TLcdAIXM51AbstractAIXMMessage,TLcdASTERIXFilteredModel,TLcdDatabaseModel,TLcdDatabaseReadOnlyModel,TLcdDataObjectIndexedAnd2DBoundsIndexedModel,TLcdDataObjectIndexedVectorModel,TLcdFeatureIndexedAnd2DBoundsIndexedModel,TLcdFeatureIndexedVectorModel,TLcdGML2AbstractFeatureCollection,TLcdGML31AbstractFeatureCollection,TLcdGML31DynamicFeatureCollection,TLcdGML31FeatureCollection,TLcdGML31Model,TLcdGML32AbstractFeatureCollection,TLcdGML32FeatureCollection,TLcdGML32Model,TLcdKML22AbstractContainer,TLcdKML22Document,TLcdKML22DynamicModel,TLcdKML22Folder,TLcdKML22Kml,TLcdKML22NetworkLink,TLcdKML22RenderableModel,TLcdMagneticNorthModel,TLcdModelList,TLcdModelTreeNode,TLcdMultilevel2DBoundsIndexedModel,TLcdMultilevelGridCoordinateModel,TLcdNetCDFFilteredModel,TLcdNVG15Model,TLcdNVG20FilteredModel,TLcdNVG20Model,TLcdRegularTiled2DBoundsIndexedModel,TLcdS57DepthAreaEdgeModel,TLcdSoft2DBoundsIndexedModel,TLcdTiled2DBoundsIndexedModel,TLcdTrackModel,TLcdVectorModel,TLcdWCSProxyModel,TLcdWFSProxyModel
Models can be created and populated by hand, or they can be created by an ILcdModelDecoder from a data source.
ILcdModel provides basic methods for retrieving, adding and removing elements. The basic method for
retrieving is sequential. The identities of the elements are determined by the equals() method.
Model reference
A model has anILcdModelReference associated with it. This model reference defines the common coordinate
system in which the geometry of its elements is expressed. All elements of a model should thus share the same
coordinate system.
Model descriptor
A model also has anILcdModelDescriptor associated with it. This model descriptor provides meta information
about the model and information common to all elements contained in this model. The actual contents of this
information may vary from model to model.
Accessing data
You can typically access data in a model on any thread, but you must take aread lock:
try (TLcdLockUtil.Lock lock = TLcdLockUtil.readLock(model);
Stream<Object> elements = model.query(all())) {
elements.forEach(consumer);
}
query, elements
or applyOnInteract2DBounds.
This also applies to accessing element internals, such as looping over points of a polyline.
Consult the javadoc of your specific model implementation for additional considerations.
Changing data
There are various methods toadd and remove elements.
External changes to the elements of the model (for example, the bounds of an element) have to be reported to the
model through elementChanged, so it can update its internal structures and send
out events to its listeners.
When you do changes to the model or one of its elements, you must take a write lock:
try (TLcdLockUtil.Lock lock = TLcdLockUtil.writeLock(model)) {
model.addElement(element, FIRE_LATER);
} finally {
model.fireCollectedModelChanges();
}
One or more ILcdModelListener objects can be registered to a model, to be notified of changes in the model.
The model will notify its listeners whenever one or more elements are added, removed and/or changed.
These events can be sent individually, grouped or silently suppressed,depending on the
event mode that was specified with the change. Two modes for firing events are supported:
FIRE_LATER: applies the change but delays the model change event. You have to flush the events throughfireCollectedModelChanges()outside the write lock. This is the recommended mode.NO_EVENT: applies the change but doesn't send or delay the model change event. This can be used if the model being constructed and is not yet in a layer.
The use of ILcdFireEventMode constants for specifying event modes in the methods of this interface has been
deprecated in favor of the constants that are defined within this interface.
See ALcdModel for info on debugging missing or wrong model locks.
Extensions
Several extensions of this interface provide additional methods targeted to specific operations (spatial access, indexed access, ...). In addition, a number of implementations ofILcdModel and its
extensions are also provided in this package, each optimized for different types of usages.
Choosing the right interface or implementation of ILcdModel is important for achieving proper performance.
See the package documentation for an overview of all available extension interfaces and
implementations.
Additional restrictions
Null values are not accepted as elements in a model. Implementations of this interface may impose additional constraints on what elements they may contain. For example, implementations that are based on a spatial indexing structure will often require that elements implementILcdBounded. Implementations should clearly specify in
their documentation any restrictions on the elements they may contain. The methods canAddElement(Object)
and canRemoveElement(Object) reflect these constraints programmatically.- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intStore the event for later.static final intDeprecated.static final intDon't signal the event at all. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddElement(Object aElement, int aEventMode) Adds the specified element to this model.voidaddElements(Vector aElements, int aEventMode) Adds all of the elements in the specified vector to this model.voidaddModelListener(ILcdModelListener aModelListener) Registers the specified model listener to receive notifications of model changes on this model.static ILcdModel.Queryall()Create a query indicating that all elements should be retrieved.booleancanAddElement(Object aElement) Returnstrueif the specified element can be added to this model,falseotherwise.booleancanRemoveElement(Object aElement) 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 aElement, int aEventMode) Notifies this model that the specified element has changed.elements()Returns an enumeration over all elements of this model.voidelementsChanged(Vector aElements, int aEventMode) Notifies this model that the elements in the specified vector have changed.static ILcdModel.Queryfilter(ILcdOGCCondition aCondition) Create a query with the given condition to filter on.voidNotifies all listeners that are registered on this model of all the changes that have been collected between the previous notification and now.Returns theILcdModelDescriptorproviding meta information about this model and its elements.Returns, if available, a model encoder that is capable of encoding this model, (encoder.canEncode(this)),nullotherwise.default TLcdModelMetadataCollects and returns metadata about the model.Returns theILcdModelReferencedescribing how the geometry of the elements contained in this model should be interpreted.default <T> Stream<T> query(ILcdModel.Query aQuery) Provides aStreamof all elements in this model that match the given query.voidremoveAllElements(int aEventMode) Removes all elements from this model.voidremoveElement(Object aElement, int aEventMode) Removes the specified element from this model.voidremoveElements(Vector aElements, int aEventMode) Removes all of the elements in the specified vector from this model.voidremoveModelListener(ILcdModelListener aModelListener) Unregisters the specified model listener so that it no longer receives notifications of model changes on this model.Methods inherited from interface com.luciad.util.ILcdDisposable
close
-
Field Details
-
FIRE_NOW
static final int FIRE_NOWDeprecated.Don't use this event mode always useFIRE_LATERorNO_EVENT. If the model isn't used yet outside the code block you can useNO_EVENT. Otherwise take aTLcdLockUtil.writeLock(Object), useFIRE_LATERand finally callfireCollectedModelChanges()For more information on how to work with models see the tutorialSignal the event immediately.This mode is not recommended, as the event happens within the write lock. Use
FIRE_LATERinstead.This constant has the same value as
ILcdFireEventMode.FIRE_NOW, for backwards compatibility.- See Also:
-
FIRE_LATER
static final int FIRE_LATERStore the event for later.Use
fireCollectedModelChanges()to flush any events that have been collected this way but not yet sent. Note that you have to usefireCollectedModelChanges()outside thewrite lock.This constant has the same value as
ILcdFireEventMode.FIRE_LATER, for backwards compatibility.- See Also:
-
NO_EVENT
static final int NO_EVENTDon't signal the event at all.Use this only if the model is not yet in use by another component. For example it is being built and not yet in a layer.
This constant has the same value as
ILcdFireEventMode.NO_EVENT, for backwards compatibility.- See Also:
-
-
Method Details
-
getModelReference
ILcdModelReference getModelReference()Returns theILcdModelReferencedescribing how the geometry of the elements contained in this model should be interpreted.- Returns:
- the
ILcdModelReferenceof thisILcdModel.
-
getModelDescriptor
ILcdModelDescriptor getModelDescriptor()Returns theILcdModelDescriptorproviding meta information about this model and its elements.- Returns:
- the
ILcdModelDescriptorof thisILcdModel. Should not benull.
-
getModelMetadata
Collects and returns metadata about the model. Note that this method does not necessarily return the sameTLcdModelMetadatainstance every time it is called. The default implementation usesTLcdModelMetadata.Builder.fromModel(com.luciad.model.ILcdModel).Implementations can
recreateorextendthe metadata. The following example adds a data category and source file mime type:public TLcdModelMetadata getModelMetadata() { String source = this.getModelDescriptor().getSourceName(); return this.getModelMetadata().asBuilder() .entryPoint(new TLcdModelMetadata.Source(source, MIME_XML)) .addDataCategory(TLcdModelMetadata.DataCategory.VECTOR) .build(); }- Returns:
- Metadata about the model.
- Since:
- 2018.0
-
getModelEncoder
ILcdModelEncoder getModelEncoder()Returns, if available, a model encoder that is capable of encoding this model, (encoder.canEncode(this)),nullotherwise.- Returns:
- a model encoder that is capable of encoding this model if available,
nullotherwise.
-
elements
Enumeration elements()Returns an enumeration over all elements of this model. The order in which the elements are enumerated is unspecified by default.- Returns:
- an enumeration over all elements of this model.
-
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.- Parameters:
aElement- the element to be added to this model.aEventMode- the mode for sending out the model change event. This can beFIRE_LATERorNO_EVENT.- See Also:
- Preconditions:
- The specified element should be expressed in the model reference of this model., It should be possible to add the specified element (
canAddElement(aElement)).
-
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.
- 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.- Parameters:
aElements- the vector of elements to be added to this model.aEventMode- the mode for sending the model change events This can beFIRE_LATERorNO_EVENT.- See Also:
- Preconditions:
- The elements in the specified vector should all be expressed in the model reference of this model., It should be possible to add each of the elements in the specified vector
(for each element:
canAddElement(aElement)).
-
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.- Parameters:
aElement- the element to be removed from this model.aEventMode- the mode for sending out the model change event. This can beFIRE_LATERorNO_EVENT.- See Also:
- Preconditions:
- It should be possible to remove the specified element (
canRemoveElement(aElement)).
-
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.- Parameters:
aElement- 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.- Parameters:
aElements- the vector of elements to be removed from this model.aEventMode- the mode for sending out the model change event. This can beFIRE_LATERorNO_EVENT.- See Also:
- Preconditions:
- It should be possible to remove each of the elements in the specified vector
(for each element:
canRemoveElement(aElement)).
-
removeAllElements
void removeAllElements(int aEventMode) 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.- Parameters:
aEventMode- the mode for sending out the model change event. This can beFIRE_LATERorNO_EVENT.
-
elementChanged
Notifies this model that the specified element has changed.- Parameters:
aElement- 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.- Parameters:
aElements- the vector of elements that have changed.aEventMode- the mode for sending out the model change event. This can beFIRE_LATERorNO_EVENT.- Throws:
NullPointerException- if the specified vector isnull.
-
fireCollectedModelChanges
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.- See Also:
-
addModelListener
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
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.- Parameters:
aModelListener- theILcdModelListenerto register on this model.- Throws:
NullPointerException- if the specified listener isnull.- See Also:
-
removeModelListener
Unregisters the specified model listener so that it no longer receives notifications of model changes on this model.- Parameters:
aModelListener- theILcdModelListenerto remove.- Throws:
NullPointerException- if the specified listener isnull.- See Also:
-
dispose
void dispose()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.- Specified by:
disposein interfaceILcdDisposable
-
query
Provides 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.- Parameters:
aQuery- The query, cannot benull. Passall()if you want all elements.- Returns:
- a stream of the retained model elements
- Since:
- 2017.0
- See Also:
- The query
-
all
Create a query indicating that all elements should be retrieved. You can further refine the query using the instance methodsfilter,sortedorlimit.- Returns:
- The query (not null)
- Since:
- 2017.0
-
filter
Create a query with the given condition to filter on. You can further refine the query using the instance methodssortedorlimit.- Parameters:
aCondition- The condition, ornullif no filtering should be done.- Returns:
- The query (not null)
- Since:
- 2017.0
- See Also:
-
FIRE_LATERorNO_EVENT.