1 9 10 package org.jboss.util; 11 12 import java.io.Serializable ; 13 14 20 public class MuCharacter 21 implements Comparable , Cloneable , Serializable , Mutable 22 { 23 static final long serialVersionUID = 1397485614608419257L; 24 25 private char value = 0; 26 27 30 public MuCharacter() {} 31 32 37 public MuCharacter(char c) { 38 value = c; 39 } 40 41 46 public MuCharacter(Object obj) { 47 setValue(obj); 48 } 49 50 56 public char set(char c) { 57 char old = value; 58 value = c; 59 return old; 60 } 61 62 67 public char get() { 68 return value; 69 } 70 71 76 public char charValue() { 77 return value; 78 } 79 80 88 public int compareTo(char other) { 89 return (value < other) ? -1 : (value == other) ? 0 : 1; 90 } 91 92 102 public int compareTo(Object obj) { 103 return compareTo((MuCharacter)obj); 104 } 105 106 111 public String toString() { 112 return String.valueOf(value); 113 } 114 115 120 public int hashCode() { 121 return value; 122 } 123 124 130 public boolean equals(Object obj) { 131 if (obj == this) return true; 132 133 if (obj != null && obj.getClass() == getClass()) { 134 return value == ((MuCharacter)obj).charValue(); 135 } 136 137 return false; 138 } 139 140 145 public Object clone() { 146 try { 147 return super.clone(); 148 } 149 catch (CloneNotSupportedException e) { 150 throw new InternalError (); 151 } 152 } 153 154 155 159 166 public void setValue(Object obj) { 167 if (obj instanceof MuCharacter) { 168 value = ((MuCharacter)obj).value; 169 } 170 else if (obj instanceof Character ) { 171 value = ((Character )obj).charValue(); 172 } 173 else if (obj instanceof Number ) { 174 value = (char)((Number )obj).intValue(); 175 } 176 else { 177 throw new NotCoercibleException("can not convert to 'char': " + obj); 178 } 179 } 180 181 186 public Object getValue() { 187 return new Character (value); 188 } 189 } 190 191 | Popular Tags |