Class MapTools<E,​F>

  • Type Parameters:
    E - Domain class of the maps
    F - Range class of the maps

    public class MapTools<E,​F>
    extends Object
    This class provides some utility functions for maps.
    Author:
    Matthias Thimm
    • Constructor Detail

      • MapTools

        public MapTools()
    • Method Detail

      • allMaps

        public Set<Map<E,​F>> allMaps​(Map<Set<E>,​Set<F>> relations)
        Computes the complete set of maps from E to F such that the following condition holds. For every map "m" in the result the set m.keySet() is equal to the union of all sets S with S in relations.keySet() and each element "e" in m.keySet() is mapped to an element "f" such that "f" in relations.get(S) with "e" in S. For example the map:
        {a,b} => {1,2}
        {c,d} => {3}
        {f} => {4,5}
        yields the set of maps:
        a=>1, b=>1, c=>3, d=>3, f=>4
        a=>1, b=>1, c=>3, d=>3, f=>5
        a=>1, b=>2, c=>3, d=>3, f=>4
        a=>1, b=>2, c=>3, d=>3, f=>5
        a=>2, b=>1, c=>3, d=>3, f=>4
        a=>2, b=>1, c=>3, d=>3, f=>5
        a=>2, b=>2, c=>3, d=>3, f=>4
        a=>2, b=>2, c=>3, d=>3, f=>5
        Parameters:
        relations - a map from sets of E to sets of F.
        Returns:
        a set of maps from E to F.
      • allMapsSingleSource

        public Set<Map<E,​F>> allMapsSingleSource​(Map<E,​Set<F>> relations)
        Computes the complete set of maps from E to F such that the following condition holds. For every map "m" in the result the set m.keySet() is equal to relations.keySet() and each element "e" in m.keySet() is mapped to an element "f" such that "f" in relations.get(S) with "e" in S. For example the map:
        a => {1,2}
        b => {3}
        c => {4,5}
        yields the set of maps:
        a=>1, b=>3, c=>4
        a=>1, b=>3, c=>5
        a=>2, b=>3, c=>4
        a=>2, b=>3, c=>5
        Parameters:
        relations - a map from sets of E to sets of F.
        Returns:
        a set of maps from E to F.
      • allBijections

        public Set<Map<E,​F>> allBijections​(Collection<E> domain,
                                                 Collection<F> range)
        Computes all bijections from E to F. E and F have to be of the same cardinality.
        Parameters:
        domain - some set.
        range - some set.
        Returns:
        all bijections from E to F.
      • allMaps

        public Set<Map<E,​F>> allMaps​(Set<? extends E> domain,
                                           Set<? extends F> range)
        This methods computes all maps from domain to range.
        Parameters:
        domain - a set of elements.
        range - a set of elements
        Returns:
        a set of maps, where every map maps any element of domain to an element of range.
      • combine

        public Map<E,​F> combine​(Set<Map<E,​F>> singleMaps)
                               throws IllegalArgumentException
        Combines all maps in singleMaps to one maps containing every assignment of each map in singleMaps.
        Parameters:
        singleMaps - the set of maps to be combined.
        Returns:
        a single map.
        Throws:
        IllegalArgumentException - if one key is used in more than one map of singleMaps.
      • isInjective

        public static boolean isInjective​(Map<? extends Object,​? extends Object> map)
        Checks whether the given map is injective, i.e. whether no two different keys are assigned the same value.
        Parameters:
        map - a map
        Returns:
        "true" iff the given map is injective.