01: package org.apache.torque.om;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
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: * The underlying key value.
37: */
38: protected Object key;
39:
40: /**
41: * Initializes the internal key value to <code>null</code>.
42: */
43: protected ObjectKey() {
44: key = null;
45: }
46:
47: /**
48: * Returns the hashcode of the underlying value (key), if key is
49: * not null. Otherwise calls Object.hashCode()
50: *
51: * @return an <code>int</code> value
52: */
53: public int hashCode() {
54: if (key == null) {
55: return super .hashCode();
56: }
57: return key.hashCode();
58: }
59:
60: /**
61: * Get the underlying object.
62: *
63: * @return the underlying object
64: */
65: public Object getValue() {
66: return key;
67: }
68:
69: /**
70: * Appends a String representation of the key to a buffer.
71: *
72: * @param sb a <code>StringBuffer</code>
73: */
74: public void appendTo(StringBuffer sb) {
75: sb.append(this .toString());
76: }
77:
78: /**
79: * Implements the compareTo method.
80: *
81: * @param obj the object to compare to this object
82: * @return a numeric comparison of the two values
83: */
84: public int compareTo(Object obj) {
85: return toString().compareTo(obj.toString());
86: }
87:
88: /**
89: * Reset the underlying object using a String.
90: *
91: * @param s a <code>String</code> value
92: * @exception TorqueException if an error occurs
93: */
94: public abstract void setValue(String s) throws TorqueException;
95: }
|