1 7 8 package java.lang; 9 10 26 public final class Boolean implements java.io.Serializable , 27 Comparable <Boolean > 28 { 29 33 public static final Boolean TRUE = new Boolean (true); 34 35 39 public static final Boolean FALSE = new Boolean (false); 40 41 46 public static final Class <Boolean > TYPE = Class.getPrimitiveClass("boolean"); 47 48 53 private final boolean value; 54 55 56 private static final long serialVersionUID = -3665804199014368530L; 57 58 69 public Boolean(boolean value) { 70 this.value = value; 71 } 72 73 86 public Boolean(String s) { 87 this(toBoolean(s)); 88 } 89 90 101 public static boolean parseBoolean(String s) { 102 return toBoolean(s); 103 } 104 105 111 public boolean booleanValue() { 112 return value; 113 } 114 115 129 public static Boolean valueOf(boolean b) { 130 return (b ? TRUE : FALSE); 131 } 132 133 144 public static Boolean valueOf(String s) { 145 return toBoolean(s) ? TRUE : FALSE; 146 } 147 148 158 public static String toString(boolean b) { 159 return b ? "true" : "false"; 160 } 161 162 170 public String toString() { 171 return value ? "true" : "false"; 172 } 173 174 181 public int hashCode() { 182 return value ? 1231 : 1237; 183 } 184 185 194 public boolean equals(Object obj) { 195 if (obj instanceof Boolean ) { 196 return value == ((Boolean )obj).booleanValue(); 197 } 198 return false; 199 } 200 201 218 public static boolean getBoolean(String name) { 219 boolean result = false; 220 try { 221 result = toBoolean(System.getProperty(name)); 222 } catch (IllegalArgumentException e) { 223 } catch (NullPointerException e) { 224 } 225 return result; 226 } 227 228 240 public int compareTo(Boolean b) { 241 return (b.value == value ? 0 : (value ? 1 : -1)); 242 } 243 244 private static boolean toBoolean(String name) { 245 return ((name != null) && name.equalsIgnoreCase("true")); 246 } 247 } 248 | Popular Tags |