Class MappingUtil


  • public final class MappingUtil
    extends java.lang.Object
    Useful utilities to do with mappings.
    Author:
    Matthew Wakeling, Andrew Varley
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> java.util.Set<java.util.Map<T,​T>> findCombinations​(java.util.Set<T> firstSet, java.util.Set<T> secondSet, java.util.Comparator<? super T> comparator)
      Produces a Set of possible mappings from items in the firstSet onto items in the secondSet, where the mapping maps from one item to another item that is equal according to the comparator.
      static <T> java.util.Set<java.util.Map<T,​T>> findCombinations​(java.util.Set<T> firstSet, java.util.Set<T> secondSet, java.util.Comparator<? super T> comparator, MappingUtilChecker<T> checker)
      Produces a Set of possible mappings from items in the firstSet onto items in the secondSet, where the mapping maps from one item to another item that is equal according to the comparator.
      static <T> java.util.Set<java.util.Set<java.util.Map<T,​T>>> findMultipleCombinations​(java.util.Set<java.util.Map<T,​T>> combinations)
      Produces a Set of possible combinations of multiple mappings (as produced by findCombinations), where all mappings in a multiple mapping combination map onto distinct objects.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • findCombinations

        public static <T> java.util.Set<java.util.Map<T,​T>> findCombinations​(java.util.Set<T> firstSet,
                                                                                   java.util.Set<T> secondSet,
                                                                                   java.util.Comparator<? super T> comparator)
        Produces a Set of possible mappings from items in the firstSet onto items in the secondSet, where the mapping maps from one item to another item that is equal according to the comparator. For example, if firstSet is {a1, b1, c2}, and secondSet is {d1, e1, f2}, and the comparator returns zero when comparing items with the same number, then the result will be a Set that contains two maps, and these are {a1->d1, b1->e1, c2->f2}, and {a1->e1, b1->d1, c2->f2}. For more examples, see the MappingUtilTest.java file. If firstSet is smaller than secondSet, then there are possible mappings, but if firstSet is bigger than secondSet, then there are no possible mappings.
        Type Parameters:
        T - The element type of the sets
        Parameters:
        firstSet - the set of items to map from
        secondSet - the set of items to map to
        comparator - a comparator for the items in the two sets that returns 0 for the required equivalence operation
        Returns:
        a Set of Maps from items in the firstSet onto items in the secondSet
      • findCombinations

        public static <T> java.util.Set<java.util.Map<T,​T>> findCombinations​(java.util.Set<T> firstSet,
                                                                                   java.util.Set<T> secondSet,
                                                                                   java.util.Comparator<? super T> comparator,
                                                                                   MappingUtilChecker<T> checker)
        Produces a Set of possible mappings from items in the firstSet onto items in the secondSet, where the mapping maps from one item to another item that is equal according to the comparator. For example, if firstSet is {a1, b1, c2}, and secondSet is {d1, e1, f2}, and the comparator returns zero when comparing items with the same number, then the result will be a Set that contains two maps, and these are {a1->d1, b1->e1, c2->f2}, and {a1->e1, b1->d1, c2->f2}. For more examples, see the MappingUtilTest.java file. If firstSet is smaller than secondSet, then there are possible mappings, but if firstSet is bigger than secondSet, then there are no possible mappings.
        Type Parameters:
        T - The element type of the sets
        Parameters:
        firstSet - the set of items to map from
        secondSet - the set of items to map to
        comparator - a comparator for the items in the two sets that returns 0 for the required equivalence operation
        checker - an object that can check a partial mapping for validity
        Returns:
        a Set of Maps from items in the firstSet onto items in the secondSet
      • findMultipleCombinations

        public static <T> java.util.Set<java.util.Set<java.util.Map<T,​T>>> findMultipleCombinations​(java.util.Set<java.util.Map<T,​T>> combinations)
        Produces a Set of possible combinations of multiple mappings (as produced by findCombinations), where all mappings in a multiple mapping combination map onto distinct objects. For example, if combinations contains {{a1->b1}, {a1->c1}}, then the result will be a Set that contains three Sets:
        1. {{a1->b1}}
        2. {{a1->c1}}
        3. {{a1->b1}, {a1->c1}}
        Type Parameters:
        T - The element type
        Parameters:
        combinations - a Set of Maps, each of which is a mapping from one set of items onto another set of items
        Returns:
        a Set of Sets of Maps, where each Set of Maps is a set of mappings that have all items being mapped onto disjoint