Package de.renebergelt.quiterables
Class Query
java.lang.Object
de.renebergelt.quiterables.Query
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:
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 TypeMethodDescriptionarray(boolean[] array)Return a Queriable which wraps the given primitive-type boolean-arrayarray(byte[] array)Return a Queriable which wraps the given primitive-type byte-arrayarray(char[] array)Return a Queriable which wraps the given primitive-type char-arrayarray(double[] array)Return a Queriable which wraps the given primitive-type double-arrayarray(float[] array)Return a Queriable which wraps the given primitive-type float-arrayarray(int[] array)Return a Queriable which wraps the given primitive-type int-arrayarray(long[] array)Return a Queriable which wraps the given primitive-type long-arrayarray(short[] array)Return a Queriable which wraps the given primitive-type short-arraystatic <T> Queriable<T>array(T[] array)Return a queriable object for the given arraystatic <T> Queriable<T>Return a queriable object for the given iterablestatic <T> Queriable<T>Return a queriable object for the given list
-
Method Details
-
iterable
Return a queriable object for the given iterable- Type Parameters:
T- Type of elements- Parameters:
lst- iterable to query- Returns:
- Queriable object
-
list
Return a queriable object for the given list- Type Parameters:
T- Type of elements- Parameters:
lst- list to query- Returns:
- Queriable object
-
array
Return a queriable object for the given array- Type Parameters:
T- Type of elements- Parameters:
array- array to query- Returns:
- Queriable object
-
array
Return a Queriable which wraps the given primitive-type int-array- Parameters:
array- array to query- Returns:
- Queriable object
-
array
Return a Queriable which wraps the given primitive-type short-array- Parameters:
array- array to query- Returns:
- Queriable object
-
array
Return a Queriable which wraps the given primitive-type long-array- Parameters:
array- array to query- Returns:
- Queriable object
-
array
Return a Queriable which wraps the given primitive-type float-array- Parameters:
array- array to query- Returns:
- Queriable object
-
array
Return a Queriable which wraps the given primitive-type double-array- Parameters:
array- array to query- Returns:
- Queriable object
-
array
Return a Queriable which wraps the given primitive-type byte-array- Parameters:
array- array to query- Returns:
- Queriable object
-
array
Return a Queriable which wraps the given primitive-type boolean-array- Parameters:
array- array to query- Returns:
- Queriable object
-
array
Return a Queriable which wraps the given primitive-type char-array- Parameters:
array- array to query- Returns:
- Queriable object
-