1 6 package javax.jdo; 7 8 import java.util.StringTokenizer ; 9 10 13 public class StringIdentity extends SingleFieldIdentity { 14 15 public StringIdentity(Class pcClass, String key) { 16 super(pcClass); 17 if (key == null) { 18 throw new NullPointerException ( 19 "key value passed to StringIdentity is null"); 20 } else { 21 StringTokenizer token = new StringTokenizer (key, "::"); 22 this.key = token.nextToken(); 23 return; 24 } 25 } 26 27 public String getKey() { 28 return key; 29 } 30 31 public int hashCode() { 32 return key.hashCode() ^ targetClassName.hashCode(); 33 } 34 35 public boolean equals(Object obj) { 36 if (obj == this) 37 return true; 38 if (!(obj instanceof StringIdentity)) { 39 return false; 40 } else { 41 StringIdentity other = (StringIdentity) obj; 42 return key.equals(other.key) 43 && targetClassName.equals(other.targetClassName); 44 } 45 } 46 47 public String toString() { 48 return "" + key + "::" + targetClassName; 49 } 50 51 private final String key; 52 } | Popular Tags |