Example #1
0
  public void collectNeededEntities(NeededEntities needs) {
    Entity entity = target.getOwner();
    if (!isGlobalVariable(entity)) needs.add((GraphEntity) entity);

    // Temporarily do not collect variables for target
    HashSet<Variable> varSet = needs.variables;
    needs.variables = null;
    target.collectNeededEntities(needs);
    needs.variables = varSet;

    if (getNext() != null) {
      getNext().collectNeededEntities(needs);
    }
  }
  /**
   * Collects all pairs (node_num. attr_id) occuring in the qualifications at the leafes of the
   * given expression and stores them in a map, which map node_numbers to collections of attr_ids
   *
   * @param act_id the id of the action the expr is condition of
   * @param map a Map
   * @param expr an Expression
   */
  protected void __recursive_qual_collect(
      int act_id,
      Map<Node, Collection<Integer>> node_map,
      Map<Edge, Collection<Integer>> edge_map,
      Expression expr) {
    if (expr == null) return;

    // recursive descent
    if (expr instanceof Operator)
      for (int i = 0; i < ((Operator) expr).arity(); i++)
        __recursive_qual_collect(act_id, node_map, edge_map, ((Operator) expr).getOperand(i));

    // get (node_num, attr_id) pairs from qualifications
    if (expr instanceof Qualification) {
      Qualification qual = (Qualification) expr;
      Entity owner = qual.getOwner();
      Entity member = qual.getMember();

      // if owner is a node, add to the node_map
      if (owner instanceof Node) {
        Node node = (Node) owner;
        // Integer node_num = (Integer) pattern_node_num[ act_id ].get( owner );
        Integer attr_id = nodeAttrMap.get(member);

        // add the pair (node_num, attr_id to the map)
        if (node_map.containsKey(node)) node_map.get(node).add(attr_id);
        else {
          Collection<Integer> newCol = new HashSet<Integer>();
          newCol.add(attr_id);
          node_map.put(node, newCol);
        }
      }

      // if owner is an edge. add to the edge_map
      if (owner instanceof Edge) {
        Edge egde = (Edge) owner;
        // Integer edge_num = (Integer) pattern_edge_num[act_id].get(owner);
        Integer attr_id = edgeAttrMap.get(member);

        // add the pair (edge_num, attr_id to the map)
        if (edge_map.containsKey(egde)) edge_map.get(egde).add(attr_id);
        else {
          Collection<Integer> newCol = new TreeSet<Integer>(integerComparator);
          newCol.add(attr_id);
          edge_map.put(egde, newCol);
        }
      }
    }
  }