< prev index next >

src/java.corba/share/classes/com/sun/tools/corba/se/idl/constExpr/Equal.java

Print this page




  39 
  40 import com.sun.tools.corba.se.idl.Util;
  41 import java.math.BigInteger;
  42 
  43 public 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


  39 
  40 import com.sun.tools.corba.se.idl.Util;
  41 import java.math.BigInteger;
  42 
  43 public 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 (Boolean.valueOf (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 (Boolean.valueOf (l.doubleValue () == r.doubleValue ()));
  67         else
  68           //daz          value (new Boolean (l.longValue () == r.longValue ()));
  69           value (Boolean.valueOf (((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
< prev index next >