KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > torque > om > ObjectKey


1 package org.apache.torque.om;
2
3 /*
4  * Licensed to the Apache Software Foundation (ASF) under one
5  * or more contributor license agreements. See the NOTICE file
6  * distributed with this work for additional information
7  * regarding copyright ownership. The ASF licenses this file
8  * to you under the Apache License, Version 2.0 (the
9  * "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 JavaDoc;
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 JavaDoc, Comparable JavaDoc
35 {
36     /**
37      * The underlying key value.
38      */

39     protected Object JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc s) throws TorqueException;
102 }
103
Popular Tags