Class Ord<E>

java.lang.Object
net.hydromatic.morel.util.Ord<E>
Type Parameters:
E - Element type
All Implemented Interfaces:
Map.Entry<Integer,E>

public class Ord<E> extends Object implements Map.Entry<Integer,E>
Pair of an element and an ordinal.
  • Field Details

    • i

      public final int i
    • e

      public final E e
  • Constructor Details

    • Ord

      private Ord(int i, E e)
      Creates an Ord.
  • Method Details

    • of

      public static <E> Ord<E> of(int n, E e)
      Creates an Ord.
    • zip

      public static <E> Iterable<Ord<E>> zip(Iterable<? extends E> iterable)
      Creates an iterable of Ords over an iterable.
    • zip

      public static <E> Iterator<Ord<E>> zip(Iterator<? extends E> iterator)
      Creates an iterator of Ords over an iterator.
    • zip

      public static <E> List<Ord<E>> zip(E[] elements)
      Returns a numbered list based on an array.
    • zip

      public static <E> List<Ord<E>> zip(List<? extends E> elements)
      Returns a numbered list.
    • forEachIndexed

      public static <E> void forEachIndexed(Iterable<E> iterable, ObjIntConsumer<E> consumer)
      Performs the given action for each element of the Iterable.
    • forEach

      public static <E> void forEach(List<E> list, ObjIntConsumer<E> consumer)
      Performs the given action for each element of the List.

      More efficient than forEachIndexed(Iterable, ObjIntConsumer) if the list implements RandomAccess.

    • forEachIndexed

      public static <K, V> void forEachIndexed(Map<K,V> map, Ord.IntObjObjConsumer<K,V> consumer)
      Performs the given action for each entry of a Map.
    • reverse

      public static <E> Iterable<Ord<E>> reverse(E... elements)
      Iterates over an array in reverse order.

      Given the array ["a", "b", "c"], returns (2, "c") then (1, "b") then (0, "a").

    • reverse

      public static <E> Iterable<Ord<E>> reverse(Iterable<? extends E> elements)
      Iterates over a list in reverse order.

      Given the list ["a", "b", "c"], returns (2, "c") then (1, "b") then (0, "a").

    • getKey

      public Integer getKey()
      Specified by:
      getKey in interface Map.Entry<Integer,E>
    • getValue

      public E getValue()
      Specified by:
      getValue in interface Map.Entry<Integer,E>
    • setValue

      public E setValue(E value)
      Specified by:
      setValue in interface Map.Entry<Integer,E>