001: /*
002: * Copyright 2003-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.map;
017:
018: import java.util.Collection;
019: import java.util.Map;
020: import java.util.Set;
021:
022: /**
023: * Provides a base decorator that enables additional functionality to be added
024: * to a Map via decoration.
025: * <p>
026: * Methods are forwarded directly to the decorated map.
027: * <p>
028: * This implementation does not perform any special processing with
029: * {@link #entrySet()}, {@link #keySet()} or {@link #values()}. Instead
030: * it simply returns the set/collection from the wrapped map. This may be
031: * undesirable, for example if you are trying to write a validating
032: * implementation it would provide a loophole around the validation.
033: * But, you might want that loophole, so this class is kept simple.
034: *
035: * @since Commons Collections 3.0
036: * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
037: *
038: * @author Daniel Rall
039: * @author Stephen Colebourne
040: */
041: public abstract class AbstractMapDecorator implements Map {
042:
043: /** The map to decorate */
044: protected transient Map map;
045:
046: /**
047: * Constructor only used in deserialization, do not use otherwise.
048: * @since Commons Collections 3.1
049: */
050: protected AbstractMapDecorator() {
051: super ();
052: }
053:
054: /**
055: * Constructor that wraps (not copies).
056: *
057: * @param map the map to decorate, must not be null
058: * @throws IllegalArgumentException if the collection is null
059: */
060: public AbstractMapDecorator(Map map) {
061: if (map == null) {
062: throw new IllegalArgumentException("Map must not be null");
063: }
064: this .map = map;
065: }
066:
067: /**
068: * Gets the map being decorated.
069: *
070: * @return the decorated map
071: */
072: protected Map getMap() {
073: return map;
074: }
075:
076: //-----------------------------------------------------------------------
077: public void clear() {
078: map.clear();
079: }
080:
081: public boolean containsKey(Object key) {
082: return map.containsKey(key);
083: }
084:
085: public boolean containsValue(Object value) {
086: return map.containsValue(value);
087: }
088:
089: public Set entrySet() {
090: return map.entrySet();
091: }
092:
093: public Object get(Object key) {
094: return map.get(key);
095: }
096:
097: public boolean isEmpty() {
098: return map.isEmpty();
099: }
100:
101: public Set keySet() {
102: return map.keySet();
103: }
104:
105: public Object put(Object key, Object value) {
106: return map.put(key, value);
107: }
108:
109: public void putAll(Map mapToCopy) {
110: map.putAll(mapToCopy);
111: }
112:
113: public Object remove(Object key) {
114: return map.remove(key);
115: }
116:
117: public int size() {
118: return map.size();
119: }
120:
121: public Collection values() {
122: return map.values();
123: }
124:
125: public boolean equals(Object object) {
126: if (object == this ) {
127: return true;
128: }
129: return map.equals(object);
130: }
131:
132: public int hashCode() {
133: return map.hashCode();
134: }
135:
136: public String toString() {
137: return map.toString();
138: }
139:
140: }
|