1 16 17 21 22 package javax.jdo.identity; 23 24 import java.io.IOException ; 25 import java.io.ObjectInput ; 26 import java.io.ObjectOutput ; 27 28 import javax.jdo.spi.I18NHelper; 29 30 33 public class CharIdentity extends SingleFieldIdentity { 34 35 37 private static I18NHelper msg = I18NHelper.getInstance ("javax.jdo.Bundle"); 39 41 private char key; 42 43 private void construct(char key) { 44 this.key = key; 45 hashCode = hashClassName() ^ key; 46 } 47 48 52 public CharIdentity (Class pcClass, char key) { 53 super (pcClass); 54 construct(key); 55 } 56 57 61 public CharIdentity (Class pcClass, Character key) { 62 super (pcClass); 63 setKeyAsObject(key); 64 construct(key.charValue()); 65 } 66 67 72 public CharIdentity (Class pcClass, String str) { 73 super(pcClass); 74 assertKeyNotNull(str); 75 if (str.length() != 1) 76 throw new IllegalArgumentException ( 77 msg.msg("EXC_StringWrongLength")); construct(str.charAt(0)); 79 } 80 81 83 public CharIdentity () { 84 } 85 86 89 public char getKey () { 90 return key; 91 } 92 93 96 public String toString () { 97 return Character.toString(key); 98 } 99 100 104 public boolean equals (Object obj) { 105 if (this == obj) { 106 return true; 107 } else if (!super.equals (obj)) { 108 return false; 109 } else { 110 CharIdentity other = (CharIdentity) obj; 111 return key == other.key; 112 } 113 } 114 115 119 protected Object createKeyAsObject() { 120 return new Character (key); 121 } 122 123 126 public void writeExternal(ObjectOutput out) throws IOException { 127 super.writeExternal (out); 128 out.writeChar(key); 129 } 130 131 134 public void readExternal(ObjectInput in) 135 throws IOException , ClassNotFoundException { 136 super.readExternal (in); 137 key = in.readChar(); 138 } 139 140 private void computeHashCode() { 141 hashCode = hashClassName() ^ key; 142 } 143 } 144 | Popular Tags |