public abstract class ALcdModel extends Object implements ILcdModel
ILcdModel
to minimize the effort required to implement this
interface.
To implement an unmodifiable model, the user needs to extend this class and implement the
ILcdModel.elements()
method.
To implement a modifiable model, the user must additionally override the following methods:
To achieve better performance, one should also consider:ILcd2DBoundsIndexedModel
for allowing spatial queriesILcdIntegerIndexedModel
for allowing integer-based queriesremoveAllElements(int)
methodModels have a set of threading rules to obey, please refer to ILcdModel
or the developer's guide.
By enabling debug-level logging on ALcdModel, write lock violations of the threading rules are reported on the log. Applications or developers should never solely rely on this mechanism, it is intended to be used for debugging purposes. Its behavior may change in future versions.
Logging can be enabled via config files:
com.luciad.model.ALcdModel.level = FINE
or via code:
Logger.getLogger(ALcdModel.class.getName()).setLevel(Level.FINE);
The violations themselves are reported at the error level.
Limitations
ILcdModel.Query
Modifier and Type | Field and Description |
---|---|
protected TLcdModelChangedEventSupport |
fModelEventSupport
Support for firing model changed events.
|
FIRE_LATER, FIRE_NOW, NO_EVENT
Constructor and Description |
---|
ALcdModel() |
Modifier and Type | Method and Description |
---|---|
void |
addElement(Object aElement,
int aEventMode)
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.
|
void |
addModelListener(ILcdModelListener aModelListener)
Registers the specified model listener to receive notifications of model changes on this model.
|
void |
allElementsChanged(int aFireEventMode)
Notifies this model that all elements have changed.
|
protected void |
allElementsRemoved(int aFireEventMode)
Sends a
TLcdModelChangedEvent to the listeners. |
boolean |
canAddElement(Object aElement)
Returns
true if the specified element can be added to this model, false otherwise. |
boolean |
canRemoveElement(Object aElement)
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.
|
protected void |
elementAdded(Object aElement,
int aFireEventMode)
Sends a
TLcdModelChangedEvent to the listeners. |
void |
elementChanged(Object aElement,
int aFireEventMode)
Notifies this model that the specified element has changed.
|
protected void |
elementRemoved(Object aElement,
int aFireEventMode)
Sends a
TLcdModelChangedEvent to the listeners. |
protected void |
elementsAdded(Vector aElements,
int aFireEventMode)
Notifies this model that the specified elements have been added.
|
void |
elementsChanged(Vector aElements,
int aFireEventMode)
Notifies this model that the elements in the specified vector have changed.
|
protected void |
elementsRemoved(Vector aElements,
int aFireEventMode)
Sends a
TLcdModelChangedEvent to the listeners. |
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.
|
ILcdModelDescriptor |
getModelDescriptor()
Returns the
ILcdModelDescriptor providing meta information about this model and
its elements. |
ILcdModelEncoder |
getModelEncoder()
Returns, if available, a model encoder that is capable of encoding this model,
(
encoder.canEncode(this) ), null otherwise. |
TLcdModelMetadata |
getModelMetadata()
Collects and returns metadata about the model, using this model's model metadata function.
|
ILcdModelReference |
getModelReference()
Returns the
ILcdModelReference describing how the geometry of the elements contained in this
model should be interpreted. |
protected void |
initializeTransientValues()
Initializes transient values.
|
static boolean |
isClassTraceOn()
Deprecated.
This method has been deprecated. It is recommended to use the
standard Java logging framework directly.
|
boolean |
isTraceOn()
Deprecated.
This method has been deprecated. It is recommended to use the
standard Java logging framework directly.
|
void |
removeAllElements(int aEventMode)
Removes all elements from this model.
|
void |
removeElement(Object aElement,
int aEventMode)
Removes the specified element from this model.
|
void |
removeElements(Vector aElements,
int aFireEventMode)
Removes all of the elements in the specified vector from this model.
|
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 |
setModelDescriptor(ILcdModelDescriptor aModelDescriptor)
Sets the model descriptor providing meta information about this model and its elements.
|
void |
setModelDisposer(Consumer<ILcdModel> aModelDisposer)
Sets the method to call when disposing the model.
|
void |
setModelEncoder(ILcdModelEncoder aModelEncoder)
Sets a model encoder on this model that can be used to encode this model.
|
void |
setModelMetadataFunction(Function<ALcdModel,TLcdModelMetadata> aModelMetadataFunction)
Sets the function that is used to collect the model metadata returned by
getModelMetadata() . |
void |
setModelReference(ILcdModelReference aModelReference)
Sets the model reference describing how the geometry of the elements contained in this model
should be interpreted.
|
void |
setTraceOn(boolean aTraceOn)
Deprecated.
This method has been deprecated. It is recommended to use the
standard Java logging framework directly.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close
protected transient TLcdModelChangedEventSupport fModelEventSupport
public 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 static boolean isClassTraceOn()
true
if tracing is enabled for this class.public void setTraceOn(boolean aTraceOn)
true
or false
as argument automatically turns
off tracing for all other class instances for which
setTraceOn
has not been called.
If the argument is false
then only the informative, warning
and error log messages are recorded.aTraceOn
- if true then all log messages are recorded for this
instance. If false, then only the informative, warning and
error log messages are recorded.public boolean isTraceOn()
true
if tracing is enabled for this class.public ILcdModelReference getModelReference()
ILcdModelReference
describing how the geometry of the elements contained in this
model should be interpreted.getModelReference
in interface ILcdModel
ILcdModelReference
of this ILcdModel
.setModelReference(ILcdModelReference)
public void setModelReference(ILcdModelReference aModelReference)
aModelReference
- the model reference for this model.getModelReference()
public ILcdModelDescriptor getModelDescriptor()
ILcdModelDescriptor
providing meta information about this model and
its elements.getModelDescriptor
in interface ILcdModel
ILcdModelDescriptor
of this ILcdModel
. Should not be null
.setModelDescriptor(ILcdModelDescriptor)
public void setModelDescriptor(ILcdModelDescriptor aModelDescriptor)
aModelDescriptor
- the model descriptor for this model.getModelDescriptor()
public ILcdModelEncoder getModelEncoder()
encoder.canEncode(this)
), null
otherwise.getModelEncoder
in interface ILcdModel
null
otherwise.setModelEncoder(ILcdModelEncoder)
public void setModelEncoder(ILcdModelEncoder aModelEncoder)
aModelEncoder
- a model encoder capable of encoding this model.encoder.canEncode(this)
).public TLcdModelMetadata getModelMetadata()
setModelMetadataFunction(Function)
. The default metadata function uses
TLcdModelMetadata.Builder.fromModel(com.luciad.model.ILcdModel)
, but subclasses may set an adjusted default function.getModelMetadata
in interface ILcdModel
ILcdModel.getModelMetadata()
public final void setModelMetadataFunction(Function<ALcdModel,TLcdModelMetadata> aModelMetadataFunction)
getModelMetadata()
. This
function will be called every time the getModelMetadata()
method is called, providing this model instance
as parameter:
public TLcdModelMetadata getModelMetadata() {
return aModelMetadataFunction.apply(this);
}
The default model metadata function uses TLcdModelMetadata.Builder.fromModel(ILcdModel)
, but subclasses
may set an adjusted default function.public final void setModelDisposer(Consumer<ILcdModel> aModelDisposer)
The disposable is called within the method dispose()
.
aModelDisposer
- the disposable that takes care of freeing resources held by the model.public void addElement(Object aElement, int aEventMode)
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
.
addElement
in interface ILcdModel
aElement
- the element to be added to this model.aEventMode
- the mode for sending out the model change event. This can be FIRE_LATER
or NO_EVENT
.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
.
canAddElement
in interface ILcdModel
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.
addElements
in interface ILcdModel
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 aElement, int aEventMode)
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
.
removeElement
in interface ILcdModel
aElement
- the element to be removed from this model.aEventMode
- the mode for sending out the model change event. This can be FIRE_LATER
or NO_EVENT
.ILcdModel.canRemoveElement(Object)
public boolean canRemoveElement(Object aElement)
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
.
canRemoveElement
in interface ILcdModel
aElement
- the element to be verified.true
if the specified element can be removed from this model, false
otherwise.public void removeElements(Vector aElements, 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.
removeElements
in interface ILcdModel
aElements
- 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 aEventMode)
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.
removeAllElements
in interface ILcdModel
aEventMode
- the mode for sending out the model change event. This can be FIRE_LATER
or NO_EVENT
.public void fireCollectedModelChanges()
This implementation calls #TLcdModelChangedEventSupport#fireCollectedModelChanges()
.
fireCollectedModelChanges
in interface ILcdModel
ILcdModelListener.modelChanged(TLcdModelChangedEvent)
public void elementsChanged(Vector aElements, int aFireEventMode)
This implementation calls TLcdModelChangedEventSupport#elementsChanged(java.util.Vector, int)
.
elementsChanged
in interface ILcdModel
aElements
- the vector of elements that have changed.aFireEventMode
- the mode for sending out the model change event. This can be FIRE_LATER
or NO_EVENT
.public void allElementsChanged(int aFireEventMode)
This implementation calls TLcdModelChangedEventSupport#allElementsChanged(int)
.
aFireEventMode
- the mode for sending out the model change event. This can be one of
FIRE_NOW
, FIRE_LATER
or
NO_EVENT
. In case of FIRE_NOW
mode,
only one event will be fired, containing all changes.public void elementChanged(Object aElement, int aFireEventMode)
This implementation calls TLcdModelChangedEventSupport#elementChanged(Object, int)
.
elementChanged
in interface ILcdModel
aElement
- the element that has changed.aFireEventMode
- the mode for sending out the model change event. This can be FIRE_LATER
or NO_EVENT
.protected void elementsAdded(Vector aElements, int aFireEventMode)
This implementation calls com.luciad.model.TLcdModelChangedEventSupport#elementsAdded(java.util.Vector, int)
.
aElements
- the Vector
of Objects that has been added to the model.aFireEventMode
- the mode for sending out the model event. This can be
FIRE_NOW, LATER or NO_EVENT.protected void elementAdded(Object aElement, int aFireEventMode)
TLcdModelChangedEvent
to the listeners.
This implementation calls com.luciad.model.TLcdModelChangedEventSupport#elementAdded(Object, int)
.
aElement
- the Object
that has been added to the model.aFireEventMode
- the mode for sending out the model event. This can be
FIRE_NOW, LATER or NO_EVENT.protected void elementsRemoved(Vector aElements, int aFireEventMode)
TLcdModelChangedEvent
to the listeners.
This implementation calls com.luciad.model.TLcdModelChangedEventSupport#elementsRemoved(java.util.Vector, int)
.
aElements
- the Vector
of Objects that has been removed from the model.aFireEventMode
- the mode for sending out the model event. This can be
FIRE_NOW, LATER or NO_EVENT.protected void elementRemoved(Object aElement, int aFireEventMode)
TLcdModelChangedEvent
to the listeners.
This implementation calls com.luciad.model.TLcdModelChangedEventSupport#elementRemoved(Object, int)
.
aElement
- the Object
that has been removed from the model.aFireEventMode
- the mode for sending out the model event. This can be
FIRE_NOW, LATER or NO_EVENT.protected void allElementsRemoved(int aFireEventMode)
TLcdModelChangedEvent
to the listeners.aFireEventMode
- the mode for sending out the model event. This can be
FIRE_NOW, LATER or NO_EVENT.public void addModelListener(ILcdModelListener aModelListener)
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
aModelListener
- the ILcdModelListener
to register on this model.ILcdModel.removeModelListener(com.luciad.model.ILcdModelListener)
,
ILcdModelListener
public void removeModelListener(ILcdModelListener aModelListener)
This implementation calls TLcdModelChangedEventSupport#removeModelListener(ILcdModelListener)
.
removeModelListener
in interface ILcdModel
aModelListener
- the ILcdModelListener
to remove.ILcdModel.addModelListener(com.luciad.model.ILcdModelListener)
,
ILcdModelListener
public void dispose()
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
setModelDisposer(Consumer)
protected void initializeTransientValues()
super.initializeTransientValues()
before
doing any processing to any transient instance
variables of the subclass.