1. /*
  2. * Copyright 2002-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  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;
  17. import java.util.Collection;
  18. import java.util.Map;
  19. import java.util.Set;
  20. /**
  21. * <p>This <code>Map</code> wraps another <code>Map</code>
  22. * implementation, using the wrapped instance for its default
  23. * implementation. This class is used as a framework on which to
  24. * build to extensions for its wrapped <code>Map</code> object which
  25. * would be unavailable or inconvenient via sub-classing (but usable
  26. * via composition).</p>
  27. *
  28. * <p>This implementation does not perform any special processing with
  29. * {@link #entrySet()}, {@link #keySet()} or {@link #values()}. Instead
  30. * it simply returns the set/collection from the wrapped map. This may be
  31. * undesirable, for example if you are trying to write a validating
  32. * implementation it would provide a loophole around the validation. But,
  33. * you might want that loophole, so this class is kept simple.</p>
  34. *
  35. * @deprecated Moved to map subpackage as AbstractMapDecorator. It will be removed in v4.0.
  36. * @since Commons Collections 2.0
  37. * @version $Revision: 1.15 $ $Date: 2004/02/18 01:15:42 $
  38. *
  39. * @author Daniel Rall
  40. * @author Stephen Colebourne
  41. */
  42. public abstract class ProxyMap implements Map {
  43. /**
  44. * The <code>Map</code> to delegate to.
  45. */
  46. protected Map map;
  47. /**
  48. * Constructor that uses the specified map to delegate to.
  49. * <p>
  50. * Note that the map is used for delegation, and is not copied. This is
  51. * different to the normal use of a <code>Map</code> parameter in
  52. * collections constructors.
  53. *
  54. * @param map the <code>Map</code> to delegate to
  55. */
  56. public ProxyMap(Map map) {
  57. this.map = map;
  58. }
  59. /**
  60. * Invokes the underlying {@link Map#clear()} method.
  61. */
  62. public void clear() {
  63. map.clear();
  64. }
  65. /**
  66. * Invokes the underlying {@link Map#containsKey(Object)} method.
  67. */
  68. public boolean containsKey(Object key) {
  69. return map.containsKey(key);
  70. }
  71. /**
  72. * Invokes the underlying {@link Map#containsValue(Object)} method.
  73. */
  74. public boolean containsValue(Object value) {
  75. return map.containsValue(value);
  76. }
  77. /**
  78. * Invokes the underlying {@link Map#entrySet()} method.
  79. */
  80. public Set entrySet() {
  81. return map.entrySet();
  82. }
  83. /**
  84. * Invokes the underlying {@link Map#equals(Object)} method.
  85. */
  86. public boolean equals(Object m) {
  87. return map.equals(m);
  88. }
  89. /**
  90. * Invokes the underlying {@link Map#get(Object)} method.
  91. */
  92. public Object get(Object key) {
  93. return map.get(key);
  94. }
  95. /**
  96. * Invokes the underlying {@link Map#hashCode()} method.
  97. */
  98. public int hashCode() {
  99. return map.hashCode();
  100. }
  101. /**
  102. * Invokes the underlying {@link Map#isEmpty()} method.
  103. */
  104. public boolean isEmpty() {
  105. return map.isEmpty();
  106. }
  107. /**
  108. * Invokes the underlying {@link Map#keySet()} method.
  109. */
  110. public Set keySet() {
  111. return map.keySet();
  112. }
  113. /**
  114. * Invokes the underlying {@link Map#put(Object,Object)} method.
  115. */
  116. public Object put(Object key, Object value) {
  117. return map.put(key, value);
  118. }
  119. /**
  120. * Invokes the underlying {@link Map#putAll(Map)} method.
  121. */
  122. public void putAll(Map t) {
  123. map.putAll(t);
  124. }
  125. /**
  126. * Invokes the underlying {@link Map#remove(Object)} method.
  127. */
  128. public Object remove(Object key) {
  129. return map.remove(key);
  130. }
  131. /**
  132. * Invokes the underlying {@link Map#size()} method.
  133. */
  134. public int size() {
  135. return map.size();
  136. }
  137. /**
  138. * Invokes the underlying {@link Map#values()} method.
  139. */
  140. public Collection values() {
  141. return map.values();
  142. }
  143. }