Пример #1
0
  /**
   * Adds the given match to the conflict set, either the plain list or the tree-like indexed
   * conflict set, whichever is relevant.
   *
   * <p>See the documentation for {@link #conflictSetSearchTree} for more info.
   *
   * @param m The match to be added.
   */
  protected void addMatchToConflictSet(ReteSimpleMatch m) {
    Collection<ReteSimpleMatch> c;
    if (this.conflictSetSearchTree == null) {

      c = this.conflictSet;
    } else {
      c = this.conflictSetSearchTree.getStorageFor(m);
    }
    assert !c.contains(m);
    c.add(m);
    m.addContainerCollection(c);
    m.addDominoListener(this);
  }
Пример #2
0
    @SuppressWarnings("unchecked")
    Set<ReteSimpleMatch> getStorageFor(ReteSimpleMatch m, boolean create) {
      Set<ReteSimpleMatch> result = null;
      HashMap<HostElement, Object> leaf = this.root;
      RuleToHostMap anchorMap = getFactory().createRuleToHostMap();
      int i = 0;
      for (; i < this.rootSearchOrder.length - 1; i++) {
        HostElement ei;
        if (this.rootSearchOrder[i] instanceof RuleNode) {
          ei = m.getNode((RuleNode) this.rootSearchOrder[i]);
          anchorMap.putNode((RuleNode) this.rootSearchOrder[i], (HostNode) ei);
        } else {
          ei = m.getEdge((RuleEdge) this.rootSearchOrder[i]);
          anchorMap.putEdge((RuleEdge) this.rootSearchOrder[i], (HostEdge) ei);
        }

        HashMap<HostElement, Object> treeNode = (HashMap<HostElement, Object>) leaf.get(ei);
        if (treeNode == null) {
          if (create) {
            treeNode = new HashMap<HostElement, Object>();
            leaf.put(ei, treeNode);
          } else {
            leaf = null;
            break;
          }
        }
        leaf = treeNode;
      }
      if (leaf != null) {
        HostElement ei;
        if (this.rootSearchOrder[this.rootSearchOrder.length - 1] instanceof RuleNode) {
          ei = m.getNode((RuleNode) this.rootSearchOrder[this.rootSearchOrder.length - 1]);
          anchorMap.putNode((RuleNode) this.rootSearchOrder[i], (HostNode) ei);
        } else {
          ei = m.getEdge((RuleEdge) this.rootSearchOrder[this.rootSearchOrder.length - 1]);
          anchorMap.putEdge((RuleEdge) this.rootSearchOrder[i], (HostEdge) ei);
        }
        Object o = leaf.get(ei);
        if ((o == null) && create) {
          o = new TreeHashSet<AbstractReteMatch>();
          leaf.put(ei, o);
        }
        result = (Set<ReteSimpleMatch>) o;
      }
      this.collectionsToAnchorsMap.put(result, anchorMap);
      return result;
    }