Class Linq4j
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final QueryProviderQuery provider that simply executes aQueryableby calling its enumerator method; does not attempt optimization.static final Enumerable<?> -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Enumerable<T>asEnumerable(Iterable<T> iterable) Adapter that converts anIterableinto anEnumerable.static <T> Enumerable<T>asEnumerable(Collection<T> collection) Adapter that converts anCollectioninto anEnumerable.static <T> Enumerable<T>asEnumerable(List<T> list) Adapter that converts anListinto anEnumerable.static <T> Enumerable<T>asEnumerable(T[] ts) Adapter that converts an array into an enumerable.static <TSource,TResult>
Enumerable<TResult>Converts the elements of a given Iterable to the specified type.static <E> Enumerable<E>concat(List<Enumerable<E>> enumerableList) Concatenates two or moreEnumerables to form a composite enumerable that contains the union of their elements.static <T> Enumerable<T>Returns anEnumerablethat has no elements.static <T> Enumerator<T>Returns anEnumeratorthat has no elements.static <V> Enumerator<V>enumerator(Collection<? extends V> values) Adapter that converts a collection into an enumerator.static <T> Iterator<T>enumeratorIterator(Enumerator<T> enumerator) Adapter that converts an enumerator into an iterator.static <T> booleanequals(T t0, T t1) Deprecated.static @Nullable Methodstatic <T> Enumerator<T>iterableEnumerator(Iterable<? extends T> iterable) Adapter that converts an iterable into an enumerator.static <TSource,TResult>
Enumerable<TResult>Returns elements of a givenIterablethat are of the specified type.Returns the cartesian product of an iterable of iterables.static <T> Enumerator<List<T>>product(List<Enumerator<T>> enumerators) Returns an enumerator that is the cartesian product of the given enumerators.static <T> Enumerable<T>singletonEnumerable(T element) Returns anEnumerablethat has one element.static <T> Enumerator<T>singletonEnumerator(T element) Returns anEnumeratorthat has one element.static <T> Enumerator<T>Returns anEnumeratorthat has one null element.static <F,E> Enumerator<E> transform(Enumerator<? extends F> enumerator, Function1<? super F, ? extends E> func) Applies a function to each element of an Enumerator.
-
Field Details
-
DEFAULT_PROVIDER
Query provider that simply executes aQueryableby calling its enumerator method; does not attempt optimization. -
EMPTY_ENUMERABLE
-
-
Method Details
-
getMethod
-
enumeratorIterator
Adapter that converts an enumerator into an iterator.WARNING: The iterator returned by this method does not call
Enumerator.close(), so it is not safe to use with an enumerator that allocates resources.- Type Parameters:
T- Element type- Parameters:
enumerator- Enumerator- Returns:
- Iterator
-
iterableEnumerator
Adapter that converts an iterable into an enumerator.- Type Parameters:
T- Element type- Parameters:
iterable- Iterable- Returns:
- enumerator
-
asEnumerable
Adapter that converts anListinto anEnumerable.- Type Parameters:
T- Element type- Parameters:
list- List- Returns:
- enumerable
-
asEnumerable
Adapter that converts anCollectioninto anEnumerable.It uses more efficient implementations if the iterable happens to be a
List.- Type Parameters:
T- Element type- Parameters:
collection- Collection- Returns:
- enumerable
-
asEnumerable
Adapter that converts anIterableinto anEnumerable.It uses more efficient implementations if the iterable happens to be a
Collectionor aList.- Type Parameters:
T- Element type- Parameters:
iterable- Iterable- Returns:
- enumerable
-
asEnumerable
Adapter that converts an array into an enumerable.- Type Parameters:
T- Element type- Parameters:
ts- Array- Returns:
- enumerable
-
enumerator
Adapter that converts a collection into an enumerator.- Type Parameters:
V- Element type- Parameters:
values- Collection- Returns:
- Enumerator over the collection
-
transform
public static <F,E> Enumerator<E> transform(Enumerator<? extends F> enumerator, Function1<? super F, ? extends E> func) Applies a function to each element of an Enumerator.- Type Parameters:
F- Backing element typeE- Element type- Parameters:
enumerator- Backing enumeratorfunc- Transform function- Returns:
- Enumerator
-
cast
public static <TSource,TResult> Enumerable<TResult> cast(Iterable<TSource> source, Class<TResult> clazz) Converts the elements of a given Iterable to the specified type.This method is implemented by using deferred execution. The immediate return value is an object that stores all the information that is required to perform the action. The query represented by this method is not executed until the object is enumerated either by calling its
RawEnumerable.enumerator()method directly or by usingfor (... in ...).Since standard Java
Collectionobjects implement theIterableinterface, thecastmethod enables the standard query operators to be invoked on collections (includingListandSet) by supplying the necessary type information. For example,ArrayListdoes not implementEnumerable<F>, but you can invokeLinq4j.cast(list, Integer.class)to convert the list of an enumerable that can be queried using the standard query operators.
If an element cannot be cast to type <TResult>, this method will throw a
ClassCastException. To obtain only those elements that can be cast to type TResult, use theofType(java.lang.Iterable<TSource>, java.lang.Class<TResult>)method instead. -
ofType
public static <TSource,TResult> Enumerable<TResult> ofType(Iterable<TSource> source, Class<TResult> clazz) Returns elements of a givenIterablethat are of the specified type.This method is implemented by using deferred execution. The immediate return value is an object that stores all the information that is required to perform the action. The query represented by this method is not executed until the object is enumerated either by calling its
RawEnumerable.enumerator()method directly or by usingfor (... in ...).The
ofTypemethod returns only those elements in source that can be cast to type TResult. To instead receive an exception if an element cannot be cast to type TResult, usecast(Iterable, Class).Since standard Java
Collectionobjects implement theIterableinterface, thecastmethod enables the standard query operators to be invoked on collections (includingListandSet) by supplying the necessary type information. For example,ArrayListdoes not implementEnumerable<F>, but you can invokeLinq4j.ofType(list, Integer.class)to convert the list of an enumerable that can be queried using the standard query operators.
-
singletonEnumerable
Returns anEnumerablethat has one element.- Type Parameters:
T- Element type- Returns:
- Singleton enumerable
-
singletonEnumerator
Returns anEnumeratorthat has one element.- Type Parameters:
T- Element type- Returns:
- Singleton enumerator
-
singletonNullEnumerator
Returns anEnumeratorthat has one null element.- Type Parameters:
T- Element type- Returns:
- Singleton enumerator
-
emptyEnumerable
Returns anEnumerablethat has no elements.- Type Parameters:
T- Element type- Returns:
- Empty enumerable
-
emptyEnumerator
Returns anEnumeratorthat has no elements.- Type Parameters:
T- Element type- Returns:
- Empty enumerator
-
concat
Concatenates two or moreEnumerables to form a composite enumerable that contains the union of their elements.- Type Parameters:
E- Element type- Parameters:
enumerableList- List of enumerable objects- Returns:
- Composite enumerator
-
product
Returns an enumerator that is the cartesian product of the given enumerators.For example, given enumerator A that returns {"a", "b", "c"} and enumerator B that returns {"x", "y"}, product(List(A, B)) will return {List("a", "x"), List("a", "y"), List("b", "x"), List("b", "y"), List("c", "x"), List("c", "y")}.
Notice that the cardinality of the result is the product of the cardinality of the inputs. The enumerators A and B have 3 and 2 elements respectively, and the result has 3 * 2 = 6 elements. This is always the case. In particular, if any of the enumerators is empty, the result is empty.
- Type Parameters:
T- Element type- Parameters:
enumerators- List of enumerators- Returns:
- Enumerator over the cartesian product
-
product
Returns the cartesian product of an iterable of iterables. -
equals
Deprecated.Returns whether the arguments are equal to each other.Equivalent to
Objects.equals(java.lang.Object, java.lang.Object)in JDK 1.7 and above.
-