public abstract class Linq4j extends Object
| Modifier and Type | Class and Description |
|---|---|
private static class |
Linq4j.CartesianProductListEnumerator<E>
Enumerates over the cartesian product of the given lists, returning
a list for each row.
|
(package private) static class |
Linq4j.CollectionEnumerable<T>
Collection enumerable.
|
(package private) static class |
Linq4j.CompositeEnumerable<E>
Composite enumerable.
|
private static class |
Linq4j.EnumeratorIterator<T>
Iterator that reads from an underlying
Enumerator. |
(package private) static class |
Linq4j.IterableEnumerable<T>
Iterable enumerable.
|
(package private) static class |
Linq4j.IterableEnumerator<T>
Iterable enumerator.
|
(package private) static class |
Linq4j.ListEnumerable<T>
List enumerable.
|
private static class |
Linq4j.ListEnumerator<V>
Enumerator optimized for random-access list.
|
private static class |
Linq4j.SingletonEnumerator<E>
Enumerator that returns one element.
|
private static class |
Linq4j.SingletonNullEnumerator<E>
Enumerator that returns one null element.
|
| Modifier and Type | Field and Description |
|---|---|
static QueryProvider |
DEFAULT_PROVIDER
Query provider that simply executes a
Queryable by calling its
enumerator method; does not attempt optimization. |
private static Object |
DUMMY |
static Enumerable<?> |
EMPTY_ENUMERABLE |
private static Enumerator<Object> |
EMPTY_ENUMERATOR |
| Modifier | Constructor and Description |
|---|---|
private |
Linq4j() |
| Modifier and Type | Method and Description |
|---|---|
static <T> Enumerable<T> |
asEnumerable(Collection<T> collection)
Adapter that converts an
Collection into an Enumerable. |
static <T> Enumerable<T> |
asEnumerable(Iterable<T> iterable)
Adapter that converts an
Iterable into an Enumerable. |
static <T> Enumerable<T> |
asEnumerable(List<T> list)
Adapter that converts an
List into an Enumerable. |
static <T> Enumerable<T> |
asEnumerable(T[] ts)
Adapter that converts an array into an enumerable.
|
static <TSource,TResult> |
cast(Iterable<TSource> source,
Class<TResult> clazz)
Converts the elements of a given Iterable to the specified type.
|
private static <T> void |
closeIterator(Iterator<T> iterator)
Closes an iterator, if it can be closed.
|
static <E> Enumerable<E> |
concat(List<Enumerable<E>> enumerableList)
Concatenates two or more
Enumerables to form a composite
enumerable that contains the union of their elements. |
static <T> Enumerable<T> |
emptyEnumerable()
Returns an
Enumerable that has no elements. |
static <T> Enumerator<T> |
emptyEnumerator()
Returns an
Enumerator that 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> boolean |
equals(T t0,
T t1)
Deprecated.
|
static Method |
getMethod(String className,
String methodName,
Class... parameterTypes) |
static <T> Enumerator<T> |
iterableEnumerator(Iterable<? extends T> iterable)
Adapter that converts an iterable into an enumerator.
|
private static <V> Enumerator<V> |
listEnumerator(List<? extends V> list) |
static <TSource,TResult> |
ofType(Iterable<TSource> source,
Class<TResult> clazz)
Returns elements of a given
Iterable that are of the specified
type. |
static <T> Iterable<List<T>> |
product(Iterable<? extends Iterable<T>> iterables)
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> T |
requireNonNull(T o)
Deprecated.
|
static <T> Enumerable<T> |
singletonEnumerable(T element)
Returns an
Enumerable that has one element. |
static <T> Enumerator<T> |
singletonEnumerator(T element)
Returns an
Enumerator that has one element. |
static <T> Enumerator<T> |
singletonNullEnumerator()
Returns an
Enumerator that has one null element. |
static <F,E> Enumerator<E> |
transform(Enumerator<F> enumerator,
Function1<F,E> func)
Applies a function to each element of an Enumerator.
|
private static final Object DUMMY
public static final QueryProvider DEFAULT_PROVIDER
Queryable by calling its
enumerator method; does not attempt optimization.private static final Enumerator<Object> EMPTY_ENUMERATOR
public static final Enumerable<?> EMPTY_ENUMERABLE
public static Method getMethod(String className, String methodName, Class... parameterTypes)
public static <T> Iterator<T> enumeratorIterator(Enumerator<T> enumerator)
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.
T - Element typeenumerator - Enumeratorpublic static <T> Enumerator<T> iterableEnumerator(Iterable<? extends T> iterable)
T - Element typeiterable - Iterablepublic static <T> Enumerable<T> asEnumerable(List<T> list)
List into an Enumerable.T - Element typelist - Listpublic static <T> Enumerable<T> asEnumerable(Collection<T> collection)
Collection into an Enumerable.
It uses more efficient implementations if the iterable happens to
be a List.
T - Element typecollection - Collectionpublic static <T> Enumerable<T> asEnumerable(Iterable<T> iterable)
Iterable into an Enumerable.
It uses more efficient implementations if the iterable happens to
be a Collection or a List.
T - Element typeiterable - Iterablepublic static <T> Enumerable<T> asEnumerable(T[] ts)
T - Element typets - Arraypublic static <V> Enumerator<V> enumerator(Collection<? extends V> values)
V - Element typevalues - Collectionprivate static <V> Enumerator<V> listEnumerator(List<? extends V> list)
public static <F,E> Enumerator<E> transform(Enumerator<F> enumerator, Function1<F,E> func)
F - Backing element typeE - Element typeenumerator - Backing enumeratorfunc - Transform functionpublic static <TSource,TResult> Enumerable<TResult> cast(Iterable<TSource> source, Class<TResult> clazz)
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 using
for (... in ...).
Since standard Java Collection objects implement the
Iterable interface, the cast method enables the standard
query operators to be invoked on collections
(including List and Set) by supplying
the necessary type information. For example, ArrayList does not
implement Enumerable<F>, but you can invoke
Linq4j.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 the ofType(java.lang.Iterable<TSource>, java.lang.Class<TResult>) method instead.
public static <TSource,TResult> Enumerable<TResult> ofType(Iterable<TSource> source, Class<TResult> clazz)
Iterable that 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 using
for (... in ...).
The ofType method 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, use
cast(Iterable, Class).
Since standard Java Collection objects implement the
Iterable interface, the cast method enables the standard
query operators to be invoked on collections
(including List and Set) by supplying
the necessary type information. For example, ArrayList does not
implement Enumerable<F>, but you can invoke
Linq4j.ofType(list, Integer.class)
to convert the list of an enumerable that can be queried using the standard query operators.
public static <T> Enumerable<T> singletonEnumerable(T element)
Enumerable that has one element.T - Element typepublic static <T> Enumerator<T> singletonEnumerator(T element)
Enumerator that has one element.T - Element typepublic static <T> Enumerator<T> singletonNullEnumerator()
Enumerator that has one null element.T - Element typepublic static <T> Enumerable<T> emptyEnumerable()
Enumerable that has no elements.T - Element typepublic static <T> Enumerator<T> emptyEnumerator()
Enumerator that has no elements.T - Element typepublic static <E> Enumerable<E> concat(List<Enumerable<E>> enumerableList)
Enumerables to form a composite
enumerable that contains the union of their elements.E - Element typeenumerableList - List of enumerable objectspublic static <T> Enumerator<List<T>> product(List<Enumerator<T>> 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.
T - Element typeenumerators - List of enumeratorspublic static <T> Iterable<List<T>> product(Iterable<? extends Iterable<T>> iterables)
@Deprecated public static <T> boolean equals(T t0, T t1)
Equivalent to Objects.equals(java.lang.Object, java.lang.Object) in JDK 1.7 and above.
@Deprecated public static <T> T requireNonNull(T o)
NullPointerException if argument is null, otherwise
returns argument.
Equivalent to Objects.requireNonNull(T) in JDK 1.7 and
above.
private static <T> void closeIterator(Iterator<T> iterator)
Copyright © 2012–2021 The Apache Software Foundation. All rights reserved.