diff options
| author | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-06-09 09:13:55 +0200 |
|---|---|---|
| committer | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-06-09 09:13:55 +0200 |
| commit | d8cd813ddc54c455eb3071795038b97b72dc1ee9 (patch) | |
| tree | 3da37c0ec1d4d0f2de6e3e1a981542df8222ae6d /src/de/fhswf/in/inf/upnfx/util/BinaryOperator.java | |
| parent | f74cd282da1f14bc3d2d768b2f68b8f6d6429e68 (diff) | |
| download | UpnFx-d8cd813ddc54c455eb3071795038b97b72dc1ee9.tar.gz UpnFx-d8cd813ddc54c455eb3071795038b97b72dc1ee9.zip | |
Add working version of UpnFx
Diffstat (limited to 'src/de/fhswf/in/inf/upnfx/util/BinaryOperator.java')
| -rw-r--r-- | src/de/fhswf/in/inf/upnfx/util/BinaryOperator.java | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/de/fhswf/in/inf/upnfx/util/BinaryOperator.java b/src/de/fhswf/in/inf/upnfx/util/BinaryOperator.java new file mode 100644 index 0000000..4f704ee --- /dev/null +++ b/src/de/fhswf/in/inf/upnfx/util/BinaryOperator.java @@ -0,0 +1,50 @@ +/** + * + */ +package de.fhswf.in.inf.upnfx.util; + + +/** + * 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(ObservableDoubleStack stack) + { + if (stack == null) + { + throw new IllegalArgumentException("Stack must not be null."); + } + + if (stack.size() < 2) + { + throw new IllegalArgumentException( + "Binary operation requires two 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); +} |
