/** * 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 BinaryPlus extends BinaryExpr { public BinaryPlus(Expr left, Expr right) { super(left, right); } // Implemetierung der Schablonenmethoden protected Object op2(Object v1, Object v2) { // + fuer int if ( v1 instanceof Integer && v2 instanceof Integer ) { return new Integer( ((Integer)v1).intValue() + ((Integer)v2).intValue() ); } // + fuer double if ( v1 instanceof Double && v2 instanceof Double ) { return new Double( ((Double)v1).doubleValue() + ((Double)v2).doubleValue() ); } // nicht erlaubtes Argument throw new IllegalArgumentException("binary + : illegal operand types"); } //-------------------- protected String op2ToString() { return "+"; } }