01: /*
02: * Copyright 2003-2006 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.apache.commons.collections.keyvalue;
17:
18: import java.util.Map;
19:
20: import org.apache.commons.collections.KeyValue;
21:
22: /**
23: * Provides a base decorator that allows additional functionality to be
24: * added to a {@link java.util.Map.Entry Map.Entry}.
25: *
26: * @since Commons Collections 3.0
27: * @version $Revision: 405927 $ $Date: 2006-05-12 23:57:03 +0100 (Fri, 12 May 2006) $
28: *
29: * @author Stephen Colebourne
30: */
31: public abstract class AbstractMapEntryDecorator implements Map.Entry,
32: KeyValue {
33:
34: /** The <code>Map.Entry</code> to decorate */
35: protected final Map.Entry entry;
36:
37: /**
38: * Constructor that wraps (not copies).
39: *
40: * @param entry the <code>Map.Entry</code> to decorate, must not be null
41: * @throws IllegalArgumentException if the collection is null
42: */
43: public AbstractMapEntryDecorator(Map.Entry entry) {
44: if (entry == null) {
45: throw new IllegalArgumentException(
46: "Map Entry must not be null");
47: }
48: this .entry = entry;
49: }
50:
51: /**
52: * Gets the map being decorated.
53: *
54: * @return the decorated map
55: */
56: protected Map.Entry getMapEntry() {
57: return entry;
58: }
59:
60: //-----------------------------------------------------------------------
61: public Object getKey() {
62: return entry.getKey();
63: }
64:
65: public Object getValue() {
66: return entry.getValue();
67: }
68:
69: public Object setValue(Object object) {
70: return entry.setValue(object);
71: }
72:
73: public boolean equals(Object object) {
74: if (object == this ) {
75: return true;
76: }
77: return entry.equals(object);
78: }
79:
80: public int hashCode() {
81: return entry.hashCode();
82: }
83:
84: public String toString() {
85: return entry.toString();
86: }
87:
88: }
|