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