T
- The type of info to store in this dictionaryabstract class HierarchicalDictionary<T extends OntologyEntity> extends Object implements Iterable<T>
Modifier and Type | Class and Description |
---|---|
(package private) class |
HierarchicalDictionary.Applier<T extends OntologyEntity,aRet,aParam>
A class used by
applyAllCachedSupers(Applier)
and applyAllSupers(Applier) to run
an algorithm on every dictionary in the "upward" part of the lattice
from this one. |
Modifier and Type | Field and Description |
---|---|
(package private) Vector<HierarchicalDictionary<T>> |
cachedSearchPath
A linear recording of a correct search order of all the
ancestor dictionaries.
|
private CASAOntology |
casaOntology |
(package private) long |
invalidationTimeStamp
Used to record the time of the last invalidation for comparison
during a search using the cached search path --
applyAllCachedSupers(Applier) |
(package private) TreeMap<String,T> |
map
This map uses keys that are the UNQUALIFIED names (not the qualified "ontology:name" syntax).
|
private int |
mark
Used by
applyAllSupers(Applier) to traverse the lattice of ontologies. |
protected Ontology |
owner |
Constructor and Description |
---|
HierarchicalDictionary(CASAOntology casaOntology,
Ontology owner)
Remembers the owner so that it can use the
owner to access objects from dictionaries or its parents' dictionaries.
|
Modifier and Type | Method and Description |
---|---|
private void |
applyAllCachedSupers(HierarchicalDictionary.Applier applier)
Call
HierarchicalDictionary.Applier.apply(HierarchicalDictionary) to all the dictionaries
in the cached path cachedSearchPath . |
private boolean |
applyAllSupers(HierarchicalDictionary.Applier applier)
Calls applier.apply() recursively to in all super dictionary in left-right
order but with the constraint that no super dictionary is applied before
all of it's sub dictionaries are applied.
|
private void |
clearAllMarks()
Sets the value of
mark to zero and recursively those of all its
super dictionaries. |
protected boolean |
consistencyCheck(Name key,
T value)
Subclasses should override this method to specify a consistency check between keys and values
|
boolean |
containsKey(Name key)
Determines if the key associated with this key in the dictionary.
|
boolean |
containsKey(String key)
Defers to
containsKey(Name) by constructing a Name out of the key String. |
T |
get(Name key)
Finds the object associated with this key in the dictionary.
|
T |
get(String key)
|
protected abstract HierarchicalDictionary<T> |
getDictionary(CASAOntology ontology)
Subclasses should override this method to specify how to retrieve super-dictionaries
from the containing ontology.
|
private void |
incAllMarks()
Increments the value of
mark and recursively those of all its
super dictionaries. |
private void |
initSuperSearch()
Prepares for a search by
applyAllSupers(Applier) by recursively
clearing all marks and then incrementing them. |
(package private) void |
invalidateSearchPathCache()
Invalidate the search path by setting
cachedSearchPath to null
and resetting invalidationTimeStamp to the current time. |
Iterator<T> |
iterator() |
Set<String> |
keySet() |
T |
put(Name key,
T value)
Adds the specified key and value to the dictionary.
|
T |
put(String key,
T value)
Defers to
#put(Name, Object) by constructing a Name out of the key String. |
private void |
resetSearchPathCache()
Rebuilds the search path cache,
cachedSearchPath , by
climbing the hierarchy and recording an equivalent linear
version of the search path. |
Collection<T> |
values() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
private final CASAOntology casaOntology
protected Ontology owner
TreeMap<String,T extends OntologyEntity> map
private int mark
applyAllSupers(Applier)
to traverse the lattice of ontologies.
Note that since ontologies are shared, caution must be taken not to run
into concurrency issues when using marks.Vector<HierarchicalDictionary<T extends OntologyEntity>> cachedSearchPath
long invalidationTimeStamp
applyAllCachedSupers(Applier)
public HierarchicalDictionary(CASAOntology casaOntology, Ontology owner)
owner
- The containing "this"casaOntology
- TODOpublic Iterator<T> iterator()
iterator
in interface Iterable<T extends OntologyEntity>
public T put(String key, T value) throws IllegalOperationException
#put(Name, Object)
by constructing a Name
out of the key String.key
- value
- IllegalOperationException
- if the qualified syntax explicitly specifies a dictionary that is not the owner.#put(Name, Object)}
public T put(Name key, T value) throws IllegalOperationException
key
- value
- IllegalOperationException
- if the qualified syntax explicitly specifies a dictionary that is not the owner.public T get(Name key)
applyAllCachedSupers(Applier)
and applyAllSupers(Applier)
.key
- IllegalOperationException
- if the qualified syntax explicitly specifies a dictionary that is not the owner.private void incAllMarks()
mark
and recursively those of all its
super dictionaries.private void clearAllMarks()
mark
to zero and recursively those of all its
super dictionaries.private void initSuperSearch()
applyAllSupers(Applier)
by recursively
clearing all marks and then incrementing them.private boolean applyAllSupers(HierarchicalDictionary.Applier applier)
applier
- private void resetSearchPathCache()
cachedSearchPath
, by
climbing the hierarchy and recording an equivalent linear
version of the search path. Because this must mark nodes
as they are visited, this behaviour must synchronize on
the CLASS of this dictionary, locking out all other similar
dictionaries in the process. Because we need to assure that
multiple reset's don't happen at once, this method is synchronized
to the instance, and will just return if the cachedSearchPath is
NOT null. Therefore, you need to set cachedSearchPath to null
FIRST if you want to rebuild and exist cachedSearchPath.void invalidateSearchPathCache()
cachedSearchPath
to null
and resetting invalidationTimeStamp
to the current time.applyAllCachedSupers(Applier)
private void applyAllCachedSupers(HierarchicalDictionary.Applier applier)
HierarchicalDictionary.Applier.apply(HierarchicalDictionary)
to all the dictionaries
in the cached path cachedSearchPath
. Note that if one the
super-dictionaries has had it's search path invalidated after
this search path has been invalidated, then we must invalidate
ours, rebuild it and recursively start again.applier
- public T get(String key) throws IllegalOperationException
key
- IllegalOperationException
IllegalOperationException
- if the qualified syntax explicitly specifies a dictionary that is not the owner.#get(Name)}
public boolean containsKey(String key) throws IllegalOperationException
containsKey(Name)
by constructing a Name
out of the key String.key
- IllegalOperationException
- if the qualified syntax explicitly specifies a dictionary that is not the owner.#containsKey(Name)}
public boolean containsKey(Name key)
key
- IllegalOperationException
- if the qualified syntax explicitly specifies a dictionary that is not the owner.public Set<String> keySet()
public Collection<T> values()
protected boolean consistencyCheck(Name key, T value)
key
- value
- protected abstract HierarchicalDictionary<T> getDictionary(CASAOntology ontology)
superOntology
-