1. /*
  2. * Copyright 2003-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.keyvalue;
  17. import java.util.Map;
  18. import org.apache.commons.collections.KeyValue;
  19. /**
  20. * Provides a base decorator that allows additional functionality to be added
  21. * to a Map Entry.
  22. *
  23. * @since Commons Collections 3.0
  24. * @version $Revision: 1.4 $ $Date: 2004/02/18 01:00:08 $
  25. *
  26. * @author Stephen Colebourne
  27. */
  28. public abstract class AbstractMapEntryDecorator implements Map.Entry, KeyValue {
  29. /** The <code>Map.Entry</code> to decorate */
  30. protected final Map.Entry entry;
  31. /**
  32. * Constructor that wraps (not copies).
  33. *
  34. * @param entry the <code>Map.Entry</code> to decorate, must not be null
  35. * @throws IllegalArgumentException if the collection is null
  36. */
  37. public AbstractMapEntryDecorator(Map.Entry entry) {
  38. if (entry == null) {
  39. throw new IllegalArgumentException("Map Entry must not be null");
  40. }
  41. this.entry = entry;
  42. }
  43. /**
  44. * Gets the map being decorated.
  45. *
  46. * @return the decorated map
  47. */
  48. protected Map.Entry getMapEntry() {
  49. return entry;
  50. }
  51. //-----------------------------------------------------------------------
  52. public Object getKey() {
  53. return entry.getKey();
  54. }
  55. public Object getValue() {
  56. return entry.getValue();
  57. }
  58. public Object setValue(Object object) {
  59. return entry.setValue(object);
  60. }
  61. public boolean equals(Object object) {
  62. if (object == this) {
  63. return true;
  64. }
  65. return entry.equals(object);
  66. }
  67. public int hashCode() {
  68. return entry.hashCode();
  69. }
  70. public String toString() {
  71. return entry.toString();
  72. }
  73. }