001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.commons.collections.keyvalue; 018 019 import java.util.Map; 020 021 import org.apache.commons.collections.KeyValue; 022 023 /** 024 * Provides a base decorator that allows additional functionality to be 025 * added to a {@link java.util.Map.Entry Map.Entry}. 026 * 027 * @since Commons Collections 3.0 028 * @version $Revision: 646777 $ $Date: 2008-04-10 13:33:15 +0100 (Thu, 10 Apr 2008) $ 029 * 030 * @author Stephen Colebourne 031 */ 032 public abstract class AbstractMapEntryDecorator implements Map.Entry, KeyValue { 033 034 /** The <code>Map.Entry</code> to decorate */ 035 protected final Map.Entry entry; 036 037 /** 038 * Constructor that wraps (not copies). 039 * 040 * @param entry the <code>Map.Entry</code> to decorate, must not be null 041 * @throws IllegalArgumentException if the collection is null 042 */ 043 public AbstractMapEntryDecorator(Map.Entry entry) { 044 if (entry == null) { 045 throw new IllegalArgumentException("Map Entry must not be null"); 046 } 047 this.entry = entry; 048 } 049 050 /** 051 * Gets the map being decorated. 052 * 053 * @return the decorated map 054 */ 055 protected Map.Entry getMapEntry() { 056 return entry; 057 } 058 059 //----------------------------------------------------------------------- 060 public Object getKey() { 061 return entry.getKey(); 062 } 063 064 public Object getValue() { 065 return entry.getValue(); 066 } 067 068 public Object setValue(Object object) { 069 return entry.setValue(object); 070 } 071 072 public boolean equals(Object object) { 073 if (object == this) { 074 return true; 075 } 076 return entry.equals(object); 077 } 078 079 public int hashCode() { 080 return entry.hashCode(); 081 } 082 083 public String toString() { 084 return entry.toString(); 085 } 086 087 }