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.multimap; 018 019import java.io.Serializable; 020import java.util.Collection; 021import java.util.Map; 022import java.util.Map.Entry; 023import java.util.Set; 024 025import org.apache.commons.collections4.MapIterator; 026import org.apache.commons.collections4.MultiSet; 027import org.apache.commons.collections4.MultiValuedMap; 028 029/** 030 * Decorates another <code>MultiValuedMap</code> to provide additional behaviour. 031 * <p> 032 * Each method call made on this <code>MultiValuedMap</code> is forwarded to the 033 * decorated <code>MultiValuedMap</code>. This class is used as a framework to build 034 * to extensions such as synchronized and unmodifiable behaviour. 035 * 036 * @param <K> the type of key elements 037 * @param <V> the type of value elements 038 * 039 * @since 4.1 040 */ 041public abstract class AbstractMultiValuedMapDecorator<K, V> 042 implements MultiValuedMap<K, V>, Serializable { 043 044 /** Serialization version */ 045 private static final long serialVersionUID = 20150612L; 046 047 /** MultiValuedMap to decorate */ 048 private final MultiValuedMap<K, V> map; 049 050 /** 051 * Constructor that wraps (not copies). 052 * 053 * @param map the map to decorate, must not be null 054 * @throws NullPointerException if the map is null 055 */ 056 protected AbstractMultiValuedMapDecorator(final MultiValuedMap<K, V> map) { 057 if (map == null) { 058 throw new NullPointerException("MultiValuedMap must not be null."); 059 } 060 this.map = map; 061 } 062 063 // ----------------------------------------------------------------------- 064 /** 065 * The decorated multi-valued map. 066 * 067 * @return the map to decorate 068 */ 069 protected MultiValuedMap<K, V> decorated() { 070 return map; 071 } 072 073 // ----------------------------------------------------------------------- 074 @Override 075 public int size() { 076 return decorated().size(); 077 } 078 079 @Override 080 public boolean isEmpty() { 081 return decorated().isEmpty(); 082 } 083 084 @Override 085 public boolean containsKey(final Object key) { 086 return decorated().containsKey(key); 087 } 088 089 @Override 090 public boolean containsValue(final Object value) { 091 return decorated().containsValue(value); 092 } 093 094 @Override 095 public boolean containsMapping(final Object key, final Object value) { 096 return decorated().containsMapping(key, value); 097 } 098 099 @Override 100 public Collection<V> get(final K key) { 101 return decorated().get(key); 102 } 103 104 @Override 105 public Collection<V> remove(final Object key) { 106 return decorated().remove(key); 107 } 108 109 @Override 110 public boolean removeMapping(final Object key, final Object item) { 111 return decorated().removeMapping(key, item); 112 } 113 114 @Override 115 public void clear() { 116 decorated().clear(); 117 } 118 119 @Override 120 public boolean put(final K key, final V value) { 121 return decorated().put(key, value); 122 } 123 124 @Override 125 public Set<K> keySet() { 126 return decorated().keySet(); 127 } 128 129 @Override 130 public Collection<Entry<K, V>> entries() { 131 return decorated().entries(); 132 } 133 134 @Override 135 public MultiSet<K> keys() { 136 return decorated().keys(); 137 } 138 139 @Override 140 public Collection<V> values() { 141 return decorated().values(); 142 } 143 144 @Override 145 public Map<K, Collection<V>> asMap() { 146 return decorated().asMap(); 147 } 148 149 @Override 150 public boolean putAll(final K key, final Iterable<? extends V> values) { 151 return decorated().putAll(key, values); 152 } 153 154 @Override 155 public boolean putAll(final Map<? extends K, ? extends V> map) { 156 return decorated().putAll(map); 157 } 158 159 @Override 160 public boolean putAll(final MultiValuedMap<? extends K, ? extends V> map) { 161 return decorated().putAll(map); 162 } 163 164 @Override 165 public MapIterator<K, V> mapIterator() { 166 return decorated().mapIterator(); 167 } 168 169 @Override 170 public boolean equals(final Object object) { 171 if (object == this) { 172 return true; 173 } 174 return decorated().equals(object); 175 } 176 177 @Override 178 public int hashCode() { 179 return decorated().hashCode(); 180 } 181 182 @Override 183 public String toString() { 184 return decorated().toString(); 185 } 186 187}