Coverage Report - org.eclipse.swtbot.swt.finder.utils.MultiValueMap
 
Classes in this File Line Coverage Branch Coverage Complexity
MultiValueMap
100%
14/14
100%
4/4
1.75
 
 1  
 /*******************************************************************************
 2  
  * Copyright (c) 2008-2009 SWTBot Committers and others.
 3  
  * All rights reserved. This program and the accompanying materials
 4  
  * are made available under the terms of the Eclipse Public License v1.0
 5  
  * which accompanies this distribution, and is available at
 6  
  * http://www.eclipse.org/legal/epl-v10.html
 7  
  *
 8  
  * Contributors:
 9  
  *     Ketan Padegaonkar - initial API and implementation
 10  
  *******************************************************************************/
 11  
 package org.eclipse.swtbot.swt.finder.utils;
 12  
 
 13  
 import java.util.Collection;
 14  
 import java.util.Collections;
 15  
 import java.util.HashMap;
 16  
 import java.util.LinkedHashSet;
 17  
 import java.util.Set;
 18  
 
 19  
 /**
 20  
  * Maps a key to a collection of values. The values are maintained in a set that gurantees order, adding the same value twice for the same key will have no effect.
 21  
  *
 22  
  * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com>
 23  
  * @version $Id$
 24  
  * @noinstantiate This class is not intended to be instantiated by clients.
 25  
  * @noextend This class is not intended to be subclassed by clients.
 26  
  */
 27  
 public class MultiValueMap<K, V> {
 28  
 
 29  
         private HashMap<K, LinkedHashSet<V>>        map;
 30  
 
 31  5057
         public MultiValueMap() {
 32  5057
                 map = new HashMap<K, LinkedHashSet<V>>();
 33  5057
         }
 34  
 
 35  
         public void put(K k, V v) {
 36  45487
                 LinkedHashSet<V> collection = map.get(k);
 37  45487
                 if (collection == null) {
 38  45485
                         collection = new LinkedHashSet<V>();
 39  45485
                         map.put(k, collection);
 40  
                 }
 41  45487
                 collection.add(v);
 42  45487
         }
 43  
 
 44  
         public Collection<V> getCollection(K k) {
 45  290847
                 LinkedHashSet<V> result = map.get(k);
 46  290847
                 if (result != null)
 47  171523
                         return result;
 48  119324
                 return Collections.emptySet();
 49  
         }
 50  
         
 51  
         public Set<K> keySet() {
 52  4
                 return map.keySet();
 53  
         }
 54  
 
 55  
 }