home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Extras / OSpace / jgl.exe / jgl_2_0 / src / COM / objectspace / jgl / LessEqualNumber.java < prev    next >
Encoding:
Java Source  |  1997-03-14  |  1.9 KB  |  56 lines

  1. // Copyright(c) 1996,1997 ObjectSpace, Inc.
  2. // Portions Copyright(c) 1995, 1996 Hewlett-Packard Company.
  3.  
  4. package COM.objectspace.jgl;
  5.  
  6. /**
  7.  * LessEqualNumber is a binary predicate that assumes that both of its operands are
  8.  * instances of Number and returns true if the first operand is less than or equal to the second operand.
  9.  * <p>
  10.  * @see java.lang.Number
  11.  * @see java.math.BigInteger
  12.  * @see java.math.BigDecimal
  13.  * @version 2.0.2
  14.  * @author ObjectSpace, Inc.
  15.  */
  16.  
  17. public class LessEqualNumber implements BinaryPredicate
  18.   {
  19.   private Class mode;
  20.  
  21.   /**
  22.    * Construct myself to use intValue() for comparisons.
  23.    */
  24.   public LessEqualNumber()
  25.     {
  26.     mode = new Integer( 0 ).getClass();
  27.     }
  28.  
  29.   /**
  30.    * Construct myself to compare objects of the given class.  The class must
  31.    * be derived from java.lang.Number.
  32.    * @param discriminator The class of objects that I will be comparing.
  33.    * @exception java.lang.IllegalArgumentException Throw if discriminator is not an instance of java.lang.Number.
  34.    */
  35.   public LessEqualNumber( Class discriminator )
  36.     {
  37.     if ( !NumberHelper.classNumber.isAssignableFrom( discriminator ) )
  38.       throw new IllegalArgumentException( "discriminator must be an instance of java.lang.Number" );
  39.     mode = discriminator;
  40.     }
  41.  
  42.   /**
  43.    * Return true if the first operand is less than or equal to the second operand.
  44.    * Be aware that some floating point conversions are not exact, and may
  45.    * cause unexpected results due to rounding.
  46.    * @param first The first operand, which must be an instance of Number.
  47.    * @param second The second operand, which must be an instance of Number.
  48.    * @exception COM.objectspace.jgl.InvalidOperationException Throw if I don't know how to interpret the values.
  49.    * @return first <= second
  50.    */
  51.   public boolean execute( Object first, Object second )
  52.     {
  53.     return NumberHelper.compare( (Number)first, (Number)second, mode ) <= 0;
  54.     }
  55.   }
  56.