Ejemplo n.º 1
0
  /**
   * Traverses a Tree, during the process it transforms Or nodes moving the upwards and it removes
   * duplicate logic statement, this does not include Not nodes.
   *
   * <p>Traversal involves three levels the graph for each iteration. The first level is the current
   * node, this node will not be transformed, instead what we are interested in are the children of
   * the current node (called the parent nodes) and the children of those parents (call the child
   * nodes).
   */
  private void processTree(final GroupElement ce, boolean[] result) throws InvalidPatternException {
    boolean hasChildOr = false;

    // first we elimininate any redundancy
    ce.pack();

    for (Object child : ce.getChildren().toArray()) {
      if (child instanceof GroupElement) {
        final GroupElement group = (GroupElement) child;

        processTree(group, result);
        if ((group.isOr() || group.isAnd()) && group.getType() == ce.getType()) {
          group.pack(ce);
        } else if (group.isOr()) {
          hasChildOr = true;
        }
      } else if (child instanceof NamedConsequence) {
        result[0] = true;
      } else if (child instanceof Pattern && ((Pattern) child).getObjectType().isEvent()) {
        result[1] = true;
      }
    }

    if (hasChildOr) {
      applyOrTransformation(ce);
    }
  }
Ejemplo n.º 2
0
  /**
   * Traverses a Tree, during the process it transforms Or nodes moving the upwards and it removes
   * duplicate logic statement, this does not include Not nodes.
   *
   * <p>Traversal involves three levels the graph for each iteration. The first level is the current
   * node, this node will not be transformed, instead what we are interested in are the children of
   * the current node (called the parent nodes) and the children of those parents (call the child
   * nodes).
   *
   * @param ce
   */
  protected void processTree(final GroupElement ce) throws InvalidPatternException {

    boolean hasChildOr = false;

    // first we elimininate any redundancy
    ce.pack();

    Object[] children = (Object[]) ce.getChildren().toArray();
    for (Object aChildren : children) {
      if (aChildren instanceof GroupElement) {
        final GroupElement child = (GroupElement) aChildren;

        processTree(child);
        if ((child.isOr() || child.isAnd()) && child.getType() == ce.getType()) {
          child.pack(ce);
        } else if (child.isOr()) {
          hasChildOr = true;
        }
      }
    }

    if (hasChildOr) {
      applyOrTransformation(ce);
    }
  }
Ejemplo n.º 3
0
  void applyOrTransformation(final GroupElement parent) throws InvalidPatternException {
    final Transformation transformation = this.orTransformations.get(parent.getType());

    if (transformation == null) {
      throw new RuntimeException(
          "applyOrTransformation could not find transformation for parent '"
              + parent.getType()
              + "' and child 'OR'");
    }
    transformation.transform(parent);
  }