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 31 public class ShortIdentity 32 extends SingleFieldIdentity 33 { 34 private short key; 35 36 private void construct(short key) { 37 this.key = key; 38 hashCode = hashClassName() ^ key; 39 } 40 41 45 public ShortIdentity (Class pcClass, short key) { 46 super(pcClass); 47 construct(key); 48 } 49 50 54 public ShortIdentity (Class pcClass, Short key) { 55 super(pcClass); 56 setKeyAsObject(key); 57 construct(key.shortValue()); 58 } 59 60 64 public ShortIdentity (Class pcClass, String str) { 65 super(pcClass); 66 assertKeyNotNull(str); 67 construct(Short.parseShort (str)); 68 } 69 70 72 public ShortIdentity () { 73 } 74 75 78 public short getKey () { 79 return key; 80 } 81 82 85 public String toString () { 86 return Short.toString(key); 87 } 88 89 93 public boolean equals (Object obj) { 94 if (this == obj) { 95 return true; 96 } else if (!super.equals (obj)) { 97 return false; 98 } else { 99 ShortIdentity other = (ShortIdentity) obj; 100 return key == other.key; 101 } 102 } 103 104 108 protected Object createKeyAsObject() { 109 return new Short (key); 110 } 111 112 115 public void writeExternal(ObjectOutput out) throws IOException { 116 super.writeExternal (out); 117 out.writeShort(key); 118 } 119 120 123 public void readExternal(ObjectInput in) 124 throws IOException , ClassNotFoundException { 125 super.readExternal (in); 126 key = in.readShort(); 127 } 128 } 129 | Popular Tags |