Skip to content

Package: ForEachNode

ForEachNode

nameinstructionbranchcomplexitylinemethod
ForEachNode(AbstractNode, AbstractNode, AbstractNode)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
equals(Object)
M: 0 C: 11
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
hashCode()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
interpret(CommunicationManager)
M: 0 C: 107
100%
M: 0 C: 10
100%
M: 0 C: 6
100%
M: 0 C: 20
100%
M: 0 C: 1
100%
iteration(CommunicationManager, String, AbstractReturnValue, String)
M: 0 C: 43
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
toString()
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: package pruefskript.parser.nodes;
2:
3: import java.util.ArrayList;
4: import java.util.List;
5: import java.util.Locale;
6:
7: import basic.PruefskriptConstants;
8: import pruefskript.CommunicationManager;
9: import pruefskript.parser.exceptions.CheckScriptException;
10: import pruefskript.parser.exceptions.WrongNodeException;
11: import pruefskript.parser.values.AbstractReturnValue;
12: import pruefskript.parser.values.ArrayValue;
13: import pruefskript.parser.values.VoidValue;
14:
15: /**
16: * ForEachNode.
17: *
18: * @author Group B5
19: *
20: */
21: public class ForEachNode extends AbstractTrinaryOperationNode {
22:         /**
23:          * ForEachNode.
24:          *
25:          * @param operand1
26:          * AbstractNode
27:          * @param operand2
28:          * AbstractNode
29:          * @param operand3
30:          * AbstractNode
31:          */
32:         public ForEachNode(final AbstractNode operand1, final AbstractNode operand2,
33:                         final AbstractNode operand3) {
34:                 super(operand1, operand2, operand3);
35:         }
36:
37:         @Override
38:         public String toString() {
39:                 return PruefskriptConstants.FOREACHTITLE + PruefskriptConstants.BRACKET_OPEN
40:                                 + super.toString() + PruefskriptConstants.BRACKET_CLOSE;
41:         }
42:
43:         @Override
44:         public boolean equals(final Object obj) {
45:•                return super.equals(obj) && obj instanceof ForEachNode;
46:
47:         }
48:
49:         @Override
50:         public int hashCode() {
51:                 return super.hashCode() + PruefskriptConstants.FOR_EACHNODE_HASHCODE;
52:         }
53:
54:         @Override
55:         public VoidValue interpret(final CommunicationManager mgr) throws CheckScriptException {
56:•                if (this.getOperand1().isIDNode()) {
57:                         final String idName = this.getOperand1().toIDNode().getName();
58:•                        if (this.getOperand2().isIDNode()) {
59:                                 final IDNode idnode = this.getOperand2().toIDNode();
60:                                 final List<AbstractReturnValue> list = new ArrayList<AbstractReturnValue>();
61:                                 list.add(idnode.interpret(mgr));
62:                                 iteration(mgr, idName, new ArrayValue(list), idnode.getName());
63:•                        } else if (this.getOperand2().isIDSetNode()) {
64:                                 final IdSetNode idSetNode = this.getOperand2().toIDSetNode();
65:                                 iteration(mgr, idName, idSetNode.interpret(mgr), idSetNode.getName());
66:•                        } else if (this.getOperand2().isIdSetArrayNode()) {
67:                                 final List<IdSetNode> list = this.getOperand2().toIdSetArrayNode().getIdSets();
68:•                                for (int i = 0; i < list.size(); i++) {
69:                                         final IdSetNode idSet = list.get(i);
70:                                         iteration(mgr, idName, idSet.interpret(mgr), idSet.getName());
71:                                 }
72:                         } else {
73:                                 throw new WrongNodeException(PruefskriptConstants.UNEXPECTED_ARRAY);
74:                         }
75:                 } else {
76:                         throw new WrongNodeException(PruefskriptConstants.UNEXPECTED_FOR_EACH);
77:                 }
78:                 return new VoidValue();
79:         }
80:
81:         /**
82:          * iteration over one idSet.
83:          *
84:          * @param mgr
85:          * The {@link CommunicationManager} to use.
86:          * @param idName
87:          * is the Name of the "runIndex".
88:          * @param arrayValue
89:          * is the arrayValue for the iteration.
90:          * @param idSetName
91:          * is the name of the iterated array,
92:          * @throws CheckScriptException
93:          * if there is any Problem.
94:          */
95:         private void iteration(final CommunicationManager mgr, final String idName,
96:                         final AbstractReturnValue arrayValue, final String idSetName)
97:                         throws CheckScriptException {
98:                 final java.util.Iterator<AbstractReturnValue> i =
99:                                 arrayValue.toArrayValue().getValues().iterator();
100:                 int j = 1; // Laufindex
101:•                while (i.hasNext()) {
102:                         final AbstractReturnValue tempValue = i.next();
103:                         final IteratorHelper laufVar = new IteratorHelper(idName, idSetName, j);
104:                         tempValue.getIterationVars().put(idName.toUpperCase(Locale.ENGLISH), laufVar);
105:                         mgr.addValue(basic.PruefskriptConstants.FOREACHTITLE, idName, tempValue);
106:                         this.getOperand3().interpret(mgr);
107:                         j++;
108:                 }
109:         }
110: }