Class Index<T>

  • Type Parameters:
    T - The indexed type

    public final class Index<T>
    extends Object
    An indexing class for associating items in a list with their index in the list
    • Constructor Detail

      • Index

        public Index​(T value,
                     int index)
        Create a new indexed value
        Parameters:
        value - The value
        index - The index
    • Method Detail

      • with

        public static <In> Iterator<Index<In>> with​(Iterator<? extends In> iterator)
        Implements an equivalent to Javascript’s eachWithIndex.

        This is a shortcut to IndexingIterator. If the input is null, a constant empty iterator is returned.

        Type Parameters:
        In - The type of the values in the list
        Parameters:
        iterator - The input list to iterate over
        Returns:
        An indexed iterator over the given child iterator
      • with

        public static <In> Iterable<Index<In>> with​(List<? extends In> iterable)
        Implements an equivalent to Javascript’s eachWithIndex.

        If the input is null or empty, a constant empty Iterable is returned.

        The output of this method is not itself a List.

        Type Parameters:
        In - The type of the values in the list
        Parameters:
        iterable - The input list to iterate over
        Returns:
        An indexed iterator over the given list
      • getIndex

        public int getIndex()
        Gets the integer index value
        Returns:
        The integer index value
      • getValue

        public T getValue()
        The value at that position in the list
        Returns:
        The value at the list position