Class TwoDimensionalCollectionValuedMap<K1,​K2,​V>

  • All Implemented Interfaces:
    Serializable

    public class TwoDimensionalCollectionValuedMap<K1,​K2,​V>
    extends Object
    implements Serializable
    A class which can store mappings from Object keys to Collections of Object values. Important methods are the add(K1, K2, V) and for adding a value to/from the Collection associated with the key, and the get(K1, K2) method for getting the Collection associated with a key. The class is quite general, because on construction, it is possible to pass a MapFactory which will be used to create the underlying map and a CollectionFactory which will be used to create the Collections. Thus this class can be configured to act like a "HashSetValuedMap" or a "ListValuedMap", or even a "HashSetValuedIdentityHashMap". The possibilities are endless!
    Author:
    Teg Grenager (grenager@cs.stanford.edu)
    See Also:
    Serialized Form
    • Constructor Detail

      • TwoDimensionalCollectionValuedMap

        public TwoDimensionalCollectionValuedMap()
        Creates a new empty TwoDimensionalCollectionValuedMap which uses a HashMap as the underlying Map, and HashSets as the Collections in each mapping. Does not treat Collections as immutable.
      • TwoDimensionalCollectionValuedMap

        public TwoDimensionalCollectionValuedMap​(boolean treatCollectionsAsImmutable)
        Creates a new empty TwoDimensionalCollectionValuedMap which uses a HashMap as the underlying Map, and HashSets as the Collections in each mapping.
        Parameters:
        treatCollectionsAsImmutable - whether or not to treat collections as immutable
      • TwoDimensionalCollectionValuedMap

        public TwoDimensionalCollectionValuedMap​(CollectionFactory<V> cf)
        Creates a new empty TwoDimensionalCollectionValuedMap which uses a HashMap as the underlying Map. Does not treat Collections as immutable.
        Parameters:
        cf - a CollectionFactory which will be used to generate the Collections in each mapping
      • TwoDimensionalCollectionValuedMap

        public TwoDimensionalCollectionValuedMap​(MapFactory<K2,​Collection<V>> mf,
                                                 CollectionFactory<V> cf)
        Creates a new empty TwoDimensionalCollectionValuedMap. Does not treat Collections as immutable.
        Parameters:
        mf - a MapFactory which will be used to generate the underlying Map
        cf - a CollectionFactory which will be used to generate the Collections in each mapping
      • TwoDimensionalCollectionValuedMap

        public TwoDimensionalCollectionValuedMap​(MapFactory<K2,​Collection<V>> mf,
                                                 CollectionFactory<V> cf,
                                                 boolean treatCollectionsAsImmutable)
        Creates a new empty TwoDimensionalCollectionValuedMap.
        Parameters:
        mf - a MapFactory which will be used to generate the underlying Map
        cf - a CollectionFactory which will be used to generate the Collections in each mapping
        treatCollectionsAsImmutable - if true, forces this Map to create new a Collection everytime a new value is added to or deleted from the Collection a mapping.
    • Method Detail

      • getCollectionValuedMap

        public CollectionValuedMap<K2,​V> getCollectionValuedMap​(K1 key1)
        Returns:
        the Collection mapped to by key, never null, but may be empty.
      • add

        public void add​(K1 key1,
                        K2 key2,
                        V value)
        Adds the value to the Collection mapped to by the key.
      • add

        public void add​(K1 key1,
                        K2 key2,
                        Collection<V> value)
        Adds a collection of values to the Collection mapped to by the key.
      • addKey

        public void addKey​(K1 key1)
        yes, this is a weird method, but i need it.
      • clear

        public void clear()
      • keySet

        public Set<K1> keySet()
        Returns:
        a Set view of the keys in this Map.
      • containsKey

        public boolean containsKey​(K1 key)
      • retainAll

        public void retainAll​(Set<K1> keys)
      • firstKeySet

        public Set<K1> firstKeySet()
      • secondKeySet

        public Set<K2> secondKeySet()