All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.calcite.linq4j.DefaultEnumerable Maven / Gradle / Ivy

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to you under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.calcite.linq4j;

import org.apache.calcite.linq4j.function.BigDecimalFunction1;
import org.apache.calcite.linq4j.function.DoubleFunction1;
import org.apache.calcite.linq4j.function.EqualityComparer;
import org.apache.calcite.linq4j.function.FloatFunction1;
import org.apache.calcite.linq4j.function.Function0;
import org.apache.calcite.linq4j.function.Function1;
import org.apache.calcite.linq4j.function.Function2;
import org.apache.calcite.linq4j.function.IntegerFunction1;
import org.apache.calcite.linq4j.function.LongFunction1;
import org.apache.calcite.linq4j.function.NullableBigDecimalFunction1;
import org.apache.calcite.linq4j.function.NullableDoubleFunction1;
import org.apache.calcite.linq4j.function.NullableFloatFunction1;
import org.apache.calcite.linq4j.function.NullableIntegerFunction1;
import org.apache.calcite.linq4j.function.NullableLongFunction1;
import org.apache.calcite.linq4j.function.Predicate1;
import org.apache.calcite.linq4j.function.Predicate2;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.nullness.qual.PolyNull;

import java.math.BigDecimal;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

/**
 * Implementation of the {@link org.apache.calcite.linq4j.Enumerable} interface
 * that implements the extension methods by calling into the {@link Extensions}
 * class.
 *
 * 

The are two abstract methods: * {@link #enumerator()} and {@link #iterator()}. * The derived class can implement each separately, or implement one in terms of * the other. * * @param Element type */ public abstract class DefaultEnumerable implements OrderedEnumerable { /** * Derived classes might wish to override this method to return the "outer" * enumerable. */ protected Enumerable getThis() { return this; } /** * Derived classes might wish to override this method to return the "outer" * ordered-enumerable. */ protected OrderedEnumerable getThisOrdered() { return this; } @Override public @Nullable R foreach(Function1 func) { R result = null; try (Enumerator enumerator = enumerator()) { while (enumerator.moveNext()) { T t = enumerator.current(); result = func.apply(t); } return result; } } @Override public Queryable asQueryable() { return Extensions.asQueryable(this); } // NOTE: Not part of the Queryable interface. protected OrderedQueryable asOrderedQueryable() { return EnumerableDefaults.asOrderedQueryable(this); } @Override public @Nullable T aggregate(Function2<@Nullable T, T, T> func) { return EnumerableDefaults.aggregate(getThis(), func); } @Override public @PolyNull TAccumulate aggregate(@PolyNull TAccumulate seed, Function2<@PolyNull TAccumulate, T, @PolyNull TAccumulate> func) { return EnumerableDefaults.aggregate(getThis(), seed, func); } @Override public TResult aggregate(TAccumulate seed, Function2 func, Function1 selector) { return EnumerableDefaults.aggregate(getThis(), seed, func, selector); } @Override public boolean all(Predicate1 predicate) { return EnumerableDefaults.all(getThis(), predicate); } @Override public boolean any() { return EnumerableDefaults.any(getThis()); } @Override public boolean any(Predicate1 predicate) { return EnumerableDefaults.any(getThis(), predicate); } @Override public Enumerable asEnumerable() { return EnumerableDefaults.asEnumerable(getThis()); } @Override public BigDecimal average(BigDecimalFunction1 selector) { return EnumerableDefaults.average(getThis(), selector); } @Override public BigDecimal average(NullableBigDecimalFunction1 selector) { return EnumerableDefaults.average(getThis(), selector); } @Override public double average(DoubleFunction1 selector) { return EnumerableDefaults.average(getThis(), selector); } @Override public Double average(NullableDoubleFunction1 selector) { return EnumerableDefaults.average(getThis(), selector); } @Override public int average(IntegerFunction1 selector) { return EnumerableDefaults.average(getThis(), selector); } @Override public Integer average(NullableIntegerFunction1 selector) { return EnumerableDefaults.average(getThis(), selector); } @Override public long average(LongFunction1 selector) { return EnumerableDefaults.average(getThis(), selector); } @Override public Long average(NullableLongFunction1 selector) { return EnumerableDefaults.average(getThis(), selector); } @Override public float average(FloatFunction1 selector) { return EnumerableDefaults.average(getThis(), selector); } @Override public Float average(NullableFloatFunction1 selector) { return EnumerableDefaults.average(getThis(), selector); } @Override public Enumerable cast(Class clazz) { return EnumerableDefaults.cast(getThis(), clazz); } @Override public Enumerable concat(Enumerable enumerable1) { return EnumerableDefaults.concat(getThis(), enumerable1); } @Override public boolean contains(T element) { return EnumerableDefaults.contains(getThis(), element); } @Override public boolean contains(T element, EqualityComparer comparer) { return EnumerableDefaults.contains(getThis(), element, comparer); } @Override public int count() { return EnumerableDefaults.count(getThis()); } @Override public int count(Predicate1 predicate) { return EnumerableDefaults.count(getThis(), predicate); } @Override public OrderedEnumerable createOrderedEnumerable( Function1 keySelector, Comparator comparator, boolean descending) { return EnumerableDefaults.createOrderedEnumerable(getThisOrdered(), keySelector, comparator, descending); } @Override public Enumerable<@Nullable T> defaultIfEmpty() { return EnumerableDefaults.defaultIfEmpty(getThis()); } @Override public Enumerable<@PolyNull T> defaultIfEmpty(@PolyNull T value) { return EnumerableDefaults.defaultIfEmpty(getThis(), value); } @Override public Enumerable distinct() { return EnumerableDefaults.distinct(getThis()); } @Override public Enumerable distinct(EqualityComparer comparer) { return EnumerableDefaults.distinct(getThis(), comparer); } @Override public T elementAt(int index) { return EnumerableDefaults.elementAt(getThis(), index); } @Override public @Nullable T elementAtOrDefault(int index) { return EnumerableDefaults.elementAtOrDefault(getThis(), index); } @Override public Enumerable except(Enumerable enumerable1) { return except(enumerable1, false); } @Override public Enumerable except(Enumerable enumerable1, boolean all) { return EnumerableDefaults.except(getThis(), enumerable1, all); } @Override public Enumerable except(Enumerable enumerable1, EqualityComparer comparer) { return except(enumerable1, comparer, false); } @Override public Enumerable except(Enumerable enumerable1, EqualityComparer comparer, boolean all) { return EnumerableDefaults.except(getThis(), enumerable1, comparer, all); } @Override public T first() { return EnumerableDefaults.first(getThis()); } @Override public T first(Predicate1 predicate) { return EnumerableDefaults.first(getThis(), predicate); } @Override public @Nullable T firstOrDefault() { return EnumerableDefaults.firstOrDefault(getThis()); } @Override public @Nullable T firstOrDefault(Predicate1 predicate) { return EnumerableDefaults.firstOrDefault(getThis(), predicate); } @Override public Enumerable> groupBy( Function1 keySelector) { return EnumerableDefaults.groupBy(getThis(), keySelector); } @Override public Enumerable> groupBy( Function1 keySelector, EqualityComparer comparer) { return EnumerableDefaults.groupBy(getThis(), keySelector, comparer); } @Override public Enumerable> groupBy( Function1 keySelector, Function1 elementSelector) { return EnumerableDefaults.groupBy(getThis(), keySelector, elementSelector); } @Override public Enumerable> groupBy( Function1 keySelector, Function1 elementSelector, EqualityComparer comparer) { return EnumerableDefaults.groupBy(getThis(), keySelector, elementSelector, comparer); } @Override public Enumerable groupBy( Function1 keySelector, Function2, TResult> elementSelector, EqualityComparer comparer) { return EnumerableDefaults.groupBy(getThis(), keySelector, elementSelector, comparer); } @Override public Enumerable groupBy( Function1 keySelector, Function2, TResult> resultSelector) { return EnumerableDefaults.groupBy(getThis(), keySelector, resultSelector); } @Override public Enumerable groupBy( Function1 keySelector, Function1 elementSelector, Function2, TResult> resultSelector) { return EnumerableDefaults.groupBy(getThis(), keySelector, elementSelector, resultSelector); } @Override public Enumerable groupBy( Function1 keySelector, Function1 elementSelector, Function2, TResult> resultSelector, EqualityComparer comparer) { return EnumerableDefaults.groupBy(getThis(), keySelector, elementSelector, resultSelector, comparer); } @Override public Enumerable groupBy( Function1 keySelector, Function0 accumulatorInitializer, Function2 accumulatorAdder, Function2 resultSelector) { return EnumerableDefaults.groupBy(getThis(), keySelector, accumulatorInitializer, accumulatorAdder, resultSelector); } @Override public Enumerable groupBy( Function1 keySelector, Function0 accumulatorInitializer, Function2 accumulatorAdder, Function2 resultSelector, EqualityComparer comparer) { return EnumerableDefaults.groupBy(getThis(), keySelector, accumulatorInitializer, accumulatorAdder, resultSelector, comparer); } @Override public Enumerable sortedGroupBy( Function1 keySelector, Function0 accumulatorInitializer, Function2 accumulatorAdder, Function2 resultSelector, Comparator comparator) { return EnumerableDefaults.sortedGroupBy( getThis(), keySelector, accumulatorInitializer, accumulatorAdder, resultSelector, comparator); } @Override public Enumerable groupJoin( Enumerable inner, Function1 outerKeySelector, Function1 innerKeySelector, Function2, TResult> resultSelector) { return EnumerableDefaults.groupJoin(getThis(), inner, outerKeySelector, innerKeySelector, resultSelector); } @Override public Enumerable groupJoin( Enumerable inner, Function1 outerKeySelector, Function1 innerKeySelector, Function2, TResult> resultSelector, EqualityComparer comparer) { return EnumerableDefaults.groupJoin(getThis(), inner, outerKeySelector, innerKeySelector, resultSelector, comparer); } @Override public Enumerable intersect(Enumerable enumerable1) { return intersect(enumerable1, false); } @Override public Enumerable intersect(Enumerable enumerable1, boolean all) { return EnumerableDefaults.intersect(getThis(), enumerable1, all); } @Override public Enumerable intersect(Enumerable enumerable1, EqualityComparer comparer) { return intersect(enumerable1, comparer, false); } @Override public Enumerable intersect(Enumerable enumerable1, EqualityComparer comparer, boolean all) { return EnumerableDefaults.intersect(getThis(), enumerable1, comparer, all); } @Override public > C into(C sink) { return EnumerableDefaults.into(getThis(), sink); } @Override public > C removeAll(C sink) { return EnumerableDefaults.remove(getThis(), sink); } @Override public Enumerable hashJoin( Enumerable inner, Function1 outerKeySelector, Function1 innerKeySelector, Function2 resultSelector) { return EnumerableDefaults.hashJoin(getThis(), inner, outerKeySelector, innerKeySelector, resultSelector); } @Override public Enumerable hashJoin( Enumerable inner, Function1 outerKeySelector, Function1 innerKeySelector, Function2 resultSelector, EqualityComparer comparer) { return EnumerableDefaults.hashJoin(getThis(), inner, outerKeySelector, innerKeySelector, resultSelector, comparer); } @Override public Enumerable hashJoin( Enumerable inner, Function1 outerKeySelector, Function1 innerKeySelector, Function2 resultSelector, EqualityComparer comparer, boolean generateNullsOnLeft, boolean generateNullsOnRight) { return EnumerableDefaults.hashJoin(getThis(), inner, outerKeySelector, innerKeySelector, resultSelector, comparer, generateNullsOnLeft, generateNullsOnRight); } @Override public Enumerable hashJoin( Enumerable inner, Function1 outerKeySelector, Function1 innerKeySelector, Function2 resultSelector, EqualityComparer comparer, boolean generateNullsOnLeft, boolean generateNullsOnRight, @Nullable Predicate2 predicate) { return EnumerableDefaults.hashJoin(getThis(), inner, outerKeySelector, innerKeySelector, resultSelector, comparer, generateNullsOnLeft, generateNullsOnRight, predicate); } @Override public Enumerable correlateJoin( JoinType joinType, Function1> inner, Function2 resultSelector) { return EnumerableDefaults.correlateJoin(joinType, getThis(), inner, resultSelector); } @Override public T last() { return EnumerableDefaults.last(getThis()); } @Override public T last(Predicate1 predicate) { return EnumerableDefaults.last(getThis(), predicate); } @Override public @Nullable T lastOrDefault() { return EnumerableDefaults.lastOrDefault(getThis()); } @Override public @Nullable T lastOrDefault(Predicate1 predicate) { return EnumerableDefaults.lastOrDefault(getThis(), predicate); } @Override public long longCount() { return EnumerableDefaults.longCount(getThis()); } @Override public long longCount(Predicate1 predicate) { return EnumerableDefaults.longCount(getThis(), predicate); } @SuppressWarnings("unchecked") @Override public @Nullable T max() { return (@Nullable T) EnumerableDefaults.max((Enumerable) getThis()); } @Override public @Nullable BigDecimal max(BigDecimalFunction1 selector) { return EnumerableDefaults.max(getThis(), selector); } @Override public @Nullable BigDecimal max(NullableBigDecimalFunction1 selector) { return EnumerableDefaults.max(getThis(), selector); } @Override public double max(DoubleFunction1 selector) { return EnumerableDefaults.max(getThis(), selector); } @Override public @Nullable Double max(NullableDoubleFunction1 selector) { return EnumerableDefaults.max(getThis(), selector); } @Override public int max(IntegerFunction1 selector) { return EnumerableDefaults.max(getThis(), selector); } @Override public @Nullable Integer max(NullableIntegerFunction1 selector) { return EnumerableDefaults.max(getThis(), selector); } @Override public long max(LongFunction1 selector) { return EnumerableDefaults.max(getThis(), selector); } @Override public @Nullable Long max(NullableLongFunction1 selector) { return EnumerableDefaults.max(getThis(), selector); } @Override public float max(FloatFunction1 selector) { return EnumerableDefaults.max(getThis(), selector); } @Override public @Nullable Float max(NullableFloatFunction1 selector) { return EnumerableDefaults.max(getThis(), selector); } @Override public > @Nullable TResult max( Function1 selector) { return EnumerableDefaults.max(getThis(), selector); } @SuppressWarnings("unchecked") @Override public @Nullable T min() { return (@Nullable T) EnumerableDefaults.min((Enumerable) getThis()); } @Override public @Nullable BigDecimal min(BigDecimalFunction1 selector) { return EnumerableDefaults.min(getThis(), selector); } @Override public @Nullable BigDecimal min(NullableBigDecimalFunction1 selector) { return EnumerableDefaults.min(getThis(), selector); } @Override public double min(DoubleFunction1 selector) { return EnumerableDefaults.min(getThis(), selector); } @Override public @Nullable Double min(NullableDoubleFunction1 selector) { return EnumerableDefaults.min(getThis(), selector); } @Override public int min(IntegerFunction1 selector) { return EnumerableDefaults.min(getThis(), selector); } @Override public @Nullable Integer min(NullableIntegerFunction1 selector) { return EnumerableDefaults.min(getThis(), selector); } @Override public long min(LongFunction1 selector) { return EnumerableDefaults.min(getThis(), selector); } @Override public @Nullable Long min(NullableLongFunction1 selector) { return EnumerableDefaults.min(getThis(), selector); } @Override public float min(FloatFunction1 selector) { return EnumerableDefaults.min(getThis(), selector); } @Override public @Nullable Float min(NullableFloatFunction1 selector) { return EnumerableDefaults.min(getThis(), selector); } @Override public > @Nullable TResult min( Function1 selector) { return EnumerableDefaults.min(getThis(), selector); } @Override public Enumerable ofType(Class clazz) { return EnumerableDefaults.ofType(getThis(), clazz); } @Override public Enumerable orderBy( Function1 keySelector) { return EnumerableDefaults.orderBy(getThis(), keySelector); } @Override public Enumerable orderBy(Function1 keySelector, Comparator comparator) { return EnumerableDefaults.orderBy(getThis(), keySelector, comparator); } @Override public Enumerable orderByDescending( Function1 keySelector) { return EnumerableDefaults.orderByDescending(getThis(), keySelector); } @Override public Enumerable orderByDescending(Function1 keySelector, Comparator comparator) { return EnumerableDefaults.orderByDescending(getThis(), keySelector, comparator); } @Override public Enumerable reverse() { return EnumerableDefaults.reverse(getThis()); } @Override public Enumerable select(Function1 selector) { return EnumerableDefaults.select(getThis(), selector); } @Override public Enumerable select( Function2 selector) { return EnumerableDefaults.select(getThis(), selector); } @Override public Enumerable selectMany( Function1> selector) { return EnumerableDefaults.selectMany(getThis(), selector); } @Override public Enumerable selectMany( Function2> selector) { return EnumerableDefaults.selectMany(getThis(), selector); } @Override public Enumerable selectMany( Function2> collectionSelector, Function2 resultSelector) { return EnumerableDefaults.selectMany(getThis(), collectionSelector, resultSelector); } @Override public Enumerable selectMany( Function1> collectionSelector, Function2 resultSelector) { return EnumerableDefaults.selectMany(getThis(), collectionSelector, resultSelector); } @Override public boolean sequenceEqual(Enumerable enumerable1) { return EnumerableDefaults.sequenceEqual(getThis(), enumerable1); } @Override public boolean sequenceEqual(Enumerable enumerable1, EqualityComparer comparer) { return EnumerableDefaults.sequenceEqual(getThis(), enumerable1, comparer); } @Override public T single() { return EnumerableDefaults.single(getThis()); } @Override public T single(Predicate1 predicate) { return EnumerableDefaults.single(getThis(), predicate); } @Override public @Nullable T singleOrDefault() { return EnumerableDefaults.singleOrDefault(getThis()); } @Override public @Nullable T singleOrDefault(Predicate1 predicate) { return EnumerableDefaults.singleOrDefault(getThis(), predicate); } @Override public Enumerable skip(int count) { return EnumerableDefaults.skip(getThis(), count); } @Override public Enumerable skipWhile(Predicate1 predicate) { return EnumerableDefaults.skipWhile(getThis(), predicate); } @Override public Enumerable skipWhile(Predicate2 predicate) { return EnumerableDefaults.skipWhile(getThis(), predicate); } @Override public BigDecimal sum(BigDecimalFunction1 selector) { return EnumerableDefaults.sum(getThis(), selector); } @Override public BigDecimal sum(NullableBigDecimalFunction1 selector) { return EnumerableDefaults.sum(getThis(), selector); } @Override public double sum(DoubleFunction1 selector) { return EnumerableDefaults.sum(getThis(), selector); } @Override public Double sum(NullableDoubleFunction1 selector) { return EnumerableDefaults.sum(getThis(), selector); } @Override public int sum(IntegerFunction1 selector) { return EnumerableDefaults.sum(getThis(), selector); } @Override public Integer sum(NullableIntegerFunction1 selector) { return EnumerableDefaults.sum(getThis(), selector); } @Override public long sum(LongFunction1 selector) { return EnumerableDefaults.sum(getThis(), selector); } @Override public Long sum(NullableLongFunction1 selector) { return EnumerableDefaults.sum(getThis(), selector); } @Override public float sum(FloatFunction1 selector) { return EnumerableDefaults.sum(getThis(), selector); } @Override public Float sum(NullableFloatFunction1 selector) { return EnumerableDefaults.sum(getThis(), selector); } @Override public Enumerable take(int count) { return EnumerableDefaults.take(getThis(), count); } @Override public Enumerable takeWhile(Predicate1 predicate) { return EnumerableDefaults.takeWhile(getThis(), predicate); } @Override public Enumerable takeWhile(Predicate2 predicate) { return EnumerableDefaults.takeWhile(getThis(), predicate); } @Override public > OrderedEnumerable thenBy( Function1 keySelector) { return EnumerableDefaults.thenBy(getThisOrdered(), keySelector); } @Override public OrderedEnumerable thenBy(Function1 keySelector, Comparator comparator) { return EnumerableDefaults.thenByDescending(getThisOrdered(), keySelector, comparator); } @Override public > OrderedEnumerable thenByDescending( Function1 keySelector) { return EnumerableDefaults.thenByDescending(getThisOrdered(), keySelector); } @Override public OrderedEnumerable thenByDescending( Function1 keySelector, Comparator comparator) { return EnumerableDefaults.thenBy(getThisOrdered(), keySelector, comparator); } @Override public Map toMap(Function1 keySelector) { return EnumerableDefaults.toMap(getThis(), keySelector); } @Override public Map toMap(Function1 keySelector, EqualityComparer comparer) { return EnumerableDefaults.toMap(getThis(), keySelector, comparer); } @Override public Map toMap( Function1 keySelector, Function1 elementSelector) { return EnumerableDefaults.toMap(getThis(), keySelector, elementSelector); } @Override public Map toMap( Function1 keySelector, Function1 elementSelector, EqualityComparer comparer) { return EnumerableDefaults.toMap(getThis(), keySelector, elementSelector, comparer); } @Override public List toList() { return EnumerableDefaults.toList(getThis()); } @Override public Lookup toLookup(Function1 keySelector) { return EnumerableDefaults.toLookup(getThis(), keySelector); } @Override public Lookup toLookup(Function1 keySelector, EqualityComparer comparer) { return EnumerableDefaults.toLookup(getThis(), keySelector, comparer); } @Override public Lookup toLookup( Function1 keySelector, Function1 elementSelector) { return EnumerableDefaults.toLookup(getThis(), keySelector, elementSelector); } @Override public Lookup toLookup( Function1 keySelector, Function1 elementSelector, EqualityComparer comparer) { return EnumerableDefaults.toLookup(getThis(), keySelector, elementSelector, comparer); } @Override public Enumerable union(Enumerable source1) { return EnumerableDefaults.union(getThis(), source1); } @Override public Enumerable union(Enumerable source1, EqualityComparer comparer) { return EnumerableDefaults.union(getThis(), source1, comparer); } @Override public Enumerable where(Predicate1 predicate) { return EnumerableDefaults.where(getThis(), predicate); } @Override public Enumerable where(Predicate2 predicate) { return EnumerableDefaults.where(getThis(), predicate); } @Override public Enumerable zip(Enumerable source1, Function2 resultSelector) { return EnumerableDefaults.zip(getThis(), source1, resultSelector); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy