Class IteratorUtils

java.lang.Object
it.unimi.di.prog2.s19.IteratorUtils

public class IteratorUtils extends Object
Utility methods for iterators.
  • Constructor Details

    • IteratorUtils

      private IteratorUtils()
      .
  • Method Details

    • concatenate

      public static <T> Iterator<T> concatenate(Iterator<? extends T> a, Iterator<? extends T> b)
      Concatenates two iterators.
      Type Parameters:
      T - the type of the elements in the iterators.
      Parameters:
      a - the first iterator.
      b - the second iterator.
      Returns:
      an iterator that first returns all elements of a and then all elements of b.
      Throws:
      NullPointerException - if a or b is null.
    • emptyIterator

      public static <T> Iterator<T> emptyIterator()
      An empty iterator.
      Type Parameters:
      T - the type of the elements in the iterator.
      Returns:
      the iterator.
    • join

      public static <T> String join(Iterator<T> iterator, String separator)
      Joins the elements of an iterator using a separator.
      Type Parameters:
      T - the type of the elements in the iterator.
      Parameters:
      iterator - the iterator.
      separator - the separator.
      Returns:
      the string obtained by concatenating the string representation of the elements of the iterator, separated by the separator.
      Throws:
      NullPointerException - if iterator or separator is null.