Ejemplo n.º 1
0
 @SuppressWarnings("unchecked")
 Set<ReteSimpleMatch> getStorageFor(RuleToHostMap anchorMap) {
   Set<ReteSimpleMatch> result = null;
   HashMap<HostElement, Object> leaf = this.root;
   for (int i = 0; i < this.rootSearchOrder.length - 1; i++) {
     HostElement ei;
     if (this.rootSearchOrder[i] instanceof RuleNode) {
       ei = anchorMap.nodeMap().get(this.rootSearchOrder[i]);
     } else {
       ei = anchorMap.edgeMap().get(this.rootSearchOrder[i]);
     }
     HashMap<HostElement, Object> treeNode = (HashMap<HostElement, Object>) leaf.get(ei);
     if (treeNode == null) {
       treeNode = new HashMap<HostElement, Object>();
       leaf.put(ei, treeNode);
     }
     leaf = treeNode;
   }
   HostElement ei =
       (this.rootSearchOrder[this.rootSearchOrder.length - 1] instanceof RuleNode)
           ? anchorMap.nodeMap().get(this.rootSearchOrder[this.rootSearchOrder.length - 1])
           : anchorMap.edgeMap().get(this.rootSearchOrder[this.rootSearchOrder.length - 1]);
   Object o = leaf.get(ei);
   if (o == null) {
     o = new TreeHashSet<AbstractReteMatch>();
     leaf.put(ei, o);
   }
   result = (Set<ReteSimpleMatch>) o;
   this.collectionsToAnchorsMap.put(result, anchorMap);
   return result;
 }
Ejemplo n.º 2
0
 /**
  * Extracts the morphism from rule nodes to input graph nodes corresponding to the transition's
  * input parameters.
  *
  * @return if {@code null}, the binding cannot be constructed and so the rule cannot match
  */
 private RuleToHostMap extractBinding(Step step) {
   RuleToHostMap result = this.state.getGraph().getFactory().createRuleToHostMap();
   Object[] sourceValues = this.state.getActualValues();
   for (Assignment assign : step.getEnterAssignments()) {
     sourceValues = assign.compute(sourceValues);
   }
   for (Pair<Var, Binding> entry : step.getRuleSwitch().getCallBinding()) {
     Binding bind = entry.two();
     HostNode value;
     if (bind == null) {
       // this corresponds to an output parameter of the call
       continue;
     }
     switch (bind.getSource()) {
       case CONST:
         value = bind.getValue().getNode();
         break;
       case VAR:
         value = Valuator.get(sourceValues, bind);
         break;
       default:
         assert false;
         value = null;
     }
     RuleNode ruleNode = entry.one().getRuleNode();
     if (isCompatible(ruleNode, value)) {
       result.putNode(ruleNode, value);
     } else {
       result = null;
       break;
     }
   }
   return result;
 }
Ejemplo n.º 3
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;
    }