Class Iterables

java.lang.Object
de.bsommerfeld.pathetic.engine.util.Iterables

public final class Iterables extends Object
Utility class that provides methods for working with Iterables. This is a replacement for Google's Iterables API.
  • Method Details

    • size

      public static int size(Iterable<?> iterable)
      Returns the number of elements in the specified iterable.
      Parameters:
      iterable - the iterable to count elements in
      Returns:
      the number of elements in the iterable
    • getLast

      public static <T> T getLast(Iterable<T> iterable)
      Returns the last element of the specified iterable.
      Type Parameters:
      T - the type of elements in the iterable
      Parameters:
      iterable - the iterable to get the last element from
      Returns:
      the last element of the iterable
      Throws:
      NoSuchElementException - if the iterable is empty
    • limit

      public static <T> Iterable<T> limit(Iterable<T> iterable, int limitSize)
      Returns an iterable that contains the first limitSize elements of the specified iterable.
      Type Parameters:
      T - the type of elements in the iterable
      Parameters:
      iterable - the iterable to limit
      limitSize - the maximum number of elements to include
      Returns:
      an iterable containing at most limitSize elements from the input iterable
    • concat

      public static <T> Iterable<T> concat(Iterable<? extends T> a, Iterable<? extends T> b)
      Returns an iterable that concatenates two iterables.
      Type Parameters:
      T - the type of elements in the iterables
      Parameters:
      a - the first iterable
      b - the second iterable
      Returns:
      an iterable containing all elements from both input iterables