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

Variable Index

 o back
Hashtable that maps a target to its source vector.
 o fore
Hashtable that maps a source to its target vector.

Constructor Index

 o Relation()
Constructs an empty relation.

Method Index

 o addPair(Hashtable, Object, Object)
Adds a new pair (x, y) to a table.
 o buildBackTable()
Builds the backward hashtable.
 o contains(Object, Object)
Returns true if the given (source, target) pair exists in the relation set.
 o decode(Decoder)
 o describeClassInfo(ClassInfo)
 o encode(Encoder)
 o finishDecoding()
 o getSources()
Returns all the source objects in the set.
 o getSourcesFor(Object)
Returns all the sources for a given target.
 o getTargets()
Returns all the target objects in the set.
 o getTargetsFor(Object)
Returns all the targets for a given source.
 o getVector(Hashtable, Object)
Returns the vector for a given object x from a given table.
 o hasBackTable()
Returns true if the backward table is built.
 o put(Object, Object)
Places a new pair (source, target) in the relation set.
 o remove(Object)
Removes all pairs (*, x) and (x, *) from the relation set (with cleaning up).
 o remove(Object, boolean)
Removes all pairs (*, x) and (x, *) from the relation set.
 o remove(Object, Object)
Removes a pair (source, target) from the relation set (with cleaning up).
 o remove(Object, Object, boolean)
Removes a pair (source, target) from the relation set.
 o removePair(Hashtable, Object, Object, boolean)
Removes a pair (x, y) from a table.

Variables

 o 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.
 o 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.

Constructors

 o Relation
  public Relation()
Constructs an empty relation. By default, the backward table is null.

Methods

 o buildBackTable
  protected void buildBackTable()
Builds the backward hashtable. This is called by getTargets() or getSourcesFor() if the backward hashtable is not built yet.
 o 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.
 o 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).
 o 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.
 o getSources
  public Vector getSources()
Returns all the source objects in the set. Always returns a non-null (cloned) Vector.
 o 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().
 o put
  public void put(Object source,
                  Object target)
Places a new pair (source, target) in the relation set.
 o remove
  public void remove(Object source,
                     Object target,
                     boolean doCleanup)
Removes a pair (source, target) from the relation set. See removePair().
 o 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).
 o 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.
 o 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.
 o 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'.
 o remove
  public void remove(Object x,
                     boolean doCleanup)
Removes all pairs (*, x) and (x, *) from the relation set. See removePair().
 o remove
  public void remove(Object x)
Removes all pairs (*, x) and (x, *) from the relation set (with cleaning up). Same as remove(x, true).
 o hasBackTable
  public boolean hasBackTable()
Returns true if the backward table is built.
 o describeClassInfo
  public void describeClassInfo(ClassInfo info)
 o decode
  public void decode(Decoder decoder) throws CodingException
 o encode
  public void encode(Encoder encoder) throws CodingException
 o finishDecoding
  public void finishDecoding()

All Packages  Class Hierarchy  This Package  Previous  Next  Index