1 6 package javax.jdo; 7 8 import java.io.Serializable ; 9 10 public class SimpleIdentity implements Serializable { 11 12 private SimpleIdentity(Class cls) { 13 targetClass = cls; 14 targetClassName = cls.getName(); 15 } 16 17 public static SimpleIdentity newInstance(Class cls, byte key) { 18 SimpleIdentity si = new SimpleIdentity(cls); 19 si.byteKey = key; 20 return si; 21 } 22 23 public static SimpleIdentity newInstance(Class cls, short key) { 24 SimpleIdentity si = new SimpleIdentity(cls); 25 si.shortKey = key; 26 return si; 27 } 28 29 public static SimpleIdentity newInstance(Class cls, int key) { 30 SimpleIdentity si = new SimpleIdentity(cls); 31 si.intKey = key; 32 return si; 33 } 34 35 public static SimpleIdentity newInstance(Class cls, long key) { 36 SimpleIdentity si = new SimpleIdentity(cls); 37 si.longKey = key; 38 return si; 39 } 40 41 public static SimpleIdentity newInstance(Class cls, Object key) { 42 SimpleIdentity si = new SimpleIdentity(cls); 43 si.objectKey = key; 44 return si; 45 } 46 47 public static SimpleIdentity newInstance(Class cls, String key) { 48 SimpleIdentity si = new SimpleIdentity(cls); 49 si.stringKey = key; 50 return si; 51 } 52 53 public byte getByteKey() { 54 return byteKey; 55 } 56 57 public int getIntKey() { 58 return intKey; 59 } 60 61 public long getLongKey() { 62 return longKey; 63 } 64 65 public Object getObjectKey() { 66 return objectKey; 67 } 68 69 public short getShortKey() { 70 return shortKey; 71 } 72 73 public String getStringKey() { 74 return stringKey; 75 } 76 77 public Class getTargetClass() { 78 return targetClass; 79 } 80 81 public String getTargetClassName() { 82 return targetClassName; 83 } 84 85 public boolean equals(Object obj) { 86 return (obj instanceof SimpleIdentity) 87 && toString().equals(obj.toString()); 88 } 89 90 public String toString() { 91 StringBuffer sb = new StringBuffer (); 92 sb.append(targetClassName); 93 sb.append("-"); 94 sb.append(String.valueOf(byteKey)); 95 sb.append("-"); 96 sb.append(String.valueOf(shortKey)); 97 sb.append("-"); 98 sb.append(String.valueOf(intKey)); 99 sb.append("-"); 100 sb.append(String.valueOf(longKey)); 101 sb.append("-"); 102 sb.append(String.valueOf(objectKey)); 103 sb.append("-"); 104 sb.append(String.valueOf(targetClassName)); 105 return sb.toString(); 106 } 107 108 private byte byteKey; 109 110 private short shortKey; 111 112 private int intKey; 113 114 private long longKey; 115 116 private Object objectKey; 117 118 private String stringKey; 119 120 private transient Class targetClass; 121 122 private String targetClassName; 123 } | Popular Tags |