diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Master/Software Architektur/SWA_Prakt2 | |
| download | Studium-master.tar.gz Studium-master.tar.bz2 | |
Diffstat (limited to 'Master/Software Architektur/SWA_Prakt2')
13 files changed, 745 insertions, 0 deletions
diff --git a/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticAddition.java b/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticAddition.java new file mode 100644 index 0000000..6565e43 --- /dev/null +++ b/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticAddition.java @@ -0,0 +1,134 @@ +package net.sven_eisenhauer.swa_prakt1;
+
+public class ArithmeticAddition extends ArithmeticOperation {
+
+ public ArithmeticAddition(ArithmeticExpression operand1,
+ ArithmeticExpression operand2) {
+ super(operand1, operand2);
+ operationSign="+";
+ }
+/* @Override
+ public Number evaluate() {
+ Number res = null;
+ Number num1 = operand1.evaluate();
+ Number num2 = operand2.evaluate();
+
+ if(num1 instanceof Integer && num2 instanceof Integer) {
+ res = num1.intValue() + num2.intValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Long) {
+ res = num1.intValue() + num2.longValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Short) {
+ res = num1.intValue() + num2.shortValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Float) {
+ res = num1.intValue() + num2.floatValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Double) {
+ res = num1.intValue() + num2.doubleValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Byte) {
+ res = num1.intValue() + num2.byteValue();
+ }
+
+ else if(num1 instanceof Byte && num2 instanceof Long) {
+ res = num1.byteValue() + num2.longValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Short) {
+ res = num1.byteValue() + num2.shortValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Float) {
+ res = num1.byteValue() + num2.floatValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Double) {
+ res = num1.byteValue() + num2.doubleValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Byte) {
+ res = num1.byteValue() + num2.byteValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Integer) {
+ res = num1.byteValue() + num2.intValue();
+ }
+
+ else if(num1 instanceof Short && num2 instanceof Long) {
+ res = num1.shortValue() + num2.longValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Short) {
+ res = num1.shortValue() + num2.shortValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Float) {
+ res = num1.shortValue() + num2.floatValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Double) {
+ res = num1.shortValue() + num2.doubleValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Byte) {
+ res = num1.shortValue() + num2.byteValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Integer) {
+ res = num1.shortValue() + num2.intValue();
+ }
+
+ else if(num1 instanceof Long && num2 instanceof Long) {
+ res = num1.longValue() + num2.longValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Short) {
+ res = num1.longValue() + num2.shortValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Float) {
+ res = num1.longValue() + num2.floatValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Double) {
+ res = num1.longValue() + num2.doubleValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Byte) {
+ res = num1.longValue() + num2.byteValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Integer) {
+ res = num1.longValue() + num2.intValue();
+ }
+
+ else if(num1 instanceof Float && num2 instanceof Long) {
+ res = num1.floatValue() + num2.longValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Short) {
+ res = num1.floatValue() + num2.shortValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Float) {
+ res = num1.floatValue() + num2.floatValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Double) {
+ res = num1.floatValue() + num2.doubleValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Byte) {
+ res = num1.floatValue() + num2.byteValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Integer) {
+ res = num1.floatValue() + num2.intValue();
+ }
+
+ else if(num1 instanceof Double && num2 instanceof Long) {
+ res = num1.doubleValue() + num2.longValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Short) {
+ res = num1.doubleValue() + num2.shortValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Float) {
+ res = num1.doubleValue() + num2.floatValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Double) {
+ res = num1.doubleValue() + num2.doubleValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Byte) {
+ res = num1.doubleValue() + num2.byteValue();
+ } else if(num1 instanceof Double && num2 instanceof Integer) {
+ res = num1.doubleValue() + num2.intValue();
+ }
+ return res;
+ }*/
+ @Override
+ public Number doOperation(Number opLeft, Number opRight) {
+ return opLeft.doubleValue()+opRight.doubleValue();
+ }
+}
diff --git a/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticDivision.java b/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticDivision.java new file mode 100644 index 0000000..eed617f --- /dev/null +++ b/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticDivision.java @@ -0,0 +1,134 @@ +package net.sven_eisenhauer.swa_prakt1;
+
+public class ArithmeticDivision extends ArithmeticOperation {
+
+ public ArithmeticDivision(ArithmeticExpression operand1,
+ ArithmeticExpression operand2) {
+ super(operand1, operand2);
+ operationSign="/";
+ }
+
+/* public Number evaluate() {
+ Number res = null;
+ Number num1 = operand1.evaluate();
+ Number num2 = operand2.evaluate();
+
+ if(num1 instanceof Integer && num2 instanceof Integer) {
+ res = num1.intValue() / num2.intValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Long) {
+ res = num1.intValue() / num2.longValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Short) {
+ res = num1.intValue() / num2.shortValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Float) {
+ res = num1.intValue() / num2.floatValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Double) {
+ res = num1.intValue() / num2.doubleValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Byte) {
+ res = num1.intValue() / num2.byteValue();
+ }
+
+ else if(num1 instanceof Byte && num2 instanceof Long) {
+ res = num1.byteValue() / num2.longValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Short) {
+ res = num1.byteValue() / num2.shortValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Float) {
+ res = num1.byteValue() / num2.floatValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Double) {
+ res = num1.byteValue() / num2.doubleValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Byte) {
+ res = num1.byteValue() / num2.byteValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Integer) {
+ res = num1.byteValue() / num2.intValue();
+ }
+
+ else if(num1 instanceof Short && num2 instanceof Long) {
+ res = num1.shortValue() / num2.longValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Short) {
+ res = num1.shortValue() / num2.shortValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Float) {
+ res = num1.shortValue() / num2.floatValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Double) {
+ res = num1.shortValue() / num2.doubleValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Byte) {
+ res = num1.shortValue() / num2.byteValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Integer) {
+ res = num1.shortValue() / num2.intValue();
+ }
+
+ else if(num1 instanceof Long && num2 instanceof Long) {
+ res = num1.longValue() / num2.longValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Short) {
+ res = num1.longValue() / num2.shortValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Float) {
+ res = num1.longValue() / num2.floatValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Double) {
+ res = num1.longValue() / num2.doubleValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Byte) {
+ res = num1.longValue() / num2.byteValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Integer) {
+ res = num1.longValue() / num2.intValue();
+ }
+
+ else if(num1 instanceof Float && num2 instanceof Long) {
+ res = num1.floatValue() / num2.longValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Short) {
+ res = num1.floatValue() / num2.shortValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Float) {
+ res = num1.floatValue() / num2.floatValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Double) {
+ res = num1.floatValue() / num2.doubleValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Byte) {
+ res = num1.floatValue() / num2.byteValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Integer) {
+ res = num1.floatValue() / num2.intValue();
+ }
+
+ else if(num1 instanceof Double && num2 instanceof Long) {
+ res = num1.doubleValue() / num2.longValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Short) {
+ res = num1.doubleValue() / num2.shortValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Float) {
+ res = num1.doubleValue() / num2.floatValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Double) {
+ res = num1.doubleValue() / num2.doubleValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Byte) {
+ res = num1.doubleValue() / num2.byteValue();
+ } else if(num1 instanceof Double && num2 instanceof Integer) {
+ res = num1.doubleValue() / num2.intValue();
+ }
+ return res;
+ }*/
+ @Override
+ public Number doOperation(Number opLeft, Number opRight) {
+ return opLeft.doubleValue()/opRight.doubleValue();
+ }
+}
diff --git a/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticExpression.java b/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticExpression.java new file mode 100644 index 0000000..393f2ac --- /dev/null +++ b/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticExpression.java @@ -0,0 +1,6 @@ +package net.sven_eisenhauer.swa_prakt1;
+
+public interface ArithmeticExpression {
+ //public void print();
+ //public Number evaluate();
+}
diff --git a/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticIterator.java b/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticIterator.java new file mode 100644 index 0000000..371ce61 --- /dev/null +++ b/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticIterator.java @@ -0,0 +1,6 @@ +package net.sven_eisenhauer.swa_prakt1; + +public interface ArithmeticIterator { + public void print(); + public Number evaluate(); +} diff --git a/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticMultiplication.java b/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticMultiplication.java new file mode 100644 index 0000000..268d338 --- /dev/null +++ b/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticMultiplication.java @@ -0,0 +1,138 @@ +package net.sven_eisenhauer.swa_prakt1;
+
+public class ArithmeticMultiplication extends ArithmeticOperation {
+
+
+
+ public ArithmeticMultiplication(ArithmeticExpression operand1,
+ ArithmeticExpression operand2) {
+ super(operand1, operand2);
+ operationSign = "*";
+ }
+ /*
+ @Override
+ public Number evaluate() {
+ Number res = null;
+ Number num1 = operand1.evaluate();
+ Number num2 = operand2.evaluate();
+
+ if(num1 instanceof Integer && num2 instanceof Integer) {
+ res = num1.intValue() * num2.intValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Long) {
+ res = num1.intValue() * num2.longValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Short) {
+ res = num1.intValue() * num2.shortValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Float) {
+ res = num1.intValue() * num2.floatValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Double) {
+ res = num1.intValue() * num2.doubleValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Byte) {
+ res = num1.intValue() * num2.byteValue();
+ }
+
+ else if(num1 instanceof Byte && num2 instanceof Long) {
+ res = num1.byteValue() * num2.longValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Short) {
+ res = num1.byteValue() * num2.shortValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Float) {
+ res = num1.byteValue() * num2.floatValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Double) {
+ res = num1.byteValue() * num2.doubleValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Byte) {
+ res = num1.byteValue() * num2.byteValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Integer) {
+ res = num1.byteValue() * num2.intValue();
+ }
+
+ else if(num1 instanceof Short && num2 instanceof Long) {
+ res = num1.shortValue() * num2.longValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Short) {
+ res = num1.shortValue() * num2.shortValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Float) {
+ res = num1.shortValue() * num2.floatValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Double) {
+ res = num1.shortValue() * num2.doubleValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Byte) {
+ res = num1.shortValue() * num2.byteValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Integer) {
+ res = num1.shortValue() * num2.intValue();
+ }
+
+ else if(num1 instanceof Long && num2 instanceof Long) {
+ res = num1.longValue() * num2.longValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Short) {
+ res = num1.longValue() * num2.shortValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Float) {
+ res = num1.longValue() * num2.floatValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Double) {
+ res = num1.longValue() * num2.doubleValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Byte) {
+ res = num1.longValue() * num2.byteValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Integer) {
+ res = num1.longValue() * num2.intValue();
+ }
+
+ else if(num1 instanceof Float && num2 instanceof Long) {
+ res = num1.floatValue() * num2.longValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Short) {
+ res = num1.floatValue() * num2.shortValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Float) {
+ res = num1.floatValue() * num2.floatValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Double) {
+ res = num1.floatValue() * num2.doubleValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Byte) {
+ res = num1.floatValue() * num2.byteValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Integer) {
+ res = num1.floatValue() * num2.intValue();
+ }
+
+ else if(num1 instanceof Double && num2 instanceof Long) {
+ res = num1.doubleValue() * num2.longValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Short) {
+ res = num1.doubleValue() * num2.shortValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Float) {
+ res = num1.doubleValue() * num2.floatValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Double) {
+ res = num1.doubleValue() * num2.doubleValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Byte) {
+ res = num1.doubleValue() * num2.byteValue();
+ } else if(num1 instanceof Double && num2 instanceof Integer) {
+ res = num1.doubleValue() * num2.intValue();
+ }
+
+ return res;
+ }*/
+ @Override
+ public Number doOperation(Number opLeft, Number opRight) {
+ return opLeft.doubleValue()*opRight.doubleValue();
+ }
+}
diff --git a/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticOperation.java b/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticOperation.java new file mode 100644 index 0000000..5bcad84 --- /dev/null +++ b/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticOperation.java @@ -0,0 +1,30 @@ +package net.sven_eisenhauer.swa_prakt1;
+
+public abstract class ArithmeticOperation implements ArithmeticExpression{
+ protected ArithmeticExpression operand1;
+ protected ArithmeticExpression operand2;
+ protected String operationSign;
+ public ArithmeticOperation(ArithmeticExpression operand1
+ ,ArithmeticExpression operand2){
+ this.operand1 = operand1;
+ this.operand2 = operand2;
+ }/*
+ @Override
+ public void print() {
+ System.out.print("(");
+ operand1.print();
+ System.out.print(operationSign);
+ operand2.print();
+ System.out.print(")");
+ }*/
+ public String getOperationSign() {
+ return operationSign;
+ }
+ public ArithmeticExpression getLeftOperand() {
+ return operand1;
+ }
+ public ArithmeticExpression getRightOperand() {
+ return operand2;
+ }
+ public abstract Number doOperation(Number opLeft, Number opRight);
+}
diff --git a/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticRunner.java b/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticRunner.java new file mode 100644 index 0000000..4991041 --- /dev/null +++ b/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticRunner.java @@ -0,0 +1,44 @@ +package net.sven_eisenhauer.swa_prakt1;
+
+public class ArithmeticRunner {
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ ArithmeticVariable a = new ArithmeticVariable("a", 2);
+ ArithmeticVariable b = new ArithmeticVariable("b", 77);
+ ArithmeticVariable c = new ArithmeticVariable("c", 0.1);
+ ArithmeticVariable d = new ArithmeticVariable("d", 0.00003);
+
+ ArithmeticExpression aAddb = new ArithmeticAddition(a,b);
+ ArithmeticExpression aSubc = new ArithmeticSubstraction(a,c);
+ ArithmeticExpression bMuld = new ArithmeticMultiplication(b, d);
+
+ ArithmeticExpression ae1 = new ArithmeticMultiplication(aAddb, aSubc);
+ ArithmeticExpression ae2 = new ArithmeticSubstraction(bMuld, a);
+
+ ArithmeticExpression root = new ArithmeticAddition(ae1, ae2);
+ /*
+ try {
+ root.print();
+ System.out.println("\nResult: "+root.evaluate());
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ */
+ try {/*
+ ArithmeticIterator iter = new ExpressionIterator(root);
+ iter.print();
+ System.out.println("\n");
+ iter = new ExpressionIterator(root);
+ System.out.println("\nEvaluate: "+iter.evaluate()+"\n");
+ */
+ new PrintIter().traverse(root);
+ System.out.println("\n"+new EvalIter().traverse(root));
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+
+}
diff --git a/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticSubstraction.java b/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticSubstraction.java new file mode 100644 index 0000000..92a9bca --- /dev/null +++ b/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticSubstraction.java @@ -0,0 +1,137 @@ +package net.sven_eisenhauer.swa_prakt1;
+
+public class ArithmeticSubstraction extends ArithmeticOperation {
+
+ public ArithmeticSubstraction(ArithmeticExpression operand1,
+ ArithmeticExpression operand2) {
+ super(operand1, operand2);
+ operationSign = "-";
+ }
+/*
+ @Override
+ public Number evaluate() {
+ Number res = null;
+ Number num1 = operand1.evaluate();
+ Number num2 = operand2.evaluate();
+
+ if(num1 instanceof Integer && num2 instanceof Integer) {
+ res = num1.intValue() -num2.intValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Long) {
+ res = num1.intValue() -num2.longValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Short) {
+ res = num1.intValue() -num2.shortValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Float) {
+ res = num1.intValue() -num2.floatValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Double) {
+ res = num1.intValue() -num2.doubleValue();
+ }
+ else if(num1 instanceof Integer && num2 instanceof Byte) {
+ res = num1.intValue() -num2.byteValue();
+ }
+
+ else if(num1 instanceof Byte && num2 instanceof Long) {
+ res = num1.byteValue() -num2.longValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Short) {
+ res = num1.byteValue() -num2.shortValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Float) {
+ res = num1.byteValue() -num2.floatValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Double) {
+ res = num1.byteValue() -num2.doubleValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Byte) {
+ res = num1.byteValue() -num2.byteValue();
+ }
+ else if(num1 instanceof Byte && num2 instanceof Integer) {
+ res = num1.byteValue() -num2.intValue();
+ }
+
+ else if(num1 instanceof Short && num2 instanceof Long) {
+ res = num1.shortValue() -num2.longValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Short) {
+ res = num1.shortValue() -num2.shortValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Float) {
+ res = num1.shortValue() -num2.floatValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Double) {
+ res = num1.shortValue() -num2.doubleValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Byte) {
+ res = num1.shortValue() -num2.byteValue();
+ }
+ else if(num1 instanceof Short && num2 instanceof Integer) {
+ res = num1.shortValue() -num2.intValue();
+ }
+
+ else if(num1 instanceof Long && num2 instanceof Long) {
+ res = num1.longValue() -num2.longValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Short) {
+ res = num1.longValue() -num2.shortValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Float) {
+ res = num1.longValue() -num2.floatValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Double) {
+ res = num1.longValue() -num2.doubleValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Byte) {
+ res = num1.longValue() -num2.byteValue();
+ }
+ else if(num1 instanceof Long && num2 instanceof Integer) {
+ res = num1.longValue() -num2.intValue();
+ }
+
+ else if(num1 instanceof Float && num2 instanceof Long) {
+ res = num1.floatValue() -num2.longValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Short) {
+ res = num1.floatValue() -num2.shortValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Float) {
+ res = num1.floatValue() -num2.floatValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Double) {
+ res = num1.floatValue() -num2.doubleValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Byte) {
+ res = num1.floatValue() -num2.byteValue();
+ }
+ else if(num1 instanceof Float && num2 instanceof Integer) {
+ res = num1.floatValue() -num2.intValue();
+ }
+
+ else if(num1 instanceof Double && num2 instanceof Long) {
+ res = num1.doubleValue() -num2.longValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Short) {
+ res = num1.doubleValue() -num2.shortValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Float) {
+ res = num1.doubleValue() -num2.floatValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Double) {
+ res = num1.doubleValue() -num2.doubleValue();
+ }
+ else if(num1 instanceof Double && num2 instanceof Byte) {
+ res = num1.doubleValue() -num2.byteValue();
+ } else if(num1 instanceof Double && num2 instanceof Integer) {
+ res = num1.doubleValue() -num2.intValue();
+ }
+
+ return res;
+ }*/
+
+ @Override
+ public Number doOperation(Number opLeft, Number opRight) {
+ return opLeft.doubleValue()-opRight.doubleValue();
+ }
+}
diff --git a/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticVariable.java b/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticVariable.java new file mode 100644 index 0000000..a9130fb --- /dev/null +++ b/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ArithmeticVariable.java @@ -0,0 +1,28 @@ +package net.sven_eisenhauer.swa_prakt1;
+
+public class ArithmeticVariable implements ArithmeticExpression {
+
+ private String name;
+ private Number value;
+
+ public ArithmeticVariable(String name,Number value) {
+ this.name = name;
+ this.value = value;
+ }
+/*
+ @Override
+ public Number evaluate() {
+ return value;
+ }
+
+ @Override
+ public void print() {
+ System.out.print(name);
+ }*/
+ public String getName() {
+ return name;
+ }
+ public Number getValue() {
+ return value;
+ }
+}
diff --git a/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/EvalIter.java b/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/EvalIter.java new file mode 100644 index 0000000..f356491 --- /dev/null +++ b/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/EvalIter.java @@ -0,0 +1,17 @@ +package net.sven_eisenhauer.swa_prakt1; + +public class EvalIter implements ExpIter { + + @Override + public Number traverse(ArithmeticExpression exp) { + if(exp instanceof ArithmeticVariable) { + return ((ArithmeticVariable) exp).getValue(); + } else { + ArithmeticOperation actOp = (ArithmeticOperation) exp; + Number leftVal = traverse(actOp.getLeftOperand()); + Number rightVal = traverse(actOp.getRightOperand()); + return actOp.doOperation(leftVal, rightVal); + } + } + +} diff --git a/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ExpIter.java b/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ExpIter.java new file mode 100644 index 0000000..cd5a728 --- /dev/null +++ b/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ExpIter.java @@ -0,0 +1,5 @@ +package net.sven_eisenhauer.swa_prakt1; + +public interface ExpIter { + public Number traverse(ArithmeticExpression exp); +} diff --git a/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ExpressionIterator.java b/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ExpressionIterator.java new file mode 100644 index 0000000..0cdd7a8 --- /dev/null +++ b/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/ExpressionIterator.java @@ -0,0 +1,47 @@ +package net.sven_eisenhauer.swa_prakt1; + +public class ExpressionIterator implements ArithmeticIterator { + private ArithmeticExpression baseNode; + + public ExpressionIterator(ArithmeticExpression baseNode) { + this.baseNode = baseNode; + } + + public void print() { + if(baseNode instanceof ArithmeticVariable) { + System.out.print(((ArithmeticVariable) baseNode).getName()); + } else { + ArithmeticOperation actOperation = (ArithmeticOperation) baseNode; + ArithmeticIterator leftIter = new ExpressionIterator(actOperation.getLeftOperand()); + ArithmeticIterator rightIter = new ExpressionIterator(actOperation.getRightOperand()); + System.out.print("("); + leftIter.print(); + System.out.print(actOperation.getOperationSign()); + rightIter.print(); + System.out.print(")"); + } + } + + public Number evaluate() { + if(baseNode instanceof ArithmeticVariable) { + return ((ArithmeticVariable) baseNode).getValue(); + } else { + ArithmeticOperation actOperation = (ArithmeticOperation) baseNode; + ArithmeticIterator leftIter = new ExpressionIterator(actOperation.getLeftOperand()); + ArithmeticIterator rightIter = new ExpressionIterator(actOperation.getRightOperand()); + Number leftVal = leftIter.evaluate(); + Number rightVal = rightIter.evaluate(); + if(actOperation instanceof ArithmeticAddition) { + return leftVal.doubleValue() + rightVal.doubleValue(); + } else if(actOperation instanceof ArithmeticSubstraction) { + return leftVal.doubleValue() - rightVal.doubleValue(); + } else if(actOperation instanceof ArithmeticDivision) { + return leftVal.doubleValue() / rightVal.doubleValue(); + } else if(actOperation instanceof ArithmeticMultiplication) { + return leftVal.doubleValue() * rightVal.doubleValue(); + } else { + return null; + } + } + } +} diff --git a/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/PrintIter.java b/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/PrintIter.java new file mode 100644 index 0000000..90d43d9 --- /dev/null +++ b/Master/Software Architektur/SWA_Prakt2/src/net/sven_eisenhauer/swa_prakt2/PrintIter.java @@ -0,0 +1,19 @@ +package net.sven_eisenhauer.swa_prakt1; + +public class PrintIter implements ExpIter { + + @Override + public Number traverse(ArithmeticExpression exp) { + if(exp instanceof ArithmeticVariable) { + System.out.print(((ArithmeticVariable) exp).getName()); + } else { + ArithmeticOperation actOp = (ArithmeticOperation) exp; + System.out.print("("); + traverse(actOp.getLeftOperand()); + System.out.print(actOp.getOperationSign()); + traverse(actOp.getRightOperand()); + System.out.print(")"); + } + return 0; + } +} |
