Class Linqy


  • public final class Linqy
    extends java.lang.Object
    A couple of (functional) sequence processing constructs.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Linqy()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> boolean all​(java.lang.Iterable<T> sequence, Predicate<? super T> predicate)
      Determines whether a given predicate holds true for all elements.
      static <T> boolean any​(java.lang.Iterable<T> sequence, Predicate<? super T> predicate)
      Determines whether a given predicate holds true for at least one element.
      static <E> java.util.List<E> asList​(java.lang.Iterable<E> i)
      Turns the iterable into a list.
      static <E> java.lang.Iterable<E> cast​(java.lang.Iterable i)
      Turns an iterable into its type-safe cousin.
      static int count​(java.lang.Iterable seq)
      Count the number of elements in a sequence.
      static <T> java.lang.Iterable<T> filter​(java.lang.Iterable<T> sequence, Predicate<? super T> filter)
      Exclude all elements from an iterable that don't match a given predicate.
      static <F,​T>
      java.lang.Iterable<T>
      map​(java.lang.Iterable<F> from, Mapper<? super F,​T> mapper)
      Create a new iterable by applying a mapper function to each element of a given sequence.
      static <E> java.lang.Iterable<E> singleton​(E single)
      An iterable containing a single element.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Linqy

        private Linqy()
    • Method Detail

      • asList

        public static <E> java.util.List<E> asList​(java.lang.Iterable<E> i)
        Turns the iterable into a list.
        Type Parameters:
        E - element type
        Parameters:
        i - the iterable
        Returns:
        a list containing all elements of the Iterable passed in
      • cast

        public static <E> java.lang.Iterable<E> cast​(java.lang.Iterable i)
        Turns an iterable into its type-safe cousin.
        Type Parameters:
        E - target element type
        Parameters:
        i - the iterable
        Returns:
        a type-safe iterable containing all elements of the Iterable passed in
      • singleton

        public static <E> java.lang.Iterable<E> singleton​(E single)
        An iterable containing a single element.
        Type Parameters:
        E - element type
        Parameters:
        single - the element of the iterable to return
        Returns:
        an Iterable returning single once and only once
      • map

        public static <F,​T> java.lang.Iterable<T> map​(java.lang.Iterable<F> from,
                                                            Mapper<? super F,​T> mapper)
        Create a new iterable by applying a mapper function to each element of a given sequence.
        Type Parameters:
        F - source element type
        T - target element type
        Parameters:
        from - the iterable to transform
        mapper - the function to apply to each element of from
        Returns:
        an iterable where each element is the result of applying the function to an element of the original iterable
      • filter

        public static <T> java.lang.Iterable<T> filter​(java.lang.Iterable<T> sequence,
                                                       Predicate<? super T> filter)
        Exclude all elements from an iterable that don't match a given predicate.
        Type Parameters:
        T - element type
        Parameters:
        sequence - the iterable to filter
        filter - the predicate to apply
        Returns:
        an iterable containing all elements of the original sequence that match the predicate
      • count

        public static int count​(java.lang.Iterable seq)
        Count the number of elements in a sequence.
        Parameters:
        seq - the sequence to count
        Returns:
        the number of elements in the sequence
      • any

        public static <T> boolean any​(java.lang.Iterable<T> sequence,
                                      Predicate<? super T> predicate)
        Determines whether a given predicate holds true for at least one element.

        Returns false for an empty sequence.

        Type Parameters:
        T - element type
        Parameters:
        sequence - the sequence to examine
        predicate - the predicate to test
        Returns:
        true if any element of the sequence matches the predicate
      • all

        public static <T> boolean all​(java.lang.Iterable<T> sequence,
                                      Predicate<? super T> predicate)
        Determines whether a given predicate holds true for all elements.

        Returns true for an empty sequence.

        Type Parameters:
        T - element type
        Parameters:
        sequence - the sequence to examine
        predicate - the predicate to test
        Returns:
        true if all elements of the sequence match the predicate