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 IntIdentity extends SingleFieldIdentity { 32 33 private int key; 34 35 private void construct(int key) { 36 this.key = key; 37 hashCode = hashClassName() ^ key; 38 } 39 40 44 public IntIdentity (Class pcClass, int key) { 45 super(pcClass); 46 construct(key); 47 } 48 49 53 public IntIdentity (Class pcClass, Integer key) { 54 super(pcClass); 55 setKeyAsObject(key); 56 construct(key.intValue ()); 57 } 58 59 60 64 public IntIdentity (Class pcClass, String str) { 65 super(pcClass); 66 assertKeyNotNull(str); 67 construct(Integer.parseInt(str)); 68 } 69 70 72 public IntIdentity () { 73 } 74 75 78 public int getKey () { 79 return key; 80 } 81 82 85 public String toString () { 86 return Integer.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 IntIdentity other = (IntIdentity) obj; 100 return key == other.key; 101 } 102 } 103 104 108 protected Object createKeyAsObject() { 109 return new Integer (key); 110 } 111 112 115 public void writeExternal(ObjectOutput out) throws IOException { 116 super.writeExternal (out); 117 out.writeInt(key); 118 } 119 120 123 public void readExternal(ObjectInput in) 124 throws IOException , ClassNotFoundException { 125 super.readExternal (in); 126 key = in.readInt(); 127 } 128 } 129 | Popular Tags |