org.jjoost.collections.bimaps
Class BiMapManyToMany<K,V>

java.lang.Object
  extended by org.jjoost.collections.bimaps.AbstractBiMap<K,V,MultiMap<K,V>,MultiMap<V,K>>
      extended by org.jjoost.collections.bimaps.BiMapManyToMany<K,V>
All Implemented Interfaces:
java.io.Serializable, AnyMap<K,V>, AnyReadMap<K,V>, MultiMap<K,V>, Function<K,java.lang.Iterable<V>>

public class BiMapManyToMany<K,V>
extends AbstractBiMap<K,V,MultiMap<K,V>,MultiMap<V,K>>
implements MultiMap<K,V>

See Also:
Serialized Form

Constructor Summary
BiMapManyToMany(MultiMap<K,V> forwards, MultiMap<V,K> back)
           
 
Method Summary
 java.lang.Iterable<V> apply(K key)
          Returns the result of applying the function to the parameter
 MultiMap<K,V> copy()
          Returns a copy of the map.
 Set<java.util.Map.Entry<K,V>> entries()
          Returns a set representing all the key->value pairs in this map.
 MultiMap<V,K> inverse()
          Returns a map representing the inverse function of this map.
 MultiSet<K> keys()
          Returns a set representing all the keys in the domain of this map.
 Set<V> values(K key)
          Returns a set representing the values associated with the provided key in this map.
 
Methods inherited from class org.jjoost.collections.bimaps.AbstractBiMap
add, clear, clearAndReturn, contains, contains, count, count, entries, first, isEmpty, list, permitsDuplicateKeys, put, putIfAbsent, remove, remove, removeAndReturn, removeAndReturn, removeAndReturnFirst, shrink, totalCount, uniqueKeyCount, values
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jjoost.collections.MultiMap
put, putIfAbsent
 
Methods inherited from interface org.jjoost.collections.AnyMap
add, clear, clearAndReturn, remove, remove, removeAndReturn, removeAndReturn, removeAndReturnFirst, shrink, values
 
Methods inherited from interface org.jjoost.collections.AnyReadMap
contains, contains, count, count, entries, first, isEmpty, list, permitsDuplicateKeys, totalCount, uniqueKeyCount
 

Constructor Detail

BiMapManyToMany

public BiMapManyToMany(MultiMap<K,V> forwards,
                       MultiMap<V,K> back)
Method Detail

copy

public MultiMap<K,V> copy()
Description copied from interface: AnyMap
Returns a copy of the map. Note that this method may not necessarily return an object of the same class as the one it is called upon, but will return one indistinguishable from it with respect to all method calls.

Specified by:
copy in interface AnyMap<K,V>
Specified by:
copy in interface MultiMap<K,V>
Returns:
the any map< k, v>

inverse

public MultiMap<V,K> inverse()
Description copied from interface: AnyMap
Returns a map representing the inverse function of this map. This operation will typically be expensive unless the map is a BiMap in which case the action is trivial. The method may not return a map of the same type as the one it is called on (although typically this will be the case, and should happen wherever possible).

Specified by:
inverse in interface AnyMap<K,V>
Overrides:
inverse in class AbstractBiMap<K,V,MultiMap<K,V>,MultiMap<V,K>>
Returns:
the inverse map/function of the one called upon

entries

public Set<java.util.Map.Entry<K,V>> entries()
Description copied from interface: AnyReadMap
Returns a set representing all the key->value pairs in this map. In a ListMap this will be a MultiSet. This set should always reflect changes to the map, and changes to the set should be reflected in the map also. Otherwise, this set should behave exactly as a regular set does.

Specified by:
entries in interface AnyMap<K,V>
Specified by:
entries in interface AnyReadMap<K,V>
Specified by:
entries in interface MultiMap<K,V>
Returns:
the entry set< k>

keys

public MultiSet<K> keys()
Description copied from interface: AnyReadMap
Returns a set representing all the keys in the domain of this map. In a MultiMap or ListMap this will be a MultiSet. This set should always reflect changes to the map, and changes to the set should be reflected in the map also. Otherwise, this set should behave exactly as a regular set does. The key equality used by this map can be obtained from this set.

Depending on the implementation of map, this key set may contain every occurrence of equal keys provided to the map, or may contain a subset thereof with repetitions to bring the number of occurrences in line with the number provided.

Note that the put() methods on this set will always fail, because no value can be provided to update the map with.

Specified by:
keys in interface AnyMap<K,V>
Specified by:
keys in interface AnyReadMap<K,V>
Specified by:
keys in interface MultiMap<K,V>
Returns:
the key set< k>

apply

public java.lang.Iterable<V> apply(K key)
Description copied from interface: Function
Returns the result of applying the function to the parameter

Specified by:
apply in interface Function<K,java.lang.Iterable<V>>
Parameters:
key - something of type domain
Returns:
the result of the function (something of type range)

values

public Set<V> values(K key)
Description copied from interface: AnyReadMap
Returns a set representing the values associated with the provided key in this map. This set should always reflect changes to the map, and changes to the set should be reflected in the map also. Otherwise, this set should behave exactly as a regular set does.

Note that in a regular (scalar) map the set returned will be a UnitarySet, which contains at most one value. put() operations on such a set will override any existing value regardless of if it is equal to the one already present.

Specified by:
values in interface AnyMap<K,V>
Specified by:
values in interface AnyReadMap<K,V>
Specified by:
values in interface MultiMap<K,V>
Returns:
the set of values mapped to by provided key