1
package org.apache.lucene.util;
4
* Licensed to the Apache Software Foundation (ASF) under one or more
5
* contributor license agreements. See the NOTICE file distributed with
6
* this work for additional information regarding copyright ownership.
7
* The ASF licenses this file to You under the Apache License, Version 2.0
8
* (the "License"); you may not use this file except in compliance with
9
* the License. You may obtain a copy of the License at
11
* http://www.apache.org/licenses/LICENSE-2.0
13
* Unless required by applicable law or agreed to in writing, software
14
* distributed under the License is distributed on an "AS IS" BASIS,
15
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
* See the License for the specific language governing permissions and
17
* limitations under the License.
22
import java.util.Collection;
23
import java.util.HashSet;
27
* Helper class for keeping Lists of Objects associated with keys. <b>WARNING: THIS CLASS IS NOT THREAD SAFE</b>
30
public class MapOfSets<K, V> {
32
private final Map<K, Set<V>> theMap;
35
* @param m the backing store for this object
37
public MapOfSets(Map<K, Set<V>> m) {
42
* @return direct access to the map backing this object.
44
public Map<K, Set<V>> getMap() {
49
* Adds val to the Set associated with key in the Map. If key is not
50
* already in the map, a new Set will first be created.
51
* @return the size of the Set associated with key once val is added to it.
53
public int put(K key, V val) {
55
if (theMap.containsKey(key)) {
56
theSet = theMap.get(key);
58
theSet = new HashSet<V>(23);
59
theMap.put(key, theSet);
65
* Adds multiple vals to the Set associated with key in the Map.
67
* already in the map, a new Set will first be created.
68
* @return the size of the Set associated with key once val is added to it.
70
public int putAll(K key, Collection<? extends V> vals) {
72
if (theMap.containsKey(key)) {
73
theSet = theMap.get(key);
75
theSet = new HashSet<V>(23);
76
theMap.put(key, theSet);