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.JDOUserException; 29 30 33 public class StringIdentity extends SingleFieldIdentity { 34 35 37 38 42 public StringIdentity (Class pcClass, String key) { 43 super (pcClass); 44 setKeyAsObject(key); 45 hashCode = hashClassName() ^ key.hashCode(); 46 } 47 48 50 public StringIdentity () { 51 } 52 53 56 public String getKey () { 57 return (String )keyAsObject; 58 } 59 60 63 public String toString () { 64 return (String )keyAsObject; 65 } 66 67 71 public boolean equals (Object obj) { 72 if (this == obj) { 73 return true; 74 } else if (!super.equals (obj)) { 75 return false; 76 } else { 77 StringIdentity other = (StringIdentity) obj; 78 return keyAsObject.equals(other.keyAsObject); 79 } 80 } 81 82 85 public void writeExternal(ObjectOutput out) throws IOException { 86 super.writeExternal (out); 87 out.writeObject(keyAsObject); 88 } 89 90 93 public void readExternal(ObjectInput in) 94 throws IOException , ClassNotFoundException { 95 super.readExternal (in); 96 keyAsObject = (String )in.readObject(); 97 } 98 } 99 | Popular Tags |