001/* 002 * ModeShape (http://www.modeshape.org) 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.modeshape.common.collection; 017 018import java.util.Collection; 019import java.util.Collections; 020import java.util.HashMap; 021import java.util.HashSet; 022 023/** 024 * A {@link Multimap} implementation that uses an {@link HashSet} to store the values associated with a key. This implementation 025 * does not allow duplicates and the values are not ordered. 026 * 027 * @param <K> the key type 028 * @param <V> the value type 029 */ 030public class HashMultimap<K, V> extends AbstractMultimap<K, V> { 031 032 /** 033 * Creates a new, empty {@code LinkedHashMultimap} (that allows no duplicates) with the default initial capacity. 034 * 035 * @param <K> the key type 036 * @param <V> the value type 037 * @return the new linked-hash multimap; never null 038 */ 039 public static <K, V> HashMultimap<K, V> create() { 040 return new HashMultimap<K, V>(); 041 } 042 043 protected HashMultimap() { 044 super(new HashMap<K, Collection<V>>()); 045 } 046 047 @Override 048 protected Collection<V> createCollection() { 049 return new HashSet<V>(); 050 } 051 052 @Override 053 protected Collection<V> createUnmodifiableEmptyCollection() { 054 return Collections.emptyList(); 055 } 056}