home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / solaris2 / jdk / src / java / lang / boolean.jav < prev    next >
Encoding:
Text File  |  1995-10-30  |  2.6 KB  |  97 lines

  1. /*
  2.  * @(#)Boolean.java    1.16 95/07/27  
  3.  *
  4.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. package java.lang;
  21.  
  22. /**
  23.  * The Boolean class provides an object wrapper for Boolean data values, and 
  24.  * serves as a place for boolean-oriented operations.
  25.  * A wrapper is useful because most of Java's utility classes require the use
  26.  * of objects.  Since booleans are not objects in Java, they need to be
  27.  * "wrapped" in a Boolean instance. 
  28.  * @version     1.16, 07/27/95
  29.  * @author    Arthur van Hoff
  30.  */
  31. public final
  32. class Boolean {
  33.     /** 
  34.      *  Assigns this Boolean to be true.
  35.      */
  36.     public static final Boolean TRUE = new Boolean(true);
  37.     /** 
  38.      * Assigns this Boolean to be false.
  39.      */
  40.     public static final Boolean FALSE = new Boolean(false);
  41.     
  42.     /**
  43.      * The value of the Boolean.
  44.      */
  45.     private boolean value;
  46.  
  47.     /**
  48.      * Constructs a Boolean object initialized to the specified boolean 
  49.      * value.
  50.      * @param value the value of the boolean
  51.      */
  52.     public Boolean(boolean value) {
  53.     this.value = value;
  54.     }
  55.  
  56.     /**
  57.      * Returns the value of this Boolean object as a boolean.
  58.      */
  59.     public boolean booleanValue() {
  60.     return value;
  61.     }
  62.  
  63.     /**
  64.      * Returns a new String object representing this Boolean's value.
  65.      */
  66.     public String toString() {
  67.     return value ? "true" : "false";
  68.     }
  69.  
  70.     /**
  71.      * Compares this object against the specified object.
  72.      * @param obj        the object to compare with
  73.      * @return         true if the objects are the same; false otherwise.
  74.      */
  75.     public boolean equals(Object obj) {
  76.     if ((obj != null) && (obj instanceof Boolean)) {
  77.         return (value == ((Boolean)obj).booleanValue());
  78.     } 
  79.     return false;
  80.     }
  81.  
  82.     /**
  83.      * Gets a Boolean from the properties.
  84.      * @param name the property name.
  85.      */
  86.     public static boolean getBoolean(String name) {
  87.     return "true".equals(System.getProperty(name));
  88.     }
  89. }
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.