Class LazyOrderIterable<T,​TComparable>

java.lang.Object
de.renebergelt.quiterables.iterators.LazyOrderIterable<T,​TComparable>
Type Parameters:
T - Type of the elements in this Iterable
All Implemented Interfaces:
Iterable<T>

public class LazyOrderIterable<T,​TComparable> extends Object implements Iterable<T>
AN Iterable which sorts its elements before returning an iterator
Author:
René Bergelt
  • Constructor Details

    • LazyOrderIterable

      public LazyOrderIterable(Iterable<T> _wrapped, ItemFunc<T,​TComparable> valueFunc, Comparator comparator, SortOrder sortOrder)
      Create a new lazy order iterable which wraps the given iterable
      Type Parameters:
      TComparable - Type of the values to compare
      Parameters:
      _wrapped - The wrapped iterable
      valueFunc - Function to retrieve the value to order by
      comparator - Comparator to use for comparing values
      sortOrder - The sort order
    • LazyOrderIterable

      public LazyOrderIterable(Iterable<T> _wrapped, ItemFunc<T,​Comparable> valueFunc, SortOrder sortOrder)
      Creates a LazyOrderIterable which uses the default Comparator
      Parameters:
      _wrapped - The iterable which will be wrapped (and sorted)
      valueFunc - The function to retrieve the values to compare
      sortOrder - The sort order
  • Method Details

    • addSecondaryOrderFunction

      public void addSecondaryOrderFunction(ItemFunc<T,​Comparable> func, SortOrder sortOrder)
      Adds a secondary ordering function which is used to compare elements for which all previous ordering functions return "equal"
      Parameters:
      func - The function to retrieve the values to compare
      sortOrder - The sort order
    • addSecondaryOrderFunction

      public <TComparable> void addSecondaryOrderFunction(ItemFunc<T,​TComparable> func, Comparator<TComparable> comparator, SortOrder sortOrder)
      Add a secondary ordering function which is used to compare elements for which all previous ordering functions return "equal"
      Type Parameters:
      TComparable - Type of the values to compare
      Parameters:
      func - The function to retrieve the values to compare
      comparator - Custom comparator
      sortOrder - The sort order
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>