1 | /*
|
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
|
---|
3 | * contributor license agreements. See the NOTICE file distributed with
|
---|
4 | * this work for additional information regarding copyright ownership.
|
---|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
|
---|
6 | * (the "License"); you may not use this file except in compliance with
|
---|
7 | * the License. You may obtain a copy of the License at
|
---|
8 | *
|
---|
9 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
10 | *
|
---|
11 | * Unless required by applicable law or agreed to in writing, software
|
---|
12 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
14 | * See the License for the specific language governing permissions and
|
---|
15 | * limitations under the License.
|
---|
16 | */
|
---|
17 | package org.apache.commons.collections.map;
|
---|
18 |
|
---|
19 | import java.util.Collection;
|
---|
20 | import java.util.Map;
|
---|
21 | import java.util.Set;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Provides a base decorator that enables additional functionality to be added
|
---|
25 | * to a Map via decoration.
|
---|
26 | * <p>
|
---|
27 | * Methods are forwarded directly to the decorated map.
|
---|
28 | * <p>
|
---|
29 | * This implementation does not perform any special processing with
|
---|
30 | * {@link #entrySet()}, {@link #keySet()} or {@link #values()}. Instead
|
---|
31 | * it simply returns the set/collection from the wrapped map. This may be
|
---|
32 | * undesirable, for example if you are trying to write a validating
|
---|
33 | * implementation it would provide a loophole around the validation.
|
---|
34 | * But, you might want that loophole, so this class is kept simple.
|
---|
35 | *
|
---|
36 | * @since Commons Collections 3.0
|
---|
37 | * @version $Revision: 646777 $ $Date: 2008-04-10 14:33:15 +0200 (jeu., 10 avr. 2008) $
|
---|
38 | *
|
---|
39 | * @author Daniel Rall
|
---|
40 | * @author Stephen Colebourne
|
---|
41 | */
|
---|
42 | public abstract class AbstractMapDecorator implements Map {
|
---|
43 |
|
---|
44 | /** The map to decorate */
|
---|
45 | protected transient Map map;
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Constructor only used in deserialization, do not use otherwise.
|
---|
49 | * @since Commons Collections 3.1
|
---|
50 | */
|
---|
51 | protected AbstractMapDecorator() {
|
---|
52 | super();
|
---|
53 | }
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * Constructor that wraps (not copies).
|
---|
57 | *
|
---|
58 | * @param map the map to decorate, must not be null
|
---|
59 | * @throws IllegalArgumentException if the collection is null
|
---|
60 | */
|
---|
61 | public AbstractMapDecorator(Map map) {
|
---|
62 | if (map == null) {
|
---|
63 | throw new IllegalArgumentException("Map must not be null");
|
---|
64 | }
|
---|
65 | this.map = map;
|
---|
66 | }
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Gets the map being decorated.
|
---|
70 | *
|
---|
71 | * @return the decorated map
|
---|
72 | */
|
---|
73 | protected Map getMap() {
|
---|
74 | return map;
|
---|
75 | }
|
---|
76 |
|
---|
77 | //-----------------------------------------------------------------------
|
---|
78 | public void clear() {
|
---|
79 | map.clear();
|
---|
80 | }
|
---|
81 |
|
---|
82 | public boolean containsKey(Object key) {
|
---|
83 | return map.containsKey(key);
|
---|
84 | }
|
---|
85 |
|
---|
86 | public boolean containsValue(Object value) {
|
---|
87 | return map.containsValue(value);
|
---|
88 | }
|
---|
89 |
|
---|
90 | public Set entrySet() {
|
---|
91 | return map.entrySet();
|
---|
92 | }
|
---|
93 |
|
---|
94 | public Object get(Object key) {
|
---|
95 | return map.get(key);
|
---|
96 | }
|
---|
97 |
|
---|
98 | public boolean isEmpty() {
|
---|
99 | return map.isEmpty();
|
---|
100 | }
|
---|
101 |
|
---|
102 | public Set keySet() {
|
---|
103 | return map.keySet();
|
---|
104 | }
|
---|
105 |
|
---|
106 | public Object put(Object key, Object value) {
|
---|
107 | return map.put(key, value);
|
---|
108 | }
|
---|
109 |
|
---|
110 | public void putAll(Map mapToCopy) {
|
---|
111 | map.putAll(mapToCopy);
|
---|
112 | }
|
---|
113 |
|
---|
114 | public Object remove(Object key) {
|
---|
115 | return map.remove(key);
|
---|
116 | }
|
---|
117 |
|
---|
118 | public int size() {
|
---|
119 | return map.size();
|
---|
120 | }
|
---|
121 |
|
---|
122 | public Collection values() {
|
---|
123 | return map.values();
|
---|
124 | }
|
---|
125 |
|
---|
126 | public boolean equals(Object object) {
|
---|
127 | if (object == this) {
|
---|
128 | return true;
|
---|
129 | }
|
---|
130 | return map.equals(object);
|
---|
131 | }
|
---|
132 |
|
---|
133 | public int hashCode() {
|
---|
134 | return map.hashCode();
|
---|
135 | }
|
---|
136 |
|
---|
137 | public String toString() {
|
---|
138 | return map.toString();
|
---|
139 | }
|
---|
140 |
|
---|
141 | }
|
---|