blob: 50ac8553a7599e9cdf7f759f7a22e9ecf3070437 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
/**
*
*/
package de.fhswf.in.inf.java1.aufgabe12;
import java.util.Stack;
/**
* An abstract class for calculations with unary operators.
*
* @author $Author: $
* @version $Revision: $, $Date: $ UTC
*/
public abstract class BinaryOperator implements Operator
{
/*
* (non-Javadoc)
*
* @see de.fhswf.in.inf.java1.aufgabe12.Operator#eval(java.util.Stack)
*/
@Override
public final void eval(Stack<Double> stack)
{
if (stack == null)
{
throw new IllegalArgumentException("Stack must not be null.");
}
if (stack.size() < 2)
{
throw new IllegalArgumentException(
"Unary operation requires one operand.");
}
double d2 = stack.pop();
double d1 = stack.pop();
stack.push(eval(d1, d2));
}
/**
* This method implements the calculation.
*
* @param d1
* The first operator.
* @param d2
* The second operator.
* @return The result of the calculation.
*/
abstract double eval(double d1, double d2);
}
|