1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| package org.deri.wsmo4j.logicalexpression; |
17 |
| |
18 |
| |
19 |
| import java.util.List; |
20 |
| import java.util.Vector; |
21 |
| |
22 |
| import org.deri.wsmo4j.logicalexpression.util.ExpressionContainmentUtil; |
23 |
| import org.deri.wsmo4j.logicalexpression.util.SetUtil; |
24 |
| import org.omwg.logicalexpression.*; |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| public abstract class BinaryImpl extends LogicalExpressionImpl |
36 |
| implements Binary { |
37 |
| |
38 |
| protected LogicalExpression exprLeft; |
39 |
| |
40 |
| protected LogicalExpression exprRight; |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
| |
46 |
| |
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
0
| public BinaryImpl(LogicalExpression exprLeft, LogicalExpression exprRight)
|
52 |
| throws IllegalArgumentException { |
53 |
0
| if (exprLeft == null || exprRight == null) {
|
54 |
0
| throw new IllegalArgumentException("null not allowed for Arguments of Binary operator");
|
55 |
| } |
56 |
0
| if (ExpressionContainmentUtil.contains(exprLeft, Constraint.class)
|
57 |
| || ExpressionContainmentUtil.contains(exprRight, Constraint.class)) { |
58 |
0
| throw new IllegalArgumentException("Nested Constraint not allowed in Binary Operator");
|
59 |
| } |
60 |
0
| this.exprLeft = exprLeft;
|
61 |
0
| this.exprRight = exprRight;
|
62 |
| } |
63 |
| |
64 |
0
| public LogicalExpression getLeftOperand() {
|
65 |
0
| return exprLeft;
|
66 |
| } |
67 |
| |
68 |
0
| public LogicalExpression getRightOperand() {
|
69 |
0
| return exprRight;
|
70 |
| } |
71 |
| |
72 |
| |
73 |
| |
74 |
| |
75 |
0
| public List <LogicalExpression> listOperands() {
|
76 |
0
| Vector <LogicalExpression> ret = new Vector <LogicalExpression>();
|
77 |
0
| ret.add(exprLeft);
|
78 |
0
| ret.add(exprRight);
|
79 |
0
| return ret;
|
80 |
| } |
81 |
| |
82 |
0
| public int hashCode() {
|
83 |
0
| return exprLeft.hashCode() + exprRight.hashCode();
|
84 |
| } |
85 |
| |
86 |
| |
87 |
| |
88 |
| |
89 |
0
| public void setLeftOperand(LogicalExpression le) {
|
90 |
0
| if (le == null) {
|
91 |
0
| throw new IllegalArgumentException("null not allowed for Arguments of Binary operator");
|
92 |
| } |
93 |
0
| if (ExpressionContainmentUtil.contains(le, Constraint.class)) {
|
94 |
0
| throw new IllegalArgumentException("Nested Constraint not allowed in Binary Operator");
|
95 |
| } |
96 |
0
| exprLeft = le;
|
97 |
| |
98 |
| } |
99 |
| |
100 |
| |
101 |
| |
102 |
| |
103 |
0
| public void setRightOperand(LogicalExpression le) {
|
104 |
0
| if (le == null) {
|
105 |
0
| throw new IllegalArgumentException("null not allowed for Arguments of Binary operator");
|
106 |
| } |
107 |
0
| if (ExpressionContainmentUtil.contains(le, Constraint.class)) {
|
108 |
0
| throw new IllegalArgumentException("Nested Constraint not allowed in Binary Operator");
|
109 |
| } |
110 |
0
| exprRight = le;
|
111 |
| } |
112 |
| |
113 |
| |
114 |
| |
115 |
| |
116 |
0
| public void setOperands(List operands) {
|
117 |
0
| if (operands.size()!=2){
|
118 |
0
| throw new IllegalArgumentException("For a Binary Operator exactly 2 expressions are necessary!");
|
119 |
| } |
120 |
0
| if (!SetUtil.allOfType(operands, LogicalExpression.class)){
|
121 |
0
| throw new IllegalArgumentException("Operands of a Binary must be Logical Expressions!!");
|
122 |
| } |
123 |
0
| setLeftOperand((LogicalExpression)operands.get(0));
|
124 |
0
| setRightOperand((LogicalExpression)operands.get(1));
|
125 |
| } |
126 |
| } |