001: /*
002: * Copyright 2002-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.collections;
017:
018: import java.util.Collection;
019: import java.util.Map;
020: import java.util.Set;
021:
022: /**
023: * <p>This <code>Map</code> wraps another <code>Map</code>
024: * implementation, using the wrapped instance for its default
025: * implementation. This class is used as a framework on which to
026: * build to extensions for its wrapped <code>Map</code> object which
027: * would be unavailable or inconvenient via sub-classing (but usable
028: * via composition).</p>
029: *
030: * <p>This implementation does not perform any special processing with
031: * {@link #entrySet()}, {@link #keySet()} or {@link #values()}. Instead
032: * it simply returns the set/collection from the wrapped map. This may be
033: * undesirable, for example if you are trying to write a validating
034: * implementation it would provide a loophole around the validation. But,
035: * you might want that loophole, so this class is kept simple.</p>
036: *
037: * @deprecated Moved to map subpackage as AbstractMapDecorator. It will be removed in v4.0.
038: * @since Commons Collections 2.0
039: * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
040: *
041: * @author Daniel Rall
042: * @author Stephen Colebourne
043: */
044: public abstract class ProxyMap implements Map {
045:
046: /**
047: * The <code>Map</code> to delegate to.
048: */
049: protected Map map;
050:
051: /**
052: * Constructor that uses the specified map to delegate to.
053: * <p>
054: * Note that the map is used for delegation, and is not copied. This is
055: * different to the normal use of a <code>Map</code> parameter in
056: * collections constructors.
057: *
058: * @param map the <code>Map</code> to delegate to
059: */
060: public ProxyMap(Map map) {
061: this .map = map;
062: }
063:
064: /**
065: * Invokes the underlying {@link Map#clear()} method.
066: */
067: public void clear() {
068: map.clear();
069: }
070:
071: /**
072: * Invokes the underlying {@link Map#containsKey(Object)} method.
073: */
074: public boolean containsKey(Object key) {
075: return map.containsKey(key);
076: }
077:
078: /**
079: * Invokes the underlying {@link Map#containsValue(Object)} method.
080: */
081: public boolean containsValue(Object value) {
082: return map.containsValue(value);
083: }
084:
085: /**
086: * Invokes the underlying {@link Map#entrySet()} method.
087: */
088: public Set entrySet() {
089: return map.entrySet();
090: }
091:
092: /**
093: * Invokes the underlying {@link Map#equals(Object)} method.
094: */
095: public boolean equals(Object m) {
096: return map.equals(m);
097: }
098:
099: /**
100: * Invokes the underlying {@link Map#get(Object)} method.
101: */
102: public Object get(Object key) {
103: return map.get(key);
104: }
105:
106: /**
107: * Invokes the underlying {@link Map#hashCode()} method.
108: */
109: public int hashCode() {
110: return map.hashCode();
111: }
112:
113: /**
114: * Invokes the underlying {@link Map#isEmpty()} method.
115: */
116: public boolean isEmpty() {
117: return map.isEmpty();
118: }
119:
120: /**
121: * Invokes the underlying {@link Map#keySet()} method.
122: */
123: public Set keySet() {
124: return map.keySet();
125: }
126:
127: /**
128: * Invokes the underlying {@link Map#put(Object,Object)} method.
129: */
130: public Object put(Object key, Object value) {
131: return map.put(key, value);
132: }
133:
134: /**
135: * Invokes the underlying {@link Map#putAll(Map)} method.
136: */
137: public void putAll(Map t) {
138: map.putAll(t);
139: }
140:
141: /**
142: * Invokes the underlying {@link Map#remove(Object)} method.
143: */
144: public Object remove(Object key) {
145: return map.remove(key);
146: }
147:
148: /**
149: * Invokes the underlying {@link Map#size()} method.
150: */
151: public int size() {
152: return map.size();
153: }
154:
155: /**
156: * Invokes the underlying {@link Map#values()} method.
157: */
158: public Collection values() {
159: return map.values();
160: }
161:
162: }
|