diff options
Diffstat (limited to 'src/de/fhswf/in/inf/upnfx/util/UnaryOperator.java')
| -rw-r--r-- | src/de/fhswf/in/inf/upnfx/util/UnaryOperator.java | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/de/fhswf/in/inf/upnfx/util/UnaryOperator.java b/src/de/fhswf/in/inf/upnfx/util/UnaryOperator.java new file mode 100644 index 0000000..be44b16 --- /dev/null +++ b/src/de/fhswf/in/inf/upnfx/util/UnaryOperator.java @@ -0,0 +1,47 @@ +/** + * + */ +package de.fhswf.in.inf.upnfx.util; + + +/** + * An abstract class for calculations with unary operators. + * + * @author $Author: $ + * @version $Revision: $, $Date: $ UTC + */ +public abstract class UnaryOperator implements Operator +{ + /* + * (non-Javadoc) + * + * @see de.fhswf.in.inf.java1.aufgabe12.Operator#eval(java.util.Stack) + */ + @Override + public final void eval(ObservableDoubleStack stack) + { + if (stack == null) + { + throw new IllegalArgumentException("Stack must not be null."); + } + + if (stack.size() < 1) + { + throw new IllegalArgumentException( + "Unary operation requires one operand."); + } + + double d = stack.pop(); + + stack.push(eval(d)); + } + + /** + * This class implements the calculation. + * + * @param d + * The unary operator. + * @return The result of the calculation. + */ + abstract double eval(double d); +} |
