Equal.java revision 608:7e06bf1dcb09
168349Sobrien/* 268349Sobrien * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. 3284193Sdelphij * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 468349Sobrien * 568349Sobrien * This code is free software; you can redistribute it and/or modify it 668349Sobrien * under the terms of the GNU General Public License version 2 only, as 768349Sobrien * published by the Free Software Foundation. Oracle designates this 868349Sobrien * particular file as subject to the "Classpath" exception as provided 968349Sobrien * by Oracle in the LICENSE file that accompanied this code. 1068349Sobrien * 1168349Sobrien * This code is distributed in the hope that it will be useful, but WITHOUT 1268349Sobrien * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1368349Sobrien * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1468349Sobrien * version 2 for more details (a copy is included in the LICENSE file that 1568349Sobrien * accompanied this code). 1668349Sobrien * 1768349Sobrien * You should have received a copy of the GNU General Public License version 1868349Sobrien * 2 along with this work; if not, write to the Free Software Foundation, 1968349Sobrien * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2068349Sobrien * 2168349Sobrien * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2268349Sobrien * or visit www.oracle.com if you need additional information or have any 2368349Sobrien * questions. 2468349Sobrien */ 2568349Sobrien/* 2668349Sobrien * COMPONENT_NAME: idl.parser 27267843Sdelphij * 28267843Sdelphij * ORIGINS: 27 29267843Sdelphij * 30267843Sdelphij * Licensed Materials - Property of IBM 31 * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999 32 * RMI-IIOP v1.0 33 * 34 */ 35 36package com.sun.tools.corba.se.idl.constExpr; 37 38// NOTES: 39 40import com.sun.tools.corba.se.idl.Util; 41import java.math.BigInteger; 42 43public class Equal extends BinaryExpr 44{ 45 protected Equal (Expression leftOperand, Expression rightOperand) 46 { 47 super ("==", leftOperand, rightOperand); 48 } // ctor 49 50 public Object evaluate () throws EvaluationException 51 { 52 try 53 { 54 Object left = left ().evaluate (); 55 if (left instanceof Boolean) 56 { 57 Boolean l = (Boolean)left; 58 Boolean r = (Boolean)right ().evaluate (); 59 value (new Boolean (l.booleanValue () == r.booleanValue())); 60 } 61 else 62 { 63 Number l = (Number)left; 64 Number r = (Number)right ().evaluate (); 65 if (l instanceof Float || l instanceof Double || r instanceof Float || r instanceof Double) 66 value (new Boolean (l.doubleValue () == r.doubleValue ())); 67 else 68 //daz value (new Boolean (l.longValue () == r.longValue ())); 69 value (new Boolean (((BigInteger)l).equals ((BigInteger)r))); 70 } 71 } 72 catch (ClassCastException e) 73 { 74 String[] parameters = {Util.getMessage ("EvaluationException.equal"), left ().value ().getClass ().getName (), right ().value ().getClass ().getName ()}; 75 throw new EvaluationException (Util.getMessage ("EvaluationException.1", parameters)); 76 } 77 return value (); 78 } // evaluate 79} // class Equal 80