/[classpath]/classpath/java/lang/Boolean.java
ViewVC logotype

Diff of /classpath/java/lang/Boolean.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.18 by mark, Tue Jan 22 22:26:59 2002 UTC revision 1.19 by ericb, Fri Feb 22 20:07:40 2002 UTC
# Line 1  Line 1 
1  /* Boolean.java -- object wrapper for boolean  /* Boolean.java -- object wrapper for boolean
2     Copyright (C) 1998, 2001 Free Software Foundation, Inc.     Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 7  GNU Classpath is free software; you can Line 7  GNU Classpath is free software; you can
7  it under the terms of the GNU General Public License as published by  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2, or (at your option)  the Free Software Foundation; either version 2, or (at your option)
9  any later version.  any later version.
10    
11  GNU Classpath is distributed in the hope that it will be useful, but  GNU Classpath is distributed in the hope that it will be useful, but
12  WITHOUT ANY WARRANTY; without even the implied warranty of  WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Line 41  package java.lang; Line 41  package java.lang;
41  import java.io.Serializable;  import java.io.Serializable;
42    
43  /**  /**
44   * Instances of class <code>Boolean</code> represent primitive   * Instances of class <code>Boolean</code> represent primitive
45   * <code>boolean</code> values.   * <code>boolean</code> values.
46   *   *
47   * @author Paul Fisher   * @author Paul Fisher
48   * @since JDK1.0   * @author Eric Blake <ebb9@email.byu.edu>
49   */   * @since 1.0
50     * @status updated to 1.4
51     */
52  public final class Boolean implements Serializable  public final class Boolean implements Serializable
53  {  {
54      static final long serialVersionUID = -3665804199014368530L;    /**
55           * Compatible with JDK 1.0.2+.
56      /**     */
57       * This field is a <code>Boolean</code> object representing the    private static final long serialVersionUID = -3665804199014368530L;
58       * primitive value <code>true</code>. This instance is returned  
59       * by the static <code>valueOf()</code> methods if they return    /**
60       * a <code>Boolean</code> representing <code>true</code>.     * This field is a <code>Boolean</code> object representing the
61       */     * primitive value <code>true</code>. This instance is returned
62      public static final Boolean TRUE  = new Boolean(true);     * by the static <code>valueOf()</code> methods if they return
63           * a <code>Boolean</code> representing <code>true</code>.
64      /**     */
65       * This field is a <code>Boolean</code> object representing the    public static final Boolean TRUE = new Boolean(true);
66       * primitive value <code>false</code>. This instance is returned  
67       * by the static <code>valueOf()</code> methods if they return    /**
68       * a <code>Boolean</code> representing <code>false</code>.     * This field is a <code>Boolean</code> object representing the
69       */     * primitive value <code>false</code>. This instance is returned
70       public static final Boolean FALSE = new Boolean(false);     * by the static <code>valueOf()</code> methods if they return
71       * a <code>Boolean</code> representing <code>false</code>.
72      /**     */
73       * The primitive type <code>boolean</code> is represented by this    public static final Boolean FALSE = new Boolean(false);
74       * <code>Class</code> object.  
75       */    /**
76      public static final Class TYPE = VMClassLoader.getPrimitiveClass('Z');     * The primitive type <code>boolean</code> is represented by this
77           * <code>Class</code> object.
78      /**     *
79       * The immutable value of this Boolean.     * @since 1.1
80       */     */
81      private final boolean value;    public static final Class TYPE = VMClassLoader.getPrimitiveClass('Z');
82        
83      /**    /**
84       * Create a <code>Boolean</code> object representing the value of the     * The immutable value of this Boolean.
85       * argument <code>value</code>. In general the use of the static     * @serial the wrapped value
86       * method <code>valueof(boolean)</code> is more efficient since it will     */
87       * not create a new object.    private final boolean value;
88       *  
89       * @param value the primitive value of this <code>Boolean</code>    /**
90       */         * Create a <code>Boolean</code> object representing the value of the
91      public Boolean(boolean value) {     * argument <code>value</code>. In general the use of the static
92          this.value = value;     * method <code>valueof(boolean)</code> is more efficient since it will
93      }     * not create a new object.
94           *
95      /**     * @param value the primitive value of this <code>Boolean</code>
96       * Creates a <code>Boolean</code> object representing the primitive     * @see #valueOf(boolean)
97       * <code>true</code> if and only if <code>s</code> matches     */
98       * the string "true" ignoring case, otherwise the object will represent    public Boolean(boolean value)
99       * the primitive <code>false</code>. In general the use of the static    {
100       * method <code>valueof(String)</code> is more efficient since it will      this.value = value;
101       * not create a new object.    }
102       *  
103       * @param s the <code>String</code> representation of <code>true</code>    /**
104       *   or false     * Creates a <code>Boolean</code> object representing the primitive
105       */     * <code>true</code> if and only if <code>s</code> matches
106      public Boolean(String s) {     * the string "true" ignoring case, otherwise the object will represent
107          value = "true".equalsIgnoreCase(s);     * the primitive <code>false</code>. In general the use of the static
108      }     * method <code>valueof(String)</code> is more efficient since it will
109       * not create a new object.
110      /**     *
111       * Return the primitive <code>boolean</code> value of this     * @param s the <code>String</code> representation of <code>true</code>
112       * <code>Boolean</code> object.     *        or false
113       */     */
114      public boolean booleanValue() {    public Boolean(String s)
115          return value;    {
116      }      value = "true".equalsIgnoreCase(s);
117      }
118      /**  
119       * Returns the Boolean <code>TRUE</code> if the given boolean is    /**
120       * <code>true</code>, otherwise it will return the Boolean     * Return the primitive <code>boolean</code> value of this
121       * <code>FALSE</code>.     * <code>Boolean</code> object.
122       *     *
123       * @since 1.4     * @return true or false, depending on the value of this Boolean
124       */     */
125      public static Boolean valueOf(boolean b) {    public boolean booleanValue()
126          return b ? TRUE : FALSE;    {
127      }      return value;
128      }
129      /**  
130       * Returns the Boolean <code>TRUE</code> if and only if the given    /**
131       * String is equal, ignoring case, to the the String "true", otherwise     * Returns the Boolean <code>TRUE</code> if the given boolean is
132       * it will return the Boolean <code>FALSE</code>.     * <code>true</code>, otherwise it will return the Boolean
133       */     * <code>FALSE</code>.
134      public static Boolean valueOf(String s) {     *
135          return "true".equalsIgnoreCase(s) ? TRUE : FALSE;     * @param b the boolean to wrap
136      }     * @return the wrapper object
137       * @see #TRUE
138      /**     * @see #FALSE
139       * Returns the integer <code>1231</code> if this object represents     * @since 1.4
140       * the primitive <code>true</code> and the integer <code>1237</code>     */
141       * otherwise.    public static Boolean valueOf(boolean b)
142       */        {
143      public int hashCode() {      return b ? TRUE : FALSE;
144          return (value) ? 1231 : 1237;    }
145      }  
146      /**
147      /**     * Returns the Boolean <code>TRUE</code> if and only if the given
148       * If the <code>obj</code> is an instance of <code>Boolean</code> and     * String is equal, ignoring case, to the the String "true", otherwise
149       * has the same primitive value as this object then <code>true</code>     * it will return the Boolean <code>FALSE</code>.
150       * is returned.  In all other cases, including if the <code>obj</code>     *
151       * is <code>null</code>, <code>false</code> is returned.     * @param s the string to convert
152       *     * @return a wrapped boolean from the string
153       * @param obj possibly an instance of any <code>Class</code>     */
154       * @return <code>false</code> is <code>obj</code> is an instance of    public static Boolean valueOf(String s)
155       *   <code>Boolean</code> and has the same primitive value as this    {
156       *   object.      return "true".equalsIgnoreCase(s) ? TRUE : FALSE;
157       */        }
158      public boolean equals(Object obj) {  
159          return (obj instanceof Boolean && value == ((Boolean)obj).value);    /**
160      }     * Returns "true" if the value of the give boolean is <code>true</code> and
161       * returns "false" if the value of the given boolean is <code>false</code>.
162      /**     *
163       * If the value of the system property <code>name</code> matches     * @param b the boolean to convert
164       * "true" ignoring case then the function returns <code>true</code>.     * @return the string representation of the boolean
165       */     * @since 1.4
166      public static boolean getBoolean(String name) {     */
167          String val = System.getProperty(name);    public static String toString(boolean b)
168          return ("true".equalsIgnoreCase(val));    {
169      }      return b ? "true" : "false";
170          }
171      /**  
172       * Returns "true" if the value of the give boolean is <code>true</code> and    /**
173       * returns "false" if the value of the given boolean is <code>false</code>.     * Returns "true" if the value of this object is <code>true</code> and
174       *     * returns "false" if the value of this object is <code>false</code>.
175       * @since 1.4     *
176       */     * @return the string representation of this
177      public static String toString(boolean b)     */
178      {    public String toString()
179          return b ? "true" : "false";    {
180      }      return value ? "true" : "false";
181      }
182      /**  
183       * Returns "true" if the value of this object is <code>true</code> and    /**
184       * returns "false" if the value of this object is <code>false</code>.     * Returns the integer <code>1231</code> if this object represents
185       */     * the primitive <code>true</code> and the integer <code>1237</code>
186      public String toString()     * otherwise.
187      {     *
188          return (value) ? "true" : "false";     * @return the hash code
189      }       */
190      public int hashCode()
191      {
192        return value ? 1231 : 1237;
193      }
194    
195      /**
196       * If the <code>obj</code> is an instance of <code>Boolean</code> and
197       * has the same primitive value as this object then <code>true</code>
198       * is returned.  In all other cases, including if the <code>obj</code>
199       * is <code>null</code>, <code>false</code> is returned.
200       *
201       * @param obj possibly an instance of any <code>Class</code>
202       * @return true if <code>obj</code> equals this
203       */
204      public boolean equals(Object obj)
205      {
206        return obj instanceof Boolean && value == ((Boolean) obj).value;
207      }
208    
209      /**
210       * If the value of the system property <code>name</code> matches
211       * "true" ignoring case then the function returns <code>true</code>.
212       *
213       * @param name the property name to look up
214       * @return true if the property resulted in "true"
215       * @see System#getProperty(String)
216       */
217      public static boolean getBoolean(String name)
218      {
219        String val = System.getProperty(name);
220        return "true".equalsIgnoreCase(val);
221      }
222  }  }

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.19

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26