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 / PositiveNumber.java < prev    next >
Encoding:
Java Source  |  1997-03-14  |  1.8 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.  * PositiveNumber is a unary predicate that assumes that its operand is an
  8.  * instance of Number and returns true if it is positive.
  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 PositiveNumber implements UnaryPredicate
  18.   {
  19.   private Class mode;
  20.   private static Integer zero = new Integer( 0 );
  21.  
  22.   /**
  23.    * Construct myself to use intValue() for comparisons.
  24.    */
  25.   public PositiveNumber()
  26.     {
  27.     mode = zero.getClass();
  28.     }
  29.  
  30.   /**
  31.    * Construct myself to compare objects of the given class.  The class must
  32.    * be derived from java.lang.Number.
  33.    * @param discriminator The class of objects that I will be comparing.
  34.    * @exception java.lang.IllegalArgumentException Throw if discriminator is not an instance of java.lang.Number.
  35.    */
  36.   public PositiveNumber( Class discriminator )
  37.     {
  38.     if ( !NumberHelper.classNumber.isAssignableFrom( discriminator ) )
  39.       throw new IllegalArgumentException( "discriminator must be an instance of java.lang.Number" );
  40.     mode = discriminator;
  41.     }
  42.  
  43.   /**
  44.    * Return true if the operand is greater than zero.
  45.    * Be aware that some floating point conversions are not exact, and may
  46.    * cause unexpected results due to rounding.
  47.    * @param object The operand, which must be a Number.
  48.    * @exception COM.objectspace.jgl.InvalidOperationException Throw if I don't know how to interpret the values.
  49.    * @return object > 0
  50.    */
  51.   public boolean execute( Object object )
  52.     {
  53.     return NumberHelper.compare( (Number)object, zero, mode ) > 0;
  54.     }
  55.   }
  56.