/** * Copyright (c): Uwe Schmidt, FH Wedel * * You may study, modify and distribute this source code * FOR NON-COMMERCIAL PURPOSES ONLY. * This copyright message has to remain unchanged. * * Note that this document is provided 'as is', * WITHOUT WARRANTY of any kind either expressed or implied. */ /** * eine Klasse fuer das unaere Minus * */ //-------------------- public class UnaryMinus extends UnaryExpr { //-------------------- public UnaryMinus(Expr operand) { super(operand); } //-------------------- // eval wertet den Operanden aus // und negiert den Wert // Operation erlaubt fuer int und double Werte public Object eval() { // operand auswerten Object value = operand.eval(); // - fuer int if ( value instanceof Integer ) { return new Integer(- ((Integer)value).intValue()); } // - fuer double if ( value instanceof Double ) { return new Double(- ((Double)value).doubleValue()); } // nicht erlaubtes Argument throw new IllegalArgumentException("unary - : illegal operand type"); } //-------------------- public String toString() { return "( -" + operand.toString() + ")"; } } //--------------------