Class TwoLevelNavigator

  • All Implemented Interfaces:
    TwoDimensional

    public class TwoLevelNavigator
    extends java.lang.Object
    implements TwoDimensional
    Default implementation of TwoDimensional that makes it trivial to calculate a position within a two dimensional object.
    • Constructor Detail

      • TwoLevelNavigator

        public TwoLevelNavigator​(java.util.function.IntSupplier elemCount,
                                 java.util.function.IntUnaryOperator elemLength)
        Creates a navigator that can be used to find a TwoDimensional.Position within a two dimensional object.
        Parameters:
        elemCount - a supplier that returns the number of "inner lists" within an "outer list" (see TwoDimensional for clarification). For example, List::size
        elemLength - a function that, given the index of an "inner list," returns either the size of that "inner list" of the length of that inner object.
    • Method Detail

      • position

        public TwoDimensional.Position position​(int major,
                                                int minor)
        Description copied from interface: TwoDimensional
        Creates a two dimensional position in some entity (e.g. area, list of lists, list of some object with length) where the major value is the index within the outer list) and the minor value is either the index within the inner list or some amount of length in a list of objects that have length.
        Specified by:
        position in interface TwoDimensional