1 package org.apache.torque.om;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.io.Serializable;
20 import org.apache.torque.TorqueException;
21
22 /***
23 * This class can be used to uniquely identify an object within
24 * an application. There are four subclasses: StringKey, NumberKey,
25 * and DateKey, and ComboKey which is a Key made up of a combination
26 * ofthe first three.
27 *
28 * @author <a href="mailto:jmcnally@apache.org">John McNally</a>
29 * @version $Id: ObjectKey.java 239630 2005-08-24 12:25:32Z henning $
30 */
31 public abstract class ObjectKey implements Serializable, Comparable
32 {
33 /***
34 * The underlying key value.
35 */
36 protected Object key;
37
38 /***
39 * Initializes the internal key value to <code>null</code>.
40 */
41 protected ObjectKey()
42 {
43 key = null;
44 }
45
46 /***
47 * Returns the hashcode of the underlying value (key), if key is
48 * not null. Otherwise calls Object.hashCode()
49 *
50 * @return an <code>int</code> value
51 */
52 public int hashCode()
53 {
54 if (key == null)
55 {
56 return super.hashCode();
57 }
58 return key.hashCode();
59 }
60
61 /***
62 * Get the underlying object.
63 *
64 * @return the underlying object
65 */
66 public Object getValue()
67 {
68 return key;
69 }
70
71 /***
72 * Appends a String representation of the key to a buffer.
73 *
74 * @param sb a <code>StringBuffer</code>
75 */
76 public void appendTo(StringBuffer sb)
77 {
78 sb.append(this.toString());
79 }
80
81 /***
82 * Implements the compareTo method.
83 *
84 * @param obj the object to compare to this object
85 * @return a numeric comparison of the two values
86 */
87 public int compareTo(Object obj)
88 {
89 return toString().compareTo(obj.toString());
90 }
91
92 /***
93 * Reset the underlying object using a String.
94 *
95 * @param s a <code>String</code> value
96 * @exception TorqueException if an error occurs
97 */
98 public abstract void setValue(String s) throws TorqueException;
99 }