Class IterableSearcher

java.lang.Object
ch.nolix.base.commontype.iterablesearcher.IterableSearcher
All Implemented Interfaces:
IIterableCountSearcher, IIterableFirstElementSearcher, IIterableSearcher

public final class IterableSearcher extends Object implements IIterableSearcher
Author:
Silvan Wyss
  • Constructor Details

    • IterableSearcher

      public IterableSearcher()
  • Method Details

    • getCount

      public int getCount(Iterable<?> iterable)
      Specified by:
      getCount in interface IIterableCountSearcher
      Parameters:
      iterable - the examined Iterable, is considered to be empty when is null
      Returns:
      the number of elements of the given iterable
    • getCount

      public <E> int getCount(Iterable<E> iterable, Predicate<E> selector)
      Specified by:
      getCount in interface IIterableCountSearcher
      Type Parameters:
      E - the type of the elements of the given iterable
      Parameters:
      iterable - the examined Iterable, is considered to be empty when is null
      selector - can select elements, ignores null elements, is considered not to select any element when is null
      Returns:
      the number of elements the given selector selects from the given iterable
    • getCountOf

      public int getCountOf(Iterable<?> iterable, Object object)
      Specified by:
      getCountOf in interface IIterableCountSearcher
      Parameters:
      iterable - the examined Iterable, is considered to be empty when is null
      object -
      Returns:
      the number of occurrences of the given object in the given iterable
    • getStoredAtOneBasedIndex

      public <E> E getStoredAtOneBasedIndex(Iterable<E> iterable, int oneBasedIndex)
      Specified by:
      getStoredAtOneBasedIndex in interface IIterableSearcher
      Type Parameters:
      E - the type of the elements of the given iterable
      Parameters:
      iterable - the searched Iterable, is considered to be empty when is null
      oneBasedIndex - the one-based index at which an element is requested
      Returns:
      the element at the given oneBasedIndexed from the given iterable
    • getStoredFirstNonNull

      public <E> E getStoredFirstNonNull(Iterable<E> iterable)
      The time complexity of this method is O(n) if the given iterable contains n elements.
      Specified by:
      getStoredFirstNonNull in interface IIterableFirstElementSearcher
      Type Parameters:
      E - the type of the elements of the given iterable
      Parameters:
      iterable - the searched iterable, is considered to be empty when is null
      Returns:
      the first non-null element of the given iterable
    • getStoredFirst

      public <E> E getStoredFirst(Iterable<E> iterable, Predicate<? super E> selector)
      The time complexity of this method is O(n) if the given iterable contains n elements.
      Specified by:
      getStoredFirst in interface IIterableFirstElementSearcher
      Type Parameters:
      E - the type of the elements of the given iterable
      Parameters:
      iterable - the searched iterable, is considered to be empty when is null
      selector - can select elements, is considered not to select any element when is null
      Returns:
      the first element the given selector selects of the given Iterable, ignoring null elements
    • getStoredFirstOfType

      public <E, T extends E> T getStoredFirstOfType(Iterable<E> iterable, Class<T> type)
      The time complexity of this method is O(n) if the given iterable contains n elements.
      Specified by:
      getStoredFirstOfType in interface IIterableFirstElementSearcher
      Type Parameters:
      E - the type of the elements of the given iterable
      T - the modeled type of the given type
      Parameters:
      iterable - the searched iterable, is considered to be empty when is null
      type -
      Returns:
      the first element of the given iterable that is of the given type