%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.torque.om.ObjectKey |
|
|
1 | package org.apache.torque.om; |
|
2 | ||
3 | /* |
|
4 | * Copyright 2001-2005 The Apache Software Foundation. |
|
5 | * |
|
6 | * Licensed under the Apache License, Version 2.0 (the "License") |
|
7 | * you may not use this file except in compliance with the License. |
|
8 | * You may obtain a copy of the License at |
|
9 | * |
|
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | * |
|
12 | * Unless required by applicable law or agreed to in writing, software |
|
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | * See the License for the specific language governing permissions and |
|
16 | * limitations under the License. |
|
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 | 178 | { |
43 | 178 | key = null; |
44 | 178 | } |
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 | 0 | if (key == null) |
55 | { |
|
56 | 0 | return super.hashCode(); |
57 | } |
|
58 | 0 | return key.hashCode(); |
59 | } |
|
60 | ||
61 | /** |
|
62 | * Get the underlying object. |
|
63 | * |
|
64 | * @return the underlying object |
|
65 | */ |
|
66 | public Object getValue() |
|
67 | { |
|
68 | 43 | 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 | 10 | sb.append(this.toString()); |
79 | 10 | } |
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 | 0 | 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 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |