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 ByteIdentity extends SingleFieldIdentity { 32 33 35 private byte key; 36 37 39 private void construct(byte key) { 40 this.key = key; 41 hashCode = super.hashClassName() ^ key; 42 } 43 44 48 public ByteIdentity(Class pcClass, byte key) { 49 super(pcClass); 50 construct(key); 51 } 52 53 57 public ByteIdentity(Class pcClass, Byte key) { 58 super(pcClass); 59 setKeyAsObject(key); 60 construct(key.byteValue()); 61 } 62 63 67 public ByteIdentity(Class pcClass, String str) { 68 super(pcClass); 69 assertKeyNotNull(str); 70 construct(Byte.parseByte(str)); 71 } 72 73 75 public ByteIdentity() { 76 } 77 78 81 public byte getKey() { 82 return key; 83 } 84 85 88 public String toString() { 89 return Byte.toString(key); 90 } 91 92 96 public boolean equals(Object obj) { 97 if (this == obj) { 98 return true; 99 } else if (!super.equals (obj)) { 100 return false; 101 } else { 102 ByteIdentity other = (ByteIdentity)obj; 103 return key == other.key; 104 } 105 } 106 107 111 protected Object createKeyAsObject() { 112 return new Byte (key); 113 } 114 115 118 public void writeExternal(ObjectOutput out) throws IOException { 119 super.writeExternal (out); 120 out.writeByte (key); 121 } 122 123 126 public void readExternal(ObjectInput in) 127 throws IOException , ClassNotFoundException { 128 super.readExternal (in); 129 key = in.readByte (); 130 } 131 } 132 | Popular Tags |