Package org.xmlunit.util
Class Linqy
java.lang.Object
org.xmlunit.util.Linqy
A couple of (functional) sequence processing constructs.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> boolean
Determines whether a given predicate holds true for all elements.static <T> boolean
Determines whether a given predicate holds true for at least one element.static <E> List<E>
Turns the iterable into a list.static <E> Iterable<E>
Turns an iterable into its type-safe cousin.static int
Count the number of elements in a sequence.static <T> Iterable<T>
Exclude all elements from an iterable that don't match a given predicate.static <F,
T> Iterable<T> Create a new iterable by applying a mapper function to each element of a given sequence.static <E> Iterable<E>
singleton
(E single) An iterable containing a single element.
-
Method Details
-
asList
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
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
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
Create a new iterable by applying a mapper function to each element of a given sequence.- Type Parameters:
F
- source element typeT
- target element type- Parameters:
from
- the iterable to transformmapper
- the function to apply to each element offrom
- Returns:
- an iterable where each element is the result of applying the function to an element of the original iterable
-
filter
Exclude all elements from an iterable that don't match a given predicate.- Type Parameters:
T
- element type- Parameters:
sequence
- the iterable to filterfilter
- the predicate to apply- Returns:
- an iterable containing all elements of the original sequence that match the predicate
-
count
Count the number of elements in a sequence.- Parameters:
seq
- the sequence to count- Returns:
- the number of elements in the sequence
-
any
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 examinepredicate
- the predicate to test- Returns:
- true if any element of the sequence matches the predicate
-
all
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 examinepredicate
- the predicate to test- Returns:
- true if all elements of the sequence match the predicate
-