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 */ 017package org.apache.commons.collections4.keyvalue; 018 019import java.util.Map; 020 021import org.apache.commons.collections4.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 3.0 028 * @version $Id: AbstractMapEntryDecorator.html 972421 2015-11-14 20:00:04Z tn $ 029 */ 030public abstract class AbstractMapEntryDecorator<K, V> implements Map.Entry<K, V>, KeyValue<K, V> { 031 032 /** The <code>Map.Entry</code> to decorate */ 033 private final Map.Entry<K, V> entry; 034 035 /** 036 * Constructor that wraps (not copies). 037 * 038 * @param entry the <code>Map.Entry</code> to decorate, must not be null 039 * @throws IllegalArgumentException if the collection is null 040 */ 041 public AbstractMapEntryDecorator(final Map.Entry<K, V> entry) { 042 if (entry == null) { 043 throw new IllegalArgumentException("Map Entry must not be null"); 044 } 045 this.entry = entry; 046 } 047 048 /** 049 * Gets the map being decorated. 050 * 051 * @return the decorated map 052 */ 053 protected Map.Entry<K, V> getMapEntry() { 054 return entry; 055 } 056 057 //----------------------------------------------------------------------- 058 059 public K getKey() { 060 return entry.getKey(); 061 } 062 063 public V getValue() { 064 return entry.getValue(); 065 } 066 067 public V setValue(final V object) { 068 return entry.setValue(object); 069 } 070 071 @Override 072 public boolean equals(final Object object) { 073 if (object == this) { 074 return true; 075 } 076 return entry.equals(object); 077 } 078 079 @Override 080 public int hashCode() { 081 return entry.hashCode(); 082 } 083 084 @Override 085 public String toString() { 086 return entry.toString(); 087 } 088 089}