home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 21 / IOPROG_21.ISO / SOFT / JSL.ZIP / JSL20 / simula / random / BooleanValue.java < prev    next >
Encoding:
Java Source  |  1998-02-20  |  1.2 KB  |  44 lines

  1.  
  2. package simula.random;
  3.  
  4. /**
  5.  * Implementation of the class Value that encapsulate boolean values.
  6.  * @see Value
  7.  */
  8. public class BooleanValue extends Value {
  9.  
  10.     private boolean value = false;
  11.  
  12.  
  13.     /**
  14.      * Creates a new object encapsulating the given boolean value.
  15.      * @param b The boolean value to encapsulate.
  16.      */
  17.     BooleanValue(boolean b) {
  18.         value = b;
  19.     }
  20.     /**
  21.      * Returns the encapsulated boolean.
  22.      * @return the encapsulated boolean.
  23.      * @exception TypeDrawnException Fired whenever meaningless
  24.      */
  25.     public boolean asBoolean() throws TypeDrawnException {
  26.         return value;
  27.     }
  28.     /**
  29.      * Returns the encapsulated boolean represented as an integer value.
  30.      * @return 1 if the encapsulated boolean is true; 0 otherwise.
  31.      * @exception TypeDrawnException Fired whenever meaningless
  32.      */
  33.     public int asInteger() throws TypeDrawnException {
  34.         return value ? 1 : 0;
  35.     }
  36.     /**
  37.      * Returns the encapsulated boolean represented as a real value.
  38.      * @return 1.0 if the encapsulated boolean is true; 0.0 otherwise.
  39.      * @exception TypeDrawnException Fired whenever meaningless
  40.      */
  41.     public double asReal() throws TypeDrawnException {
  42.         return value ? 1.0 : 0.0;
  43.     }
  44. }