Class Query

java.lang.Object
de.renebergelt.quiterables.Query

public class Query extends Object
Main class of the QuIterables library Mimics some of C#'s generic LINQ convenience methods for Java 8 and below
Use anonymous methods for the predicates.
Beginning with Java 8 you may use lambda expression to increase readability Example to retrieve the first element of a string list which ends with ".jpg", if any:

Recommended method for Java 8 and above: Collection<String> lst = ...; String r = Query.list(lst).firstOrDefault((x) -> x.endsWith(".jpg")); if (r != null) { // process the element } else { System.out.println("There is no such element."); } Java 7 and below: Collection<String> lst = ...; String r = Query.list(lst).firstOrDefault(new Predicate<String>() { @Override public boolean evaluate(String argument) { return argument.endsWith(".jpg"); }; if (r != null) { // process the element } else { System.out.println("There is no such element."); } Chaining of methods Collection<String> lst = ...; Collection<String> resultCollection = Query.list(lst) .where(x -> x.StartsWith(".jpg")) .select(x -> x.substring(0, 3)) .distinct();
Author:
René Bergelt
  • Method Summary

    Modifier and Type
    Method
    Description
    array​(boolean[] array)
    Return a Queriable which wraps the given primitive-type boolean-array
    static Queriable<Byte>
    array​(byte[] array)
    Return a Queriable which wraps the given primitive-type byte-array
    array​(char[] array)
    Return a Queriable which wraps the given primitive-type char-array
    array​(double[] array)
    Return a Queriable which wraps the given primitive-type double-array
    array​(float[] array)
    Return a Queriable which wraps the given primitive-type float-array
    array​(int[] array)
    Return a Queriable which wraps the given primitive-type int-array
    static Queriable<Long>
    array​(long[] array)
    Return a Queriable which wraps the given primitive-type long-array
    array​(short[] array)
    Return a Queriable which wraps the given primitive-type short-array
    static <T> Queriable<T>
    array​(T[] array)
    Return a queriable object for the given array
    static <T> Queriable<T>
    iterable​(Iterable<T> lst)
    Return a queriable object for the given iterable
    static <T> Queriable<T>
    list​(List<T> lst)
    Return a queriable object for the given list

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • iterable

      public static <T> Queriable<T> iterable(Iterable<T> lst)
      Return a queriable object for the given iterable
      Type Parameters:
      T - Type of elements
      Parameters:
      lst - iterable to query
      Returns:
      Queriable object
    • list

      public static <T> Queriable<T> list(List<T> lst)
      Return a queriable object for the given list
      Type Parameters:
      T - Type of elements
      Parameters:
      lst - list to query
      Returns:
      Queriable object
    • array

      public static <T> Queriable<T> array(T[] array)
      Return a queriable object for the given array
      Type Parameters:
      T - Type of elements
      Parameters:
      array - array to query
      Returns:
      Queriable object
    • array

      public static Queriable<Integer> array(int[] array)
      Return a Queriable which wraps the given primitive-type int-array
      Parameters:
      array - array to query
      Returns:
      Queriable object
    • array

      public static Queriable<Short> array(short[] array)
      Return a Queriable which wraps the given primitive-type short-array
      Parameters:
      array - array to query
      Returns:
      Queriable object
    • array

      public static Queriable<Long> array(long[] array)
      Return a Queriable which wraps the given primitive-type long-array
      Parameters:
      array - array to query
      Returns:
      Queriable object
    • array

      public static Queriable<Float> array(float[] array)
      Return a Queriable which wraps the given primitive-type float-array
      Parameters:
      array - array to query
      Returns:
      Queriable object
    • array

      public static Queriable<Double> array(double[] array)
      Return a Queriable which wraps the given primitive-type double-array
      Parameters:
      array - array to query
      Returns:
      Queriable object
    • array

      public static Queriable<Byte> array(byte[] array)
      Return a Queriable which wraps the given primitive-type byte-array
      Parameters:
      array - array to query
      Returns:
      Queriable object
    • array

      public static Queriable<Boolean> array(boolean[] array)
      Return a Queriable which wraps the given primitive-type boolean-array
      Parameters:
      array - array to query
      Returns:
      Queriable object
    • array

      public static Queriable<Character> array(char[] array)
      Return a Queriable which wraps the given primitive-type char-array
      Parameters:
      array - array to query
      Returns:
      Queriable object