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