01: /*
02: * Created on 10-Jul-2005
03: *
04: */
05: package com.jofti.cache;
06:
07: import java.io.Serializable;
08:
09: /**
10:
11: *
12: *The implmentation class for keys that do not implement Comparable.<p>
13: *
14: * @author Steve Woodcock (steve@jofti.com)<p>
15: */
16: public class NonComparableKeyWrapper implements
17: INonComparableKeyWrapper, Serializable {
18:
19: private static final long serialVersionUID = 7309788376554006517L;
20:
21: private Object key;
22:
23: public NonComparableKeyWrapper(Object key) {
24: this .key = key;
25: }
26:
27: public Object getKey() {
28: return key;
29: }
30:
31: /* (non-Javadoc)
32: * @see java.lang.Comparable#compareTo(java.lang.Object)
33: */
34: public int compareTo(Object o) {
35:
36: if (o instanceof INonComparableKeyWrapper) {
37: return key.toString().compareTo(
38: ((INonComparableKeyWrapper) o).getKey().toString());
39: } else {
40: return -1;
41: }
42: }
43:
44: public boolean equals(Object o) {
45: if (o instanceof INonComparableKeyWrapper) {
46: return key.equals(((INonComparableKeyWrapper) o).getKey());
47: } else {
48: return false;
49: }
50: }
51:
52: public int hashCode() {
53: return key.hashCode();
54: }
55:
56: public String toString() {
57: return key.toString();
58: }
59: }
|