org.openstreetmap.josm.tools
Class MultiMap<A,B>

java.lang.Object
  extended by org.openstreetmap.josm.tools.MultiMap<A,B>

public class MultiMap<A,B>
extends java.lang.Object

MultiMap - maps keys to multiple values Corresponds to Google guava LinkedHashMultimap and Apache Collections MultiValueMap but it is an independent (simple) implementation.


Field Summary
private  java.util.Map<A,java.util.LinkedHashSet<B>> map
           
 
Constructor Summary
MultiMap()
           
MultiMap(int capacity)
           
 
Method Summary
 void clear()
           
 boolean contains(A key, B value)
          Returns true if the multimap contains a value for a key.
 boolean containsKey(A key)
           
 java.util.Set<java.util.Map.Entry<A,java.util.LinkedHashSet<B>>> entrySet()
           
 java.util.Set<B> get(A key)
          Returns the Set associated with the given key.
 java.util.LinkedHashSet<B> getValues(A key)
          Like get, but returns an empty Set if nothing has been mapped to the key.
 boolean isEmpty()
           
 java.util.Set<A> keySet()
          Get the keySet.
 void put(A key, B value)
          Map a key to a value.
 void putAll(A key, java.util.Collection<B> values)
          Map the key to all the given values.
 void putVoid(A key)
          Put a key that maps to nothing.
 java.util.LinkedHashSet<B> remove(A key)
          Removes all mappings for a certain key.
 boolean remove(A key, B value)
          Removes a cerain key=value mapping.
 int size()
          Returns the number of keys.
 java.lang.String toString()
           
 java.util.Collection<java.util.LinkedHashSet<B>> values()
          Returns a collection of all value sets.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

map

private final java.util.Map<A,java.util.LinkedHashSet<B>> map
Constructor Detail

MultiMap

public MultiMap()

MultiMap

public MultiMap(int capacity)
Method Detail

put

public void put(A key,
                B value)
Map a key to a value. Can be called multiple times with the same key, but different value.


putVoid

public void putVoid(A key)
Put a key that maps to nothing. (Only if it is not already in the map) Afterwards containsKey(key) will return true and get(key) will return an empty Set instead of null.


putAll

public void putAll(A key,
                   java.util.Collection<B> values)
Map the key to all the given values. Adds to the mappings that are already there.


keySet

public java.util.Set<A> keySet()
Get the keySet.


get

public java.util.Set<B> get(A key)
Returns the Set associated with the given key. Result is null if nothing has been mapped to this key. Modifications of the returned list changes the underling map, but you should better not do that.


getValues

public java.util.LinkedHashSet<B> getValues(A key)
Like get, but returns an empty Set if nothing has been mapped to the key.


isEmpty

public boolean isEmpty()

containsKey

public boolean containsKey(A key)

contains

public boolean contains(A key,
                        B value)
Returns true if the multimap contains a value for a key.

Parameters:
key - The key
value - The value
Returns:
true if the key contains the value

clear

public void clear()

entrySet

public java.util.Set<java.util.Map.Entry<A,java.util.LinkedHashSet<B>>> entrySet()

size

public int size()
Returns the number of keys.


values

public java.util.Collection<java.util.LinkedHashSet<B>> values()
Returns a collection of all value sets.


remove

public boolean remove(A key,
                      B value)
Removes a cerain key=value mapping.

Returns:
true, if something was removed

remove

public java.util.LinkedHashSet<B> remove(A key)
Removes all mappings for a certain key.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


JOSM