Class com.micronova.util.Relation
All Packages Class Hierarchy This Package Previous Next Index
Class com.micronova.util.Relation
java.lang.Object
|
+----com.micronova.util.Relation
- public class Relation
- extends Object
- implements Codable
A Relation is a set of (source, target) pairs of Objects.
Object comparison is identity-based, not 'equals'.
- Version:
- 1.0
- Author:
- Makoto Nagata, MicroNova
-
back
-
Hashtable that maps a target to its source vector.
-
fore
-
Hashtable that maps a source to its target vector.
-
Relation()
-
Constructs an empty relation.
-
addPair(Hashtable, Object, Object)
-
Adds a new pair (x, y) to a table.
-
buildBackTable()
-
Builds the backward hashtable.
-
contains(Object, Object)
-
Returns true if the given (source, target) pair exists
in the relation set.
-
decode(Decoder)
-
-
describeClassInfo(ClassInfo)
-
-
encode(Encoder)
-
-
finishDecoding()
-
-
getSources()
-
Returns all the source objects in the set.
-
getSourcesFor(Object)
-
Returns all the sources for a given target.
-
getTargets()
-
Returns all the target objects in the set.
-
getTargetsFor(Object)
-
Returns all the targets for a given source.
-
getVector(Hashtable, Object)
-
Returns the vector for a given object x from a given table.
-
hasBackTable()
-
Returns true if the backward table is built.
-
put(Object, Object)
-
Places a new pair (source, target) in the relation set.
-
remove(Object)
-
Removes all pairs (*, x) and (x, *) from the relation set (with cleaning up).
-
remove(Object, boolean)
-
Removes all pairs (*, x) and (x, *) from the relation set.
-
remove(Object, Object)
-
Removes a pair (source, target) from the relation set (with
cleaning up).
-
remove(Object, Object, boolean)
-
Removes a pair (source, target) from the relation set.
-
removePair(Hashtable, Object, Object, boolean)
-
Removes a pair (x, y) from a table.
fore
protected Hashtable fore
- Hashtable that maps a source to its target vector.
I.e., fore.get(source) is the vector containing all the
target objects for a given source.
back
protected Hashtable back
- Hashtable that maps a target to its source vector.
This is null by default, but automatically
built by buildBackTable()
when either getTargets()
or getSourcesFor()
is performed.
Once built, back.get(target) is always the vector
containing all the source objects for a given target.
Relation
public Relation()
- Constructs an empty relation. By default, the backward
table is null.
buildBackTable
protected void buildBackTable()
- Builds the backward hashtable. This is called by
getTargets() or
getSourcesFor()
if the backward hashtable is not built yet.
getVector
protected Vector getVector(Hashtable table,
Object x)
- Returns the vector for a given object x from a given table.
Returns null if x is not found.
addPair
protected void addPair(Hashtable table,
Object x,
Object y)
- Adds a new pair (x, y) to a table.
I.e., y is added to the vector for x
if it is not present (comparison is identity-based).
removePair
protected void removePair(Hashtable table,
Object x,
Object y,
boolean doCleanup)
- Removes a pair (x, y) from a table.
If doCleanup is true, the vector for x is removed from
the hashtable if it becomes empty after removal.
Otherwise, the vector stays in the hashtable.
getSources
public Vector getSources()
- Returns all the source objects in the set.
Always returns a non-null (cloned) Vector.
getTargets
public Vector getTargets()
- Returns all the target objects in the set.
Always returns a non-null (cloned) Vector.
The backward table is built if not present by
buildBackTable().
put
public void put(Object source,
Object target)
- Places a new pair (source, target) in the relation set.
remove
public void remove(Object source,
Object target,
boolean doCleanup)
- Removes a pair (source, target) from the relation set.
See removePair().
remove
public void remove(Object source,
Object target)
- Removes a pair (source, target) from the relation set (with
cleaning up). Same as remove(source, target, true).
getTargetsFor
public Vector getTargetsFor(Object source)
- Returns all the targets for a given source.
Always returns a non-null Vector. If the
returned vector is non-empty, it is the
actual vector stored in the hashtable.
Do not modify the returned vector.
getSourcesFor
public Vector getSourcesFor(Object target)
- Returns all the sources for a given target.
The backward table is built if not present.
Always returns a non-null Vector. If the
returned vector is non-empty, it is the
actual vector stored in the hashtable.
Do not modify the returned vector.
contains
public boolean contains(Object source,
Object target)
- Returns true if the given (source, target) pair exists
in the relation set. Comparison is identity-based,
not 'equals'.
remove
public void remove(Object x,
boolean doCleanup)
- Removes all pairs (*, x) and (x, *) from the relation set.
See removePair().
remove
public void remove(Object x)
- Removes all pairs (*, x) and (x, *) from the relation set (with cleaning up).
Same as remove(x, true).
hasBackTable
public boolean hasBackTable()
- Returns true if the backward table is built.
describeClassInfo
public void describeClassInfo(ClassInfo info)
decode
public void decode(Decoder decoder) throws CodingException
encode
public void encode(Encoder encoder) throws CodingException
finishDecoding
public void finishDecoding()
All Packages Class Hierarchy This Package Previous Next Index