Class Positions


  • public final class Positions
    extends java.lang.Object
    Contains utility methods for position objects.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Positions.DimensionStripper
      A functional object to transform positions to other positions with the dimensions stripped as given in the constructor.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean areDimensionsConsistent​(java.util.Set<java.lang.Class<?>> dimensions, java.util.Set<java.lang.Class<?>> positionCoordinatesToCheck)  
      static boolean areDimensionsConsistentWithCoordinates​(java.util.Set<java.lang.Class<?>> dimensions, Position position)
      Searches if given position coordinates match acceptable dimensions.
      static void assertConsistentDimensions​(Position position, java.util.Set<java.lang.Class<?>> dimensions)
      Checks if the given position is conform with the given coordinate and throws an exception, if not.
      static java.lang.Iterable<Position> cartesianEnumProduct​(java.lang.Class<?>... enumClasses)
      Returns all positions which can be built from the values of the passed in classes that are assumed to be enum classes.
      static java.lang.Iterable<Position> cartesianEnumProduct​(java.util.Set<java.lang.Class<?>> classes)
      Returns all positions which can be built from the values of the passed in classes that are assumed to be enum classes.
      static java.lang.Iterable<Position> cartesianProduct​(java.lang.Class<? extends java.lang.Enum<?>>... enumClasses)
      Returns all positions which can be built from all combinations of the values of the given enum classes.
      static java.util.Set<Position> cartesianProduct​(java.lang.Iterable<java.util.Set<?>> coordinateSets)
      Returns all positions which can be built from all combinations of all the coordinates.
      static java.lang.Iterable<Position> cartesianProduct​(java.util.Set<java.lang.Class<? extends java.lang.Enum<?>>> enumClasses)
      Returns all positions which can be built from all combinations of the values of the given enum classes.
      static com.google.common.collect.ImmutableSetMultimap<Position,​PositionPair> combineAll​(java.util.Set<PositionPair> positionPairs, java.util.Set<java.lang.Class<?>> targetDimensions)
      Combines all position pairs into positions containing the given dimensions and returns a map from the combined positions to the original position pairs.
      static Position combineDimensions​(PositionPair pair, java.util.Set<java.lang.Class<?>> targetDimensions)
      Combines the both positions of the pair in such a way, that for each coordinate of the types given in the given set of dimensions have to be either present in both positions of the pair, and then have to be the same or be present in only one of the both positions
      static Position combineDimensions​(Position left, Position right, java.util.Set<java.lang.Class<?>> targetDimensions)
      Combines the both positions in such a way, that for each coordinate of the types given in the given set of dimensions have to be either present in both positions of the pair, and then have to be the same or be present in only one of the both positions
      static <T> java.util.Set<T> coordinatesOfType​(java.util.Set<Position> positions, java.lang.Class<T> ofClass)
      Extracts the provided class of the coordinate from the set of the positions.
      static Position difference​(Position left, Position right)
      Returns a position which contains the coordinates which are contained in the left position but not in the right position.
      static java.lang.Iterable<Position> from​(java.lang.Class<? extends java.lang.Enum<?>> enumClass)
      Returns one position for each value of the given enum.
      static <T> java.util.Set<Position> from​(java.util.Collection<T> coordinates)  
      static <T> java.util.Set<Position> from​(T... coordinates)  
      static com.google.common.collect.Multimap<Position,​Position> mapByStripping​(java.lang.Iterable<Position> positions, java.util.Set<java.lang.Class<?>> dimensionsToStrip)  
      static <T> boolean oneIsNull​(T left, T right)  
      static Positions.DimensionStripper strip​(java.lang.Class<?> dimensionsToStrip)
      Convenience delegation method to stripping(Class), for a bit more fluent syntax.
      static Positions.DimensionStripper stripping​(java.lang.Class<?> dimensionsToStrip)
      Factory method for a dimension stripper with one dimension to strip only
      static Positions.DimensionStripper stripping​(java.util.Set<? extends java.lang.Class<?>> dimensionsToStrip)
      Factory method for a dimension stripper.
      static Position union​(Position left, Position right)
      Constructs a position, whose coordinates are the union of the coordinates of the two individual positions.
      static java.util.Set<Position> unique​(java.lang.Iterable<Position> positions)
      Copies the given positions to a set, to be sure that each element is contained only once
      • Methods inherited from class java.lang.Object

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

      • union

        public static Position union​(Position left,
                                     Position right)
        Constructs a position, whose coordinates are the union of the coordinates of the two individual positions. This is only correctly defined, if the two given positions do not have any dimensional overlap (i.e. Any coordinate of a certain type (class) is only present in either the left or the right position.)
        Parameters:
        left - the first position to use construct the union position
        right - the second position to construct the union position
        Returns:
        a position, which contains the union of the coordinates of the two input positions.
        Throws:
        java.lang.NullPointerException - if one of the arguments is null
        java.lang.IllegalArgumentException - if the given aguments have an overlap of dimensions and therefor the union of the position is not well defined
      • unique

        public static java.util.Set<Position> unique​(java.lang.Iterable<Position> positions)
        Copies the given positions to a set, to be sure that each element is contained only once
        Parameters:
        positions - the positions, which shall be ensured that they are unique
        Returns:
        a set of unique positions
      • stripping

        public static Positions.DimensionStripper stripping​(java.util.Set<? extends java.lang.Class<?>> dimensionsToStrip)
        Factory method for a dimension stripper.
        Parameters:
        dimensionsToStrip - the dimensions which shall be stripped from the positions passed to the stripper.
        Returns:
        a function object that can strip the given dimensions from positions.
      • stripping

        public static Positions.DimensionStripper stripping​(java.lang.Class<?> dimensionsToStrip)
        Factory method for a dimension stripper with one dimension to strip only
        Parameters:
        dimensionsToStrip - the dimension to strip
        Returns:
        a dimension stripper stripping exactly one dimension
        See Also:
        stripping(Set)
      • strip

        public static Positions.DimensionStripper strip​(java.lang.Class<?> dimensionsToStrip)
        Convenience delegation method to stripping(Class), for a bit more fluent syntax.
        Parameters:
        dimensionsToStrip - the dimension to strip
        Returns:
        a dimension stripper stripping exactly one dimension
        See Also:
        stripping(Class)
      • assertConsistentDimensions

        public static void assertConsistentDimensions​(Position position,
                                                      java.util.Set<java.lang.Class<?>> dimensions)
        Checks if the given position is conform with the given coordinate and throws an exception, if not.
        Parameters:
        position - the position for which to check the consistency
        dimensions - the dimensions for which the conformity has to be verified.
        Throws:
        java.lang.IllegalArgumentException - if the position is not conform
        See Also:
        Position.isConsistentWith(Set)
      • areDimensionsConsistentWithCoordinates

        public static boolean areDimensionsConsistentWithCoordinates​(java.util.Set<java.lang.Class<?>> dimensions,
                                                                     Position position)
        Searches if given position coordinates match acceptable dimensions.
        Parameters:
        dimensions -
        position -
        Returns:
      • areDimensionsConsistent

        public static boolean areDimensionsConsistent​(java.util.Set<java.lang.Class<?>> dimensions,
                                                      java.util.Set<java.lang.Class<?>> positionCoordinatesToCheck)
      • combineDimensions

        public static Position combineDimensions​(PositionPair pair,
                                                 java.util.Set<java.lang.Class<?>> targetDimensions)
        Combines the both positions of the pair in such a way, that for each coordinate of the types given in the given set of dimensions have to be
        • either present in both positions of the pair, and then have to be the same
        • or be present in only one of the both positions
        Parameters:
        pair - the pair, whose dimensions should be united
        targetDimensions - the dimension in which the positions shall be united
        Returns:
        a new position, containing the coordinates of the pair, merged by the above rules
      • combineDimensions

        public static Position combineDimensions​(Position left,
                                                 Position right,
                                                 java.util.Set<java.lang.Class<?>> targetDimensions)
        Combines the both positions in such a way, that for each coordinate of the types given in the given set of dimensions have to be
        • either present in both positions of the pair, and then have to be the same
        • or be present in only one of the both positions
        Parameters:
        left - the first of the two positions, whose dimensions should be united
        right - the second of the two positions whose dimensions should be combined
        targetDimensions - the dimension in which the positions shall be united
        Returns:
        a new position, with the coordinates merged according to the above rules
      • oneIsNull

        public static <T> boolean oneIsNull​(T left,
                                            T right)
      • combineAll

        public static com.google.common.collect.ImmutableSetMultimap<Position,​PositionPair> combineAll​(java.util.Set<PositionPair> positionPairs,
                                                                                                             java.util.Set<java.lang.Class<?>> targetDimensions)
        Combines all position pairs into positions containing the given dimensions and returns a map from the combined positions to the original position pairs.
        Parameters:
        positionPairs - the position pairs to combine the final positions
        targetDimensions - the dimensions in which to combine the positions
        Returns:
        a map from the combined dimensions to the original pairs
      • mapByStripping

        public static com.google.common.collect.Multimap<Position,​Position> mapByStripping​(java.lang.Iterable<Position> positions,
                                                                                                 java.util.Set<java.lang.Class<?>> dimensionsToStrip)
      • coordinatesOfType

        public static <T> java.util.Set<T> coordinatesOfType​(java.util.Set<Position> positions,
                                                             java.lang.Class<T> ofClass)
        Extracts the provided class of the coordinate from the set of the positions.
        Parameters:
        positions -
        ofClass - a class of the coordinate to be extracted
        Returns:
        a set of the extracted coordinates from provided positions
      • cartesianProduct

        @SafeVarargs
        public static java.lang.Iterable<Position> cartesianProduct​(java.lang.Class<? extends java.lang.Enum<?>>... enumClasses)
        Returns all positions which can be built from all combinations of the values of the given enum classes.
        Parameters:
        enumClasses - the enum classes from which to get the values from
        Returns:
        positions containing all possible combinations of enum values
      • from

        public static java.lang.Iterable<Position> from​(java.lang.Class<? extends java.lang.Enum<?>> enumClass)
        Returns one position for each value of the given enum. Functionally, this is equivalent to cartesianProduct(Class...) with only one class given.
        Parameters:
        enumClass - the class of the enum from which to take the values as coordinates
        Returns:
        an iterable of positions, containing the values oif the given enum class as (one-dimensional) positions.
      • cartesianEnumProduct

        public static java.lang.Iterable<Position> cartesianEnumProduct​(java.lang.Class<?>... enumClasses)
        Returns all positions which can be built from the values of the passed in classes that are assumed to be enum classes. This is basically the runtime-checked version of cartesianProduct(Class...)
        Parameters:
        enumClasses - the enum classes from which to get their values
        Returns:
        an iterable containing the positions which are constructed from the values of the enums
        Throws:
        java.lang.IllegalArgumentException - in case not all clases are enums
      • cartesianProduct

        public static java.lang.Iterable<Position> cartesianProduct​(java.util.Set<java.lang.Class<? extends java.lang.Enum<?>>> enumClasses)
        Returns all positions which can be built from all combinations of the values of the given enum classes.
        Parameters:
        enumClasses - the enums whose values will be used to create the positions
        Returns:
        an iterable with positions containing all possible combinations of the enum values
      • cartesianEnumProduct

        public static java.lang.Iterable<Position> cartesianEnumProduct​(java.util.Set<java.lang.Class<?>> classes)
        Returns all positions which can be built from the values of the passed in classes that are assumed to be enum classes. This is basically the runtime-checked version of cartesianProduct(Set)
        Parameters:
        classes - the enum classes from which to get their values
        Returns:
        an iterable containing the positions which are constructed from the values of the enums
        Throws:
        java.lang.IllegalArgumentException - in case not all clases are enums
      • cartesianProduct

        public static java.util.Set<Position> cartesianProduct​(java.lang.Iterable<java.util.Set<?>> coordinateSets)
        Returns all positions which can be built from all combinations of all the coordinates.
        Parameters:
        coordinateSets - the sets of coordinates. Note: The types of the set elements have to be different!
        Returns:
        a set of positions, containing all possible combinations
      • from

        public static <T> java.util.Set<Position> from​(java.util.Collection<T> coordinates)
      • from

        public static <T> java.util.Set<Position> from​(T... coordinates)
      • difference

        public static Position difference​(Position left,
                                          Position right)
        Returns a position which contains the coordinates which are contained in the left position but not in the right position. The right position might also contain coordinates not contained in the left position, which are simply ignored.
        Parameters:
        left - the position from which the coordinates of the right position shall be substracted
        right - the position whose coordinates shall be substracted from the left position
        Returns:
        a position containing all coordinates from the left position, which are not present in the right position