/** * 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. */ public class UnaryMinus extends UnaryExpr { //-------------------- public UnaryMinus(Expr operand) { super(operand); } //-------------------- // op1 negiert den Wert // Operation erlaubt fuer int und double Werte protected Object op1(Object v1) { // - fuer int if ( v1 instanceof Integer ) { return new Integer(- ((Integer)v1).intValue()); } // - fuer double if ( v1 instanceof Double ) { return new Double(- ((Double)v1).doubleValue()); } // nicht erlaubtes Argument throw new IllegalArgumentException("unary - : illegal operand type"); } //-------------------- public String op1ToString() { return "-"; } } //--------------------