package yi.iu.processor.clc;

import java.util.*;

/**
 * Class IntersectingLineClusterSets represents intersecting line clusters.
 * Beside the common funtionality of line cluster sets (see LineClusterSets),
 * it also contains the information of the interrelationships of each
 * intersecting line cluster pairs
 * @deprecated IntersectingLineClusters is used to store the intersecting
 *             relationships between each intersecting line cluster pairs.
 *             It is designed to be used by CLC_Interrelationship.  if
 *             r(c1, c2) and r(c2, c3) [* r(.,.) means two clusters are
 *             inter-related], then cl, c2, c3 will be put to one
 *             IntersectingLineClusters.  But when CLC_Interrelationship call
 *             put() to add new pairs, it uses merged results which mean it
 *             actually call put(c1, c2) and put(c1, c3) since c3 is eventually
 *             merged with c1 as c2.  So the interrelationship is meanless at
 *             all.
 */
public class IntersectingLineClusters extends LineClusterSets {
  /**
   *
   */
  HashMap m_interrelations;

  public IntersectingLineClusters() {
    super();
    m_interrelations = new HashMap();
  }

  /**
   * Put in the relationship.  The order of the two line cluster sets are
   * important.  Different order can correspond to different relationship.  If
   * the relationship is symmetric, the caller is responsible for maintaining
   * it.
   * @param lc1
   * @param lc2
   * @param r
   */
  void put(LineClusterSet lc1, LineClusterSet lc2, Interrelationship r) {
    put(lc1, lc1);
    put(lc2, lc2);
    // find the relations corresponding to lc1
    if (!m_interrelations.containsKey(lc1)) { // the hashmap is not existing
      HashMap relations = new HashMap();
      m_interrelations.put(lc1, relations);
    }

    HashMap entry = (HashMap)m_interrelations.get(lc1);
    // put in the relation to
    entry.put(lc2, r);
  }

  Interrelationship get(LineClusterSet lc1, LineClusterSet lc2) {
    if (!m_interrelations.containsKey(lc1)) return null;
    HashMap entry = (HashMap)m_interrelations.get(lc1);
    return (Interrelationship)entry.get(lc2);
  }
}