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 LongIdentity extends SingleFieldIdentity { 32 33 35 private long key; 36 37 private void construct(long key) { 38 this.key = key; 39 hashCode = hashClassName() ^ (int)key; 40 } 41 42 46 public LongIdentity (Class pcClass, long key) { 47 super (pcClass); 48 construct(key); 49 } 50 51 55 public LongIdentity (Class pcClass, Long key) { 56 super(pcClass); 57 setKeyAsObject(key); 58 construct(key.longValue()); 59 } 60 61 65 public LongIdentity (Class pcClass, String str) { 66 super(pcClass); 67 assertKeyNotNull(str); 68 construct(Long.parseLong(str)); 69 } 70 71 73 public LongIdentity () { 74 } 75 76 79 public long getKey () { 80 return key; 81 } 82 83 86 public String toString () { 87 return Long.toString(key); 88 } 89 90 94 public boolean equals (Object obj) { 95 if (this == obj) { 96 return true; 97 } else if (!super.equals (obj)) { 98 return false; 99 } else { 100 LongIdentity other = (LongIdentity) obj; 101 return key == other.key; 102 } 103 } 104 105 109 protected Object createKeyAsObject() { 110 return new Long (key); 111 } 112 113 116 public void writeExternal(ObjectOutput out) throws IOException { 117 super.writeExternal (out); 118 out.writeLong(key); 119 } 120 121 124 public void readExternal(ObjectInput in) 125 throws IOException , ClassNotFoundException { 126 super.readExternal (in); 127 key = in.readLong(); 128 } 129 130 } 131 | Popular Tags |