1 9 10 package org.jboss.util; 11 12 import java.io.Serializable ; 13 14 20 public class MuBoolean 21 implements Comparable , Cloneable , Serializable , Mutable 22 { 23 static final long serialVersionUID = 8496688045920612417L; 24 25 private boolean value; 27 30 public MuBoolean() {} 31 32 37 public MuBoolean(boolean b) { 38 value = b; 39 } 40 41 46 public MuBoolean(Object obj) { 47 setValue(obj); 48 } 49 50 55 public MuBoolean(String value) { 56 set(Boolean.valueOf(value)); 57 } 58 59 64 public boolean booleanValue() { 65 return value; 66 } 67 68 74 public boolean set(boolean b) { 75 boolean old = value; 76 value = b; 77 return old; 78 } 79 80 86 public boolean set(Boolean b) { 87 boolean old = value; 88 value = b.booleanValue(); 89 return old; 90 } 91 92 98 public boolean set(MuBoolean b) { 99 boolean old = value; 100 value = b.value; 101 return old; 102 } 103 104 109 public boolean get() { 110 return value; 111 } 112 113 121 public boolean commit(boolean assumed, boolean b) { 122 boolean success = (assumed == value); 123 if (success) value = b; 124 return success; 125 } 126 127 133 public boolean swap(MuBoolean b) { 134 if (b == this) return value; 135 136 boolean temp = value; 137 value = b.value; 138 b.value = temp; 139 140 return value; 141 } 142 143 148 public boolean complement() { 149 value = !value; 150 return value; 151 } 152 153 159 public boolean and(boolean b) { 160 value &= b; 161 162 return value; 163 } 164 165 171 public boolean or(boolean b) { 172 value |= b; 173 174 return value; 175 } 176 177 183 public boolean xor(boolean b) { 184 value ^= b; 185 186 return value; 187 } 188 189 197 public int compareTo(boolean bool) { 198 return (value == bool) ? 0 : (value) ? 1 : -1; 199 } 200 201 211 public int compareTo(Object obj) throws ClassCastException { 212 return compareTo(((MuBoolean)obj).value); 213 } 214 215 220 public String toString() { 221 return String.valueOf(value); 222 } 223 224 229 public int hashCode() { 230 return HashCode.generate(value); 231 } 232 233 239 public boolean equals(Object obj) { 240 if (obj == this) return true; 241 242 if (obj != null && obj.getClass() == getClass()) { 243 MuBoolean bool = (MuBoolean)obj; 244 return value == bool.value; 245 } 246 247 return false; 248 } 249 250 255 public Object clone() { 256 try { 257 return super.clone(); 258 } 259 catch (CloneNotSupportedException e) { 260 throw new InternalError (); 261 } 262 } 263 264 265 269 279 public void setValue(Object obj) { 280 if (obj instanceof MuBoolean) { 281 value = ((MuBoolean)obj).value; 282 } 283 else if (obj instanceof Boolean ) { 284 value = ((Boolean )obj).booleanValue(); 285 } 286 else if (obj != null) { 287 value = true; 288 } 289 else { 290 value = false; 291 } 292 } 293 294 299 public Object getValue() { 300 return value ? Boolean.TRUE : Boolean.FALSE; 301 } 302 } 303 304 | Popular Tags |