Package lupos.gui.operatorgraph.visualeditor.ruleeditor.operators

Examples of lupos.gui.operatorgraph.visualeditor.ruleeditor.operators.AbstractRuleOperator


    // create connection between the two operators...
    this.firstOp.addSucceedingElement(new GraphWrapperIDTuple(this.secondOp, opID));
    this.secondOp.addPrecedingElement(this.firstOp);

    AbstractRuleOperator ruleOp1 = (AbstractRuleOperator) this.firstOp.getElement();
    AbstractRuleOperator ruleOp2 = (AbstractRuleOperator) this.secondOp.getElement();

    ruleOp1.setActiveConnection(ruleOp2, loadObject.getBoolean("active"));
    ruleOp1.setChildOpID(ruleOp2, opIDLabel);
    ruleOp1.setMode(ruleOp2, ModeEnum.valueOf(loadObject.getString("mode")));

    if(!opIDLabel.equals("-1")) {
      try {
        ruleOp2.setOpID(opIDLabel, loadObject.getBoolean("active"));
      }
      catch(ModificationException e) {
        e.printStackTrace();
      }
    }
View Full Code Here


      final HashSet<String> equalOps = new HashSet<String>();
      final HashSet<String> jumpOps_left = new HashSet<String>();
      final HashSet<String> jumpOps_right = new HashSet<String>();

      for(final GraphWrapper gw0 : gws0) {
        final AbstractRuleOperator op0 = (AbstractRuleOperator) gw0.getElement();
        final String op0name = op0.getName();

        if(op0.getClass() == JumpOverOperator.class) {
          jumpOps_left.add(op0.getName());
        }

        if(op0name.startsWith(AbstractRuleOperator.internal_name)) {
          continue;
        }

        for(final GraphWrapper gw1 : gws1) {
          final AbstractRuleOperator op1 = (AbstractRuleOperator) gw1.getElement();
          final String op1name = op1.getName();

          if(op1.getClass() == JumpOverOperator.class) {
            jumpOps_right.add(op1.getName());
          }

          if(op1name.startsWith(AbstractRuleOperator.internal_name)) {
            continue;
          }

          if(op0name.equals(op1name) && !op0.getClassType().equals(op1.getClassType())) {
            throw new ModificationException("ERROR: Two operators on both sides have the same name but not the same class type!", op1);
          }
          else if(op0name.equals(op1name) && op0.getClassType().equals(op1.getClassType())) {
            equalOps.add(op0name);
          }
        }
      }

      jumpOps_right.removeAll(jumpOps_left);

      if(jumpOps_right.size() > 0) {
        throw new ModificationException("ERROR: It is not allowed to add JumpOverOperators on the right side which are not present on the left side!", null);
      }


      for(final GraphWrapper gw : visualGraph0.getRootList(false)) {
        this.validateCycles((Operator) gw.getElement(), new LinkedHashSet<Operator>(), false);
      }

      for(final GraphWrapper gw : visualGraph1.getRootList(false)) {
        this.validateCycles((Operator) gw.getElement(), new LinkedHashSet<Operator>(), false);
      }


      final AbstractRuleOperator startNode = this.getStartNode();

      if(startNode == null) {
        return new Triple<Boolean, HashMap<String, VariableContainer>, HashMap<String, VariableContainer>>(true, null, null);
      }

      this.analyze_manage_node(variableList_left, startNode, 0, new HashSet<AbstractRuleOperator>(), new HashMap<Operator, HashSet<Operator>>());

      if(variableList_left.get(startNode.getName()).getDimension() > 0) {
        throw new ModificationException("ERROR: The dimension of the start node must be 0!", null);
      }


      boolean changed = true;
      final LinkedList<HashSet<ConnectionContainer>> connections = this.getConnections();
      final HashSet<ConnectionContainer> rightConnections = connections.get(1);

      if(visualGraph1.getRootList(false).size() > 0) {
        this.analyze_manage_node(variableList_right, (AbstractRuleOperator) visualGraph1.getRootList(false).get(0).getElement(), 0, new HashSet<AbstractRuleOperator>(), new HashMap<Operator, HashSet<Operator>>());
      }

      for(final ConnectionContainer conn : rightConnections) {
        final String parentName = this.getJumpOverName(conn.getParent(), false);
        final String childName = this.getJumpOverName(conn.getChild(), true);

        if(variableList_left.containsKey(childName)) {
          if(!variableList_left.containsKey(parentName) && conn.getMode() != ModeEnum.ALL_PRECEDING) {
            variableList_right.get(parentName).setCountProvider(conn.getChild());
          }

          variableList_right.get(childName).setCountProvider(conn.getChild());
        }

        if(variableList_left.containsKey(parentName)) {
          if(!variableList_left.containsKey(childName) && conn.getMode() != ModeEnum.ALL_SUCCEEDING) {
            variableList_right.get(childName).setCountProvider(conn.getParent());
          }

          variableList_right.get(parentName).setCountProvider(conn.getParent());
        }
      }

      while(changed) {
        changed = false;

        for(final ConnectionContainer conn : rightConnections) {
          final String parentName = this.getJumpOverName(conn.getParent(), false);
          final String childName = this.getJumpOverName(conn.getChild(), true);

          if(variableList_right.get(parentName).getCountProvider() == null && variableList_right.get(childName).getCountProvider() != null) {
            variableList_right.get(parentName).setCountProvider(variableList_right.get(childName).getCountProvider());
            changed = true;
          }
          else if(variableList_right.get(childName).getCountProvider() == null && variableList_right.get(parentName).getCountProvider() != null) {
            variableList_right.get(childName).setCountProvider(variableList_right.get(parentName).getCountProvider());
            changed = true;
          }
        }
      }

      for(final VariableContainer vc : variableList_right.values()) {
        if(vc.getCountProvider() == null) {
          if(!variableList_left.containsKey(vc.getOpName())) {
            throw new ModificationException("ERROR: Can't determine dimension size for operator " + vc.getOpName() + "!", null);
          }
        }
      }


      final StringBuffer warnings = new StringBuffer();

      final Hashtable<GraphWrapper, LinkedList<GraphWrapper>> annotations0 = visualGraph0.getDrawnLineAnnotations();
      final Hashtable<GraphWrapper, LinkedList<GraphWrapper>> annotations1 = visualGraph1.getDrawnLineAnnotations();

      for(final GraphWrapper gw0 : annotations0.keySet()) {
        final AbstractRuleOperator op0 = (AbstractRuleOperator) gw0.getElement();
        final String op0name = op0.getName();

        // first op on left side has children...
        if(equalOps.contains(op0name)) {
          for(final GraphWrapper gw0child : annotations0.get(gw0)) {
            final AbstractRuleOperator op0child = (AbstractRuleOperator) gw0child.getElement();
            final String op0childName = op0child.getName();

            // second op on left side is child...
            if(equalOps.contains(op0childName)) {
              final AnnotationPanel annotation0 = (AnnotationPanel) op0.getAnnotationLabel(op0child);

              for(final GraphWrapper gw1 : annotations1.keySet()) {
                final AbstractRuleOperator op1 = (AbstractRuleOperator) gw1.getElement();
                final String op1name = op1.getName();
                boolean breakFlag = false;

                // first op on right side has children...
                if(equalOps.contains(op1name) && op0name.equals(op1name) && op0.getClassType().equals(op1.getClassType())) {
                  for(final GraphWrapper gw1child : annotations1.get(gw1)) {
                    final AbstractRuleOperator op1child = (AbstractRuleOperator) gw1child.getElement();
                    final String op1childName = op1child.getName();

                    // second op on right side is child...
                    if(equalOps.contains(op1childName) && op0childName.equals(op1childName) && op0child.getClassType().equals(op1child.getClassType())) {
                      final AnnotationPanel annotation1 = (AnnotationPanel) op1.getAnnotationLabel(op1child);

                      if(annotation0.getMode() != annotation1.getMode()) {
                        warnings.append("The connections of equal operators on both sides should have the same mode! The mode on the right side is being ignored if not.\n");
View Full Code Here

      final LinkedList<Operator> elements = new LinkedList<Operator>(visitedNodes);
      elements.add(op);

      for(int i = elements.indexOf(op); i < elements.size()-1; i += 1) {
        final AbstractRuleOperator element = (AbstractRuleOperator) elements.get(i);
        final AbstractRuleOperator nextElement = (AbstractRuleOperator) elements.get(i+1);

        if(element.equals(op)) {
          inLoop = true;
        }

        if(inLoop) {
          final ModeEnum mode = ((AnnotationPanel) element.getAnnotationLabel(nextElement)).getMode();

          if(mode == ModeEnum.ALL_PRECEDING || mode == ModeEnum.ALL_SUCCEEDING) {
            throw new ModificationException("The mode '" + mode + "' is not allowed in cycles!", element);
          }
        }
      }

      return;
    }

    visitedNodes.add(op);

    for(final OperatorIDTuple<Operator> sucOpIDt : op.getSucceedingOperators()) {
      final AbstractRuleOperator sucOp = (AbstractRuleOperator) sucOpIDt.getOperator();

      final ModeEnum mode = ((AnnotationPanel) ((AbstractRuleOperator) op).getAnnotationLabel(sucOp)).getMode();

      if(mode == ModeEnum.ALL_SUCCEEDING) {
        foundAllSucceeding = true;
View Full Code Here

    final LinkedList<Operator> precedingOperators = node.getPrecedingOperators();

    if(precedingOperators.size() > 0) {
      for(int i = 0; i < precedingOperators.size(); i += 1) {
        final AbstractRuleOperator precOp = (AbstractRuleOperator) precedingOperators.get(i);


        HashSet<Operator> connectionNodes = visitedConnections.get(precOp);

        if(connectionNodes == null) {
          connectionNodes = new HashSet<Operator>();
          visitedConnections.put(precOp, connectionNodes);
        }
        else if(connectionNodes.contains(node)) {
          continue;
        }

        connectionNodes.add(node);


        switch(((AnnotationPanel) precOp.getAnnotationLabel(node)).getMode()) {
        default:
        case ONLY_PRECEDING_AND_SUCCEEDING:
        case ONLY_SUCCEEDING:
        case EXISTS:
          this.analyze_manage_node(variableList, precOp, currentDimension, visitedNodes, visitedConnections);

          break;
        case ALL_PRECEDING:
          this.analyze_manage_node(variableList, precOp, currentDimension+1, visitedNodes, visitedConnections);

          break;
        case ALL_SUCCEEDING:
          final HashMap<Operator, HashSet<Operator>> new_visitedConnections = new HashMap<Operator, HashSet<Operator>>();

          final HashSet<Operator> tmp = new HashSet<Operator>();
          tmp.add(node);

          new_visitedConnections.put(precOp, tmp);

          this.analyze_increment_dimension(variableList, precOp, currentDimension, new HashSet<AbstractRuleOperator>(), false);
          this.analyze_manage_node(variableList, precOp, currentDimension, new HashSet<AbstractRuleOperator>(), new_visitedConnections);

          break;
        }
      }
    }


    final LinkedList<OperatorIDTuple<Operator>> succedingOperators = node.getSucceedingOperators();

    if(succedingOperators.size() > 0) {
      for(int i = 0; i < succedingOperators.size(); i += 1) {
        final OperatorIDTuple<Operator> sucOpIDTup = succedingOperators.get(i);
        final AbstractRuleOperator sucOp = (AbstractRuleOperator) sucOpIDTup.getOperator();


        HashSet<Operator> connectionNodes = visitedConnections.get(node);

        if(connectionNodes == null) {
View Full Code Here

    visitedNodes.add(node);


    if(preceding) {
      for(final Operator precOp : node.getPrecedingOperators()) {
        final AbstractRuleOperator precRuleOp = (AbstractRuleOperator) precOp;
        final String opName = this.getJumpOverName(precRuleOp, false);
        final int newDimension = (((AnnotationPanel) precRuleOp.getAnnotationLabel(node)).getMode() == ModeEnum.ALL_PRECEDING) ? currentDimension+1 : currentDimension;
        final VariableContainer vc = variableList.get(opName);

        if(vc == null) {
          final Class<?> clazzType = (node.getClass() == JumpOverOperator.class) ? BasicOperator.class : precRuleOp.getClassType().getOpClass();

          variableList.put(opName, new VariableContainer(opName, clazzType, newDimension));
        }
        else {
          vc.setDimension(newDimension);
        }

        this.analyze_increment_dimension(variableList, precRuleOp, newDimension, visitedNodes, preceding);
      }
    }
    else {
      for(final OperatorIDTuple<Operator> opIDt : node.getSucceedingOperators()) {
        final AbstractRuleOperator sucOp = (AbstractRuleOperator) opIDt.getOperator();
        final String opName = this.getJumpOverName(sucOp, true);
        final int newDimension = (((AnnotationPanel) node.getAnnotationLabel(sucOp)).getMode() == ModeEnum.ALL_SUCCEEDING) ? currentDimension+1 : currentDimension;
        final VariableContainer vc = variableList.get(opName);

        if(vc == null) {
          final Class<?> clazzType = (node.getClass() == JumpOverOperator.class) ? BasicOperator.class : sucOp.getClassType().getOpClass();

          variableList.put(opName, new VariableContainer(opName, clazzType, newDimension));
        }
        else {
          vc.setDimension(newDimension);
View Full Code Here

      for(int i = 0; i <= 1; i += 1) {
        final VisualGraph<Operator> vg = this.visualGraphs.get(i);
        final HashSet<ConnectionContainer> connections = new HashSet<ConnectionContainer>();

        for(final GraphWrapper parentGW : vg.getDrawnLineAnnotations().keySet()) {
          final AbstractRuleOperator parentOp = (AbstractRuleOperator) parentGW.getElement();

          for(final GraphWrapper childGW : vg.getDrawnLineAnnotations().get(parentGW)) {
            final AbstractRuleOperator childOp = (AbstractRuleOperator) childGW.getElement();

            connections.add(new ConnectionContainer((AnnotationPanel) parentOp.getAnnotationLabel(childOp)));
          }
        }
View Full Code Here

  @SuppressWarnings("unchecked")
  public boolean validateOperatorPanel(boolean showErrors, Object data) {
    try {
      String idText = this.jTF_id.getText();

      AbstractRuleOperator ruleOp = (AbstractRuleOperator) this.operator;
      AbstractRuleOperator ruleChildOp = (AbstractRuleOperator) this.child;

      ruleOp.setActiveConnection(ruleChildOp, this.jCB_activate.isSelected());
      boolean ret = ruleChildOp.setOpID(idText, this.isActive());

      if(ret) {
        ruleOp.setChildOpID(ruleChildOp, idText);
      }
View Full Code Here

      this.replaceMethodCode.append(
          spaces + "// remove obsolete connections...\n"
      );

      for(ConnectionContainer conn : leftConnections) {
        AbstractRuleOperator parentOp = conn.getParent();
        AbstractRuleOperator childOp = conn.getChild();
        String parentName = this.getJumpOverName(parentOp, false);
        String childName = this.getJumpOverName(childOp, true);

        String opIDLabel = conn.getOpIDLabel();
        boolean hasLabel = conn.getIsActive() && !opIDLabel.equals("");
        StringBuffer labelBrackets = new StringBuffer();

        String succeedingString = null;
        int dim = 0;
        StringBuffer arrayAccess = new StringBuffer();

        switch(conn.getMode()) {
        case ALL_PRECEDING:
          dim = this.variableList_left.get(childName).getDimension();

          if(hasLabel) {
            for(int i = 0; i <= dim; i += 1) {
              labelBrackets.append("[]");
            }

            this.replaceMethodCode.append(
                spaces + "int" + labelBrackets + " _label_" + opIDLabel + " = null;\n" +
                "\n"
            );
          }

          for(int i = 0; i < dim; i += 1) {
            if(hasLabel) {
              labelBrackets.delete(labelBrackets.length()-2, labelBrackets.length());

              this.replaceMethodCode.append(
                  spaces + "_label_" + opIDLabel + arrayAccess + " = new int[this." + childName + ".length]" + labelBrackets + ";\n" +
                  "\n"
              );
            }

            this.replaceMethodCode.append(spaces + "for(this._dim_" + i + " = 0; this._dim_" + i + " < this." + childName + ".length; this._dim_" + i + " += 1) {\n");

            arrayAccess.append("[this._dim_" + i + "]");

            spaces.append("    ");
          }

          succeedingString = (conn.getIsActive() && conn.getOpID() != -1) ? "new OperatorIDTuple(this." + childName + arrayAccess + ", " + conn.getOpID() + ")" : "this." + childName + arrayAccess;

          if(hasLabel) {
            labelBrackets.delete(labelBrackets.length()-2, labelBrackets.length());

            this.replaceMethodCode.append(
                spaces + "int _label_" + opIDLabel + "_count" + " = 0;\n" +
                spaces + "_label_" + opIDLabel + arrayAccess + " = new int[this." + parentName + arrayAccess + ".length]" + labelBrackets + ";\n" +
                "\n"
            );
          }

          this.replaceMethodCode.append(spaces + "for(" + parentOp.getClassType().getOpClass().getName() + " _parent : this." + parentName + arrayAccess + ") {\n");

          if(hasLabel) {
            this.replaceMethodCode.append(
                spaces + "    _label_" + opIDLabel + arrayAccess + "[_label_" + opIDLabel + "_count] = _parent.getOperatorIDTuple(this." + childName + arrayAccess + ").getId();\n" +
                spaces + "    _label_" + opIDLabel + "_count += 1;\n" +
                "\n"
            );
          }

          this.replaceMethodCode.append(
              spaces + "    _parent.removeSucceedingOperator(" + succeedingString + ");\n" +
              spaces + "    this." + childName + arrayAccess + ".removePrecedingOperator(_parent);\n" +
              spaces + "}\n" +
              "\n"
          );

          break;

        case ALL_SUCCEEDING:
          dim = this.variableList_left.get(parentName).getDimension();

          if(hasLabel) {
            for(int i = 0; i <= dim; i += 1) {
              labelBrackets.append("[]");
            }

            this.replaceMethodCode.append(
                spaces + "int" + labelBrackets + " _label_" + opIDLabel + " = null;\n" +
                "\n"
            );
          }

          for(int i = 0; i < dim; i += 1) {
            if(hasLabel) {
              labelBrackets.delete(labelBrackets.length()-2, labelBrackets.length());

              this.replaceMethodCode.append(
                  spaces + "_label_" + opIDLabel + arrayAccess + " = new int[this." + childName + ".length]" + labelBrackets + ";\n" +
                  "\n"
              );
            }

            this.replaceMethodCode.append(spaces + "for(this._dim_" + i + " = 0; this._dim_" + i + " < this." + parentName + ".length; this._dim_" + i + " += 1) {\n");

            arrayAccess.append("[this._dim_" + i + "]");

            spaces.append("    ");
          }

          succeedingString = (conn.getIsActive() && conn.getOpID() != -1) ? "new OperatorIDTuple(_child, " + conn.getOpID() + ")" : "_child";

          if(hasLabel) {
            labelBrackets.delete(labelBrackets.length()-2, labelBrackets.length());

            this.replaceMethodCode.append(
                spaces + "int _label_" + opIDLabel + "_count = 0;\n" +
                spaces + "_label_" + opIDLabel + arrayAccess + " = new int[this." + childName + arrayAccess + ".length]" + labelBrackets + ";\n" +
                "\n"
            );
          }

          this.replaceMethodCode.append(spaces + "for(" + childOp.getClassType().getOpClass().getName() + " _child : this." + childName + arrayAccess + ") {\n");

          if(hasLabel) {
            this.replaceMethodCode.append(
                spaces + "    _label_" + opIDLabel + arrayAccess + "[_label_" + opIDLabel + "_count] = this." + parentName + arrayAccess + ".getOperatorIDTuple(_child).getId();\n" +
                spaces + "    _label_" + opIDLabel + "_count += 1;\n" +
                "\n"
            );
          }

          this.replaceMethodCode.append(
              spaces + "    this." + parentName + arrayAccess + ".removeSucceedingOperator(" + succeedingString + ");\n" +
              spaces + "    _child.removePrecedingOperator(this." + parentName + arrayAccess + ");\n" +
              spaces + "}\n" +
              "\n"
          );

          break;

        default:
          dim = this.variableList_left.get(parentName).getDimension();

          if(hasLabel) {
            for(int i = 0; i <= dim; i += 1) {
              labelBrackets.append("[]");
            }

            this.replaceMethodCode.append(
                spaces + "int" + labelBrackets + " _label_" + opIDLabel + " = null;\n" +
                "\n"
            );
          }

          for(int i = 0; i < dim; i += 1) {
            if(hasLabel) {
              labelBrackets.delete(labelBrackets.length()-2, labelBrackets.length());

              this.replaceMethodCode.append(
                  spaces + "_label_" + opIDLabel + arrayAccess + " = new int[this." + childName + ".length]" + labelBrackets + ";\n" +
                  "\n"
              );
            }

            this.replaceMethodCode.append(spaces + "for(this._dim_" + i + " = 0; this._dim_" + i + " < this." + parentName + ".length; this._dim_" + i + " += 1) {\n");

            arrayAccess.append("[this._dim_" + i + "]");

            spaces.append("    ");
          }

          succeedingString = (conn.getIsActive() && conn.getOpID() != -1) ? "new OperatorIDTuple(this." + childName + arrayAccess + ", " + conn.getOpID() + ")" : "this." + childName + arrayAccess;

          if(hasLabel) {
            labelBrackets.delete(labelBrackets.length()-2, labelBrackets.length());

            this.replaceMethodCode.append(
                spaces + "    _label_" + opIDLabel + arrayAccess + " = this." + parentName + arrayAccess + ".getOperatorIDTuple(this." + childName + arrayAccess + ").getId();\n" +
                "\n"
            );
          }

          this.replaceMethodCode.append(
              spaces + "this." + parentName + arrayAccess + ".removeSucceedingOperator(" + succeedingString + ");\n" +
              spaces + "this." + childName + arrayAccess + ".removePrecedingOperator(this." + parentName + arrayAccess + ");\n"
          );

          break;
        }

        for(int i = 0; i < dim; i += 1) {
          spaces.delete(spaces.length()-4, spaces.length());

          this.replaceMethodCode.append(spaces + "}\n");
        }
      }
      // --- remove all connections that only occur on the left side - end ---

      // --- add operators that only occur on the right side - begin ---
      this.replaceMethodCode.append(
          "\n" +
          spaces + "// add new operators...\n"
      );

      for(String opName : rightOperators) {
        AbstractRuleOperator op = rightOperatorsMap.get(opName);
        String opClass = op.getClassType().getOpClass().getName();
        VariableContainer vc = variableList_right.get(opName);
        int dim = vc.getDimension();
        StringBuffer arrayAccess = new StringBuffer();

        for(int i = 0; i < dim; i += 1) {
          arrayAccess.append("[]");
        }

        this.replaceMethodCode.append(spaces + opClass + arrayAccess + " " + opName + " = null;\n");

        arrayAccess = new StringBuffer();

        for(int i = 0; i < dim; i += 1) {
          this.replaceMethodCode.append(
              vc.initiate_next_dimension(spaces, i, this.getOpName(vc.getCountProvider(), rightOperators, true) + arrayAccess + ".length", false) +
              "\n" +
              spaces + "for(this._dim_" + i + " = 0; this._dim_" + i + " < " + opName + arrayAccess + ".length; this._dim_" + i + " += 1) {\n"
          );

          spaces.append("    ");
          arrayAccess.append("[this._dim_" + i + "]");
        }

        this.replaceMethodCode.append(spaces + opName + arrayAccess + " = new " + opClass + "();\n");

        if(this.generateStartMap) {
          this.replaceMethodCode.append(spaces + "this.addNodeToStartNodeMap(" + opName + arrayAccess + ", _startNodes);\n");
        }

        for(int i = 0; i < dim; i += 1) {
          spaces.delete(spaces.length()-4, spaces.length());

          this.replaceMethodCode.append(spaces + "}\n");
        }
      }

      this.replaceMethodCode.append("\n");
      // --- add operators that only occur on the right side - end ---

      // --- add connections that only occur on the right side - begin ---
      this.replaceMethodCode.append(
          "\n" +
          spaces + "// add new connections...\n"
      );

      for(ConnectionContainer conn : rightConnections) {
        AbstractRuleOperator parentOp = conn.getParent();
        AbstractRuleOperator childOp = conn.getChild();
        String parentName = this.getOpName(parentOp, rightOperators, false);
        String childName = this.getOpName(childOp, rightOperators, true);
        VariableContainer parentVC = variableList_right.get(this.getJumpOverName(parentOp, false));
        VariableContainer childVC = variableList_right.get(this.getJumpOverName(childOp, true));

        String opIDLabel = conn.getOpIDLabel();
        boolean hasLabel = conn.getIsActive() && !opIDLabel.equals("");

        int dim = 0;
        StringBuffer arrayAccess = new StringBuffer();
        String succeedingString = "";

        switch(conn.getMode()) {
        case ALL_PRECEDING:
          dim = childVC.getDimension();

          for(int i = 0; i < dim; i += 1) {
            this.replaceMethodCode.append(spaces + "for(this._dim_" + i + " = 0; this._dim_" + i + " < " + childName + ".length; this._dim_" + i + " += 1) {\n");

            arrayAccess.append("[this._dim_" + i + "]");

            spaces.append("    ");
          }

          if(conn.getIsActive()) {
            if(hasLabel) {
              succeedingString = "new OperatorIDTuple(" + childName + arrayAccess + ", _label_" + conn.getOpIDLabel() + arrayAccess + "[_label_" + opIDLabel + "_count])";

              this.replaceMethodCode.append(
                  spaces + "_label_" + opIDLabel + "_count = 0;\n" +
                  "\n"
              );
            }
            else {
              succeedingString = "new OperatorIDTuple(" + childName + arrayAccess + ", " + conn.getOpID() + ")";
            }
          }
          else {
            succeedingString = childName + arrayAccess;
          }

          this.replaceMethodCode.append(
              spaces + "for(" + parentOp.getClassType().getOpClass().getName() + " _parent : " + parentName + arrayAccess + ") {\n" +
              spaces + "    _parent.addSucceedingOperator(" + succeedingString + ");\n" +
              spaces + "    " + childName + arrayAccess + ".addPrecedingOperator(_parent);\n"
          );

          if(hasLabel) {
            this.replaceMethodCode.append(
                "\n" +
                spaces + "    _label_" + opIDLabel + "_count += 1;\n"
            );
          }

          this.replaceMethodCode.append(
              spaces + "}\n" +
              "\n"
          );

          break;

        case ALL_SUCCEEDING:
          dim = parentVC.getDimension();

          for(int i = 0; i < dim; i += 1) {
            this.replaceMethodCode.append(spaces + "for(this._dim_" + i + " = 0; this._dim_" + i + " < " + parentName + ".length; this._dim_" + i + " += 1) {\n");

            arrayAccess.append("[this._dim_" + i + "]");

            spaces.append("    ");
          }

          if(conn.getIsActive()) {
            if(hasLabel) {
              succeedingString = "new OperatorIDTuple(_child, _label_" + conn.getOpIDLabel() + arrayAccess + "[_label_" + opIDLabel + "_count])";

              this.replaceMethodCode.append(
                  spaces + "_label_" + opIDLabel + "_count = 0;\n" +
                  "\n"
              );
            }
            else {
              succeedingString = "new OperatorIDTuple(_child, " + conn.getOpID() + ")";
            }
          }
          else {
            succeedingString = "_child";
          }

          this.replaceMethodCode.append(
              spaces + "for(" + childOp.getClassType().getOpClass().getName() + " _child : " + childName + arrayAccess + ") {\n" +
              spaces + "    " + parentName + arrayAccess + ".addSucceedingOperator(" + succeedingString + ");\n" +
              spaces + "    _child.addPrecedingOperator(" + parentName + arrayAccess + ");\n"
          );

          if(hasLabel) {
View Full Code Here

  private HashMap<String, AbstractRuleOperator> getOperatorsMap(VisualGraph<Operator> vg) {
    HashMap<String, AbstractRuleOperator> operators = new HashMap<String, AbstractRuleOperator>();

    for(GraphWrapper gw : vg.getBoxes().keySet()) {
      AbstractRuleOperator op = (AbstractRuleOperator) gw.getElement();

      operators.put(op.getName(), op);
    }

    return operators;
  }
View Full Code Here

    if(precedingOperators.size() > 0) {
      boolean added = false;
      int precedingIndex = 0;

      for(int i = 0; i < precedingOperators.size(); i += 1) {
        AbstractRuleOperator precOp = (AbstractRuleOperator) precedingOperators.get(i);


        HashSet<Operator> connectionNodes = visitedConnections.get(precOp);

        if(connectionNodes == null) {
          connectionNodes = new HashSet<Operator>();
          visitedConnections.put(precOp, connectionNodes);
        }
        else if(connectionNodes.contains(node)) {
          continue;
        }

        connectionNodes.add(node);


        if(!added) {
          buffer.append(
              "\n" +
              spaces + "List<BasicOperator> _precedingOperators_" + runNumber + "_" + i + " = " + nodeName + ".getPrecedingOperators();\n" +
              "\n"
          );

          added = true;
          precedingIndex = i;
        }


        AnnotationPanel panel = (AnnotationPanel) precOp.getAnnotationLabel(node);

        switch(panel.getMode()) {
        case ONLY_PRECEDING_AND_SUCCEEDING:
        case ONLY_PRECEDING:
          if(node.getClass() == JumpOverOperator.class) {
            buffer.append(
                spaces + "if(" + testName + " != " + originalNodeName + ") {\n"
            );

            spaces.append("    ");
          }

          buffer.append(
              spaces + "if(_precedingOperators_" + runNumber + "_" + precedingIndex + ".size() != 1) {\n" +
              spaces + "    " + ((runNumber != 1) ? "continue" : "return false") + ";\n" +
              spaces + "}\n"
          );

          if(node.getClass() == JumpOverOperator.class) {
            spaces.delete(spaces.length()-4, spaces.length());

            buffer.append(spaces + "}\n");
          }

          break;

        case ALL_PRECEDING:
          buffer.append(
              "\n" +
              spaces + "this._dim_" + currentDimension + " = -1;\n"
          );

          for(String variable : this.get_variables_for_next_dimension(precOp, true)) {
            VariableContainer vc = this.variableList_left.get(variable);

            buffer.append(vc.initiate_next_dimension(spaces, currentDimension, "_precedingOperators_" + runNumber + "_" + precedingIndex + ".size()", true));
          }

          break;
        }

        buffer.append(
            "\n" +
            spaces + "for(BasicOperator _precOp_" + runNumber + "_" + i + " : _precedingOperators_" + runNumber + "_" + precedingIndex + ") {\n"
        );

        bracesCount++;
        spaces.append("    ");

        switch(panel.getMode()) {
        case ALL_PRECEDING:
          buffer.append(
              spaces + "this._dim_" + currentDimension + " += 1;\n" +
              "\n"
          );
          break;
        }

        if(panel.isActive()) {
          int opID = panel.getOpID();

          if(opID != -1) {
            buffer.append(
                spaces + "if(_precOp_" + runNumber + "_" + i + ".getOperatorIDTuple(" + nodeName + ").getId() != " + opID + ") {\n" +
                spaces + "    continue;\n" +
                spaces + "}\n" +
                "\n"
            );
          }
        }

        String nextOpName = "_precOp_" + runNumber + "_" + i;
        testName = "";

        switch(panel.getMode()) {
        default:
        case EXISTS:
          if(precOp.getClass() == JumpOverOperator.class) {
            String[] data = this.handleJumpOverOperator(spaces, buffer, (JumpOverOperator) precOp, nextOpName, runNumber, 0, true);
            nextOpName = data[0];
            testName = data[1];
          }

          bracesCount += this.manage_node(spaces, buffer, precOp, nextOpName, visitedNodes, visitedConnections, runNumber, currentDimension, testName);

          break;
        case ALL_PRECEDING:
          buffer.append(
              spaces + "if(!this._checkPrivate" + this.count_private + "(" + nextOpName + ")) {\n" +
              spaces + "    return false;\n" +
              spaces + "}\n"
          );

          this.generate_checkPrivate(precOp, visitedNodes, visitedConnections, currentDimension+1);

          spaces.delete(spaces.length()-4, spaces.length());

          buffer.append(spaces + "}\n");
          bracesCount -= 1;

          break;
        case ALL_SUCCEEDING:
          System.err.println("WARNING: This case should never happen!");

          break;
        case ONLY_PRECEDING_AND_SUCCEEDING:
        case ONLY_SUCCEEDING:
          buffer.append(
              spaces + "if(" + nextOpName + ".getSucceedingOperators().size() != 1) {\n" +
              spaces + "    break;\n" +
              spaces + "}\n" +
              "\n"
          );

          if(precOp.getClass() == JumpOverOperator.class) {
            String[] data = this.handleJumpOverOperator(spaces, buffer, (JumpOverOperator) precOp, nextOpName, runNumber, 0, true);
            nextOpName = data[0];
            testName = data[1];
          }

          bracesCount += this.manage_node(spaces, buffer, precOp, nextOpName, visitedNodes, visitedConnections, runNumber, currentDimension, testName);

          break;
        }
      }
    }


    LinkedList<OperatorIDTuple<Operator>> succedingOperators = node.getSucceedingOperators();

    if(succedingOperators.size() > 0) {
      boolean added = false;
      int succedingIndex = 0;

      for(int i = 0; i < succedingOperators.size(); i += 1) {
        OperatorIDTuple<Operator> sucOpIDTup = succedingOperators.get(i);
        AbstractRuleOperator sucOp = (AbstractRuleOperator) sucOpIDTup.getOperator();


        HashSet<Operator> connectionNodes = visitedConnections.get(node);

        if(connectionNodes == null) {
          connectionNodes = new HashSet<Operator>();
          visitedConnections.put(node, connectionNodes);
        }
        else if(connectionNodes.contains(sucOp)) {
          continue;
        }

        connectionNodes.add(sucOp);


        if(!added) {
          buffer.append(
              "\n" +
              spaces + "List<OperatorIDTuple> _succedingOperators_" + runNumber + "_" + i + " = " + nodeName + ".getSucceedingOperators();\n" +
              "\n"
          );

          added = true;
          succedingIndex = i;
        }


        AnnotationPanel panel = (AnnotationPanel) node.getAnnotationLabel(sucOp);

        switch(panel.getMode()) {
        case ONLY_PRECEDING_AND_SUCCEEDING:
        case ONLY_SUCCEEDING:
          buffer.append(
              spaces + "if(_succedingOperators_" + runNumber + "_" + succedingIndex + ".size() != 1) {\n" +
              spaces + "    " + ((runNumber != 1) ? "continue" : "return false") + ";\n" +
              spaces + "}\n"
          );

          break;


        case ALL_SUCCEEDING:
          buffer.append(
              "\n" +
              spaces + "this._dim_" + currentDimension + " = -1;\n"
          );

          for(String variable : this.get_variables_for_next_dimension(sucOp, false)) {
            VariableContainer vc = this.variableList_left.get(variable);

            buffer.append(vc.initiate_next_dimension(spaces, currentDimension, "_succedingOperators_" + runNumber + "_" + succedingIndex + ".size()", true));
          }

          break;
        }


        buffer.append(
            "\n" +
            spaces + "for(OperatorIDTuple _sucOpIDTup_" + runNumber + "_" + i + " : _succedingOperators_" + runNumber + "_" + succedingIndex + ") {\n"
        );

        bracesCount++;
        spaces.append("    ");

        switch(panel.getMode()) {
        case ALL_SUCCEEDING:
          buffer.append(
              spaces + "this._dim_" + currentDimension + " += 1;\n" +
              "\n"
          );
          break;
        }


        if(panel.isActive()) {
          int opID = panel.getOpID();

          if(opID != -1) {
            buffer.append(
                spaces + "if(_sucOpIDTup_" + runNumber + "_" + i + ".getId() != " + opID + ") {\n" +
                spaces + "    continue;\n" +
                spaces + "}\n" +
                "\n"
            );
          }
        }

        String nextOpName = "_sucOpIDTup_" + runNumber + "_" + i + ".getOperator()";
        testName = "";

        switch(panel.getMode()) {
        default:
        case EXISTS:
          if(sucOp.getClass() == JumpOverOperator.class) {
            String[] data = this.handleJumpOverOperator(spaces, buffer, (JumpOverOperator) sucOp, nextOpName, runNumber, 0, false);
            nextOpName = data[0];
            testName = data[1];
          }

          bracesCount += this.manage_node(spaces, buffer, sucOp, nextOpName, visitedNodes, visitedConnections, runNumber, currentDimension, testName);

          break;
        case ALL_SUCCEEDING:
          buffer.append(
              spaces + "if(!this._checkPrivate" + this.count_private + "(" + nextOpName + ")) {\n" +
              spaces + "    return false;\n" +
              spaces + "}\n"
          );

          this.generate_checkPrivate(sucOp, visitedNodes, visitedConnections, currentDimension+1);

          spaces.delete(spaces.length()-4, spaces.length());

          buffer.append(spaces + "}\n");
          bracesCount -= 1;

          break;
        case ALL_PRECEDING:
          System.err.println("WARNING: This case should never happen!");

          break;
        case ONLY_PRECEDING_AND_SUCCEEDING:
        case ONLY_PRECEDING:
          buffer.append(
              spaces + "if(" + nextOpName + ".getPrecedingOperators().size() != 1) {\n" +
              spaces + "    break;\n" +
              spaces + "}\n" +
              "\n"
          );

          if(sucOp.getClass() == JumpOverOperator.class) {
            String[] data = this.handleJumpOverOperator(spaces, buffer, (JumpOverOperator) sucOp, nextOpName, runNumber, 0, false);
            nextOpName = data[0];
            testName = data[1];
          }
View Full Code Here

TOP

Related Classes of lupos.gui.operatorgraph.visualeditor.ruleeditor.operators.AbstractRuleOperator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.