org.omnaest.utils.structure.map.dualmap
Class LinkedHashDualMap<K,V>

java.lang.Object
  extended by org.omnaest.utils.structure.map.dualmap.LinkedHashDualMap<K,V>
Type Parameters:
K -
V -
All Implemented Interfaces:
Serializable, Map<K,V>, DualMap<K,V>

public class LinkedHashDualMap<K,V>
extends Object
implements DualMap<K,V>

DualMap implementation which makes use of two LinkedHashMap instances to get an index on keys and values.

Author:
Omnaest
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
protected  Map<K,V> keyToValueMap
           
protected static long serialVersionUID
           
protected  Map<V,K> valueToKeyMap
           
 
Constructor Summary
  LinkedHashDualMap()
           
protected LinkedHashDualMap(Map<K,V> keyToValueMap, Map<V,K> valueToKeyMap)
           
 
Method Summary
 void clear()
           
 boolean contains(Object element)
          Returns true, if the element is contained as key or value
 boolean containsKey(Object key)
           
 boolean containsValue(Object key)
           
 Set<Map.Entry<K,V>> entrySet()
           
 V get(Object key)
           
 DualMap<V,K> invert()
          Returns the same DualMap instance but with inverted key and value
 boolean isEmpty()
           
 Set<K> keySet()
           
 V put(K key, V value)
           
 DualMap<K,V> putAll(DualMap<? extends K,? extends V> dualMap)
           
 void putAll(Map<? extends K,? extends V> map)
           
 V remove(Object key)
           
 int size()
           
 String toString()
           
 Collection<V> values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

serialVersionUID

protected static final long serialVersionUID
See Also:
Constant Field Values

keyToValueMap

protected final Map<K,V> keyToValueMap

valueToKeyMap

protected final Map<V,K> valueToKeyMap
Constructor Detail

LinkedHashDualMap

public LinkedHashDualMap()
See Also:
LinkedHashDualMap

LinkedHashDualMap

protected LinkedHashDualMap(Map<K,V> keyToValueMap,
                            Map<V,K> valueToKeyMap)
Parameters:
keyToValueMap -
valueToKeyMap -
See Also:
LinkedHashDualMap
Method Detail

clear

public void clear()
Specified by:
clear in interface Map<K,V>

contains

public boolean contains(Object element)
Description copied from interface: DualMap
Returns true, if the element is contained as key or value

Specified by:
contains in interface DualMap<K,V>
Returns:

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map<K,V>

containsValue

public boolean containsValue(Object key)
Specified by:
containsValue in interface Map<K,V>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map<K,V>

put

public V put(K key,
             V value)
Specified by:
put in interface Map<K,V>

size

public int size()
Specified by:
size in interface Map<K,V>

putAll

public DualMap<K,V> putAll(DualMap<? extends K,? extends V> dualMap)
Specified by:
putAll in interface DualMap<K,V>
Returns:
this
See Also:
Map.put(Object, Object), Map.putAll(Map), #putAllSecondElementToFirstElement(Map)

putAll

public void putAll(Map<? extends K,? extends V> map)
Specified by:
putAll in interface Map<K,V>

invert

public DualMap<V,K> invert()
Description copied from interface: DualMap
Returns the same DualMap instance but with inverted key and value

Specified by:
invert in interface DualMap<K,V>
Returns:
DualMap

toString

public String toString()
Overrides:
toString in class Object

get

public V get(Object key)
Specified by:
get in interface Map<K,V>

remove

public V remove(Object key)
Specified by:
remove in interface Map<K,V>

keySet

public Set<K> keySet()
Specified by:
keySet in interface Map<K,V>

values

public Collection<V> values()
Specified by:
values in interface Map<K,V>

entrySet

public Set<Map.Entry<K,V>> entrySet()
Specified by:
entrySet in interface Map<K,V>


Copyright © 2013. All Rights Reserved.