public class TLcdVectorModel extends ALcdModel implements ILcdIntegerIndexedModel
ILcdIntegerIndexedModel
.
This model stores its elements in a linear index, allowing fast integer-index-based queries.
Since only a linear index is maintained, addition of elements is fast and memory consumption is very low. There are no constraints on the elements that can be added to this model.
Users may consider using this model if one or more of the following conditions are met:
ILcdBounded.
package documentation
provides a detailed overview of all model
implementations that are available in this package, and their usage.ILcdModel.Query
Modifier and Type | Field and Description |
---|---|
protected Vector |
fVector
The vector to contain the models elements.
|
fModelEventSupport
FIRE_LATER, FIRE_NOW, NO_EVENT
Constructor and Description |
---|
TLcdVectorModel()
Constructs a new, empty
TLcdVectorModel , initialized with a default TLcdModelDescriptor . |
TLcdVectorModel(ILcdModelReference aModelReference)
Constructs a new, empty
TLcdVectorModel , initialized with the specified model reference and a default
TLcdModelDescriptor . |
TLcdVectorModel(ILcdModelReference aModelReference,
ILcdModelDescriptor aModelDescriptor)
Constructs a new, empty
TLcdVectorModel , initialized with the specified model reference and model
descriptor. |
Modifier and Type | Method and Description |
---|---|
void |
addElement(Object aElement,
int aFireEventMode)
Adds the specified element to this model.
|
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. |
boolean |
contains(Object aElement)
Returns
true if the specified element is contained in this model, false otherwise. |
Object |
elementAt(int aIndex)
Returns the element at the specified index.
|
Enumeration |
elements()
Returns an enumeration over all elements of this model.
|
ILcdFilter |
getAddElementFilter()
Returns the filter that is used to control which elements are accepted for addition to this model.
|
ILcdFilter |
getRemoveElementFilter()
Returns the filter that is used to control which elements are accepted for removal from this model.
|
int |
indexOf(Object aObject)
Returns the index of the first occurrence of the specified element in the model, or -1 if this model does not
contain the element.
|
void |
removeAllElements(int aFireEventMode)
Removes all elements from this model.
|
void |
removeElement(Object aElement,
int aFireEventMode)
Removes the specified element from this model.
|
void |
setAddElementFilter(ILcdFilter aFilter)
Sets the filter that is used to control which elements are accepted for addition to this model.
|
void |
setRemoveElementFilter(ILcdFilter aFilter)
Sets the filter that is used to control which elements are accepted for removal from this model.
|
int |
size()
Returns the number of elements in this model.
|
String |
toString() |
addElements, addModelListener, allElementsChanged, allElementsRemoved, dispose, elementAdded, elementChanged, elementRemoved, elementsAdded, elementsChanged, elementsRemoved, fireCollectedModelChanges, getModelDescriptor, getModelEncoder, getModelMetadata, getModelReference, initializeTransientValues, isClassTraceOn, isTraceOn, removeElements, removeModelListener, setClassTraceOn, setModelDescriptor, setModelDisposer, setModelEncoder, setModelMetadataFunction, setModelReference, setTraceOn
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addElements, addModelListener, all, dispose, elementChanged, elementsChanged, filter, fireCollectedModelChanges, getModelDescriptor, getModelEncoder, getModelMetadata, getModelReference, query, removeElements, removeModelListener
close
protected Vector fVector
public TLcdVectorModel()
TLcdVectorModel
, initialized with a default TLcdModelDescriptor
.public TLcdVectorModel(ILcdModelReference aModelReference)
TLcdVectorModel
, initialized with the specified model reference and a default
TLcdModelDescriptor
.aModelReference
- the model reference describing the coordinate system used in this model.public TLcdVectorModel(ILcdModelReference aModelReference, ILcdModelDescriptor aModelDescriptor)
TLcdVectorModel
, initialized with the specified model reference and model
descriptor.aModelReference
- the model reference describing the coordinate system used in this model.aModelDescriptor
- the model descriptor providing meta information about this model.public void setAddElementFilter(ILcdFilter aFilter)
canAddElement(Object)
method, to decide whether an element can be added to
this model or not. By default, no filter is set.aFilter
- the filter to be used to control which elements are accepted for addition to this model.canAddElement(Object)
,
getAddElementFilter()
public ILcdFilter getAddElementFilter()
canAddElement(Object)
,
setAddElementFilter(com.luciad.util.ILcdFilter)
public void setRemoveElementFilter(ILcdFilter aFilter)
canRemoveElement(Object)
method, to decide whether an element can be removed
from this model or not. By default, no filter is set.aFilter
- the filter to be used to control which elements are accepted for removal from this model.canRemoveElement(Object)
,
getRemoveElementFilter()
public ILcdFilter getRemoveElementFilter()
canRemoveElement(Object)
,
setRemoveElementFilter(com.luciad.util.ILcdFilter)
public int size()
ILcdIntegerIndexedModel
size
in interface ILcdIntegerIndexedModel
public Object elementAt(int aIndex)
ILcdIntegerIndexedModel
elementAt
in interface ILcdIntegerIndexedModel
aIndex
- an index into this ILcdModel
.public int indexOf(Object aObject)
ILcdIntegerIndexedModel
i
for which this.elementAt(i).equals(aElement)
.indexOf
in interface ILcdIntegerIndexedModel
aObject
- the element to search for.public Enumeration elements()
ILcdModel
public void addElement(Object aElement, int aFireEventMode)
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 implementation calls ALcdModel.elementAdded(Object, int)
after the element has been added, to sent a
model change event to this model's listeners.
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
.ILcdModel.canAddElement(Object)
public boolean canAddElement(Object aElement)
true
if the specified element can be added to this model, false
otherwise.
If an addition filter is set, this method returns filter.accept(aElement)
, otherwise it always returns
true
.canAddElement
in interface ILcdModel
canAddElement
in class ALcdModel
aElement
- the element to be tested.true
if the specified element can be added to this model, false
otherwise.public void removeElement(Object aElement, int aFireEventMode)
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 implementation calls ALcdModel.elementRemoved(Object, int)
after the element has been removed, to
sent a model change event to this model's listeners.
removeElement
in interface ILcdModel
removeElement
in class ALcdModel
aElement
- 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
.ILcdModel.canRemoveElement(Object)
public boolean canRemoveElement(Object aElement)
true
if the specified element can be removed from this model, false
otherwise.
If a removal filter is set, this method returns filter.accept(aElement)
, otherwise it always returns
true
.canRemoveElement
in interface ILcdModel
canRemoveElement
in class ALcdModel
aElement
- the element to be tested.true
if the specified element can be removed from this model, false
otherwise.public boolean contains(Object aElement)
true
if the specified element is contained in this model, false
otherwise.aElement
- the element to be tested.true
if the specified element is contained in this model, false
otherwise.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 implementation calls ALcdModel.allElementsRemoved(int)
after the elements have been removed, to sent a model
change event to this model's listeners.
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
.