/** * Projects each element of a sequence into a new form. */ public static <TSource, TResult> Enumerable<TResult> select( final Enumerable<TSource> source, final Function1<TSource, TResult> selector) { if (selector == Functions.identitySelector()) { //noinspection unchecked return (Enumerable<TResult>) source; } return new AbstractEnumerable<TResult>() { public Enumerator<TResult> enumerator() { return new Enumerator<TResult>() { final Enumerator<TSource> enumerator = source.enumerator(); public TResult current() { return selector.apply(enumerator.current()); } public boolean moveNext() { return enumerator.moveNext(); } public void reset() { enumerator.reset(); } public void close() { enumerator.close(); } }; } }; }
this.sources = Functions.generate(rowType.getFieldCount(), i -> ImmutableIntList.of(offset + i)); this.trivial = true;
/** * Returns the number of elements in a * sequence. */ public static <TSource> int count(Enumerable<TSource> enumerable) { return (int) longCount(enumerable, Functions.truePredicate1()); }
/** * Returns distinct elements from a sequence by using * a specified {@link EqualityComparer} to compare values. */ public static <TSource> Enumerable<TSource> distinct( Enumerable<TSource> enumerable, EqualityComparer<TSource> comparer) { if (comparer == Functions.identityComparer()) { return distinct(enumerable); } final Set<Wrapped<TSource>> set = new HashSet<>(); Function1<TSource, Wrapped<TSource>> wrapper = wrapperFor(comparer); Function1<Wrapped<TSource>, TSource> unwrapper = unwrapper(); enumerable.select(wrapper).into(set); return Linq4j.asEnumerable(set).select(unwrapper); }
/** * Invokes a transform function on each element of a * sequence and returns the maximum int value. */ public static <TSource> int max(Enumerable<TSource> source, IntegerFunction1<TSource> selector) { return aggregate(source.select(adapt(selector)), null, Extensions.INTEGER_MAX); }
/** * Creates a new HepPlanner with the option to keep the graph a * tree (noDag = true) or allow DAG (noDag = false). * * @param noDag If false, create shared nodes if expressions are * identical * @param program Program controlling rule application * @param onCopyHook Function to call when a node is copied */ public HepPlanner( HepProgram program, Context context, boolean noDag, Function2<RelNode, RelNode, Void> onCopyHook, RelOptCostFactory costFactory) { super(costFactory, context); this.mainProgram = program; this.onCopyHook = Util.first(onCopyHook, Functions.ignore2()); this.noDag = noDag; }
static Predicate1<String> matcher(final Pat pattern) { if (pattern.s == null || pattern.s.equals("%")) { return Functions.truePredicate1(); } final Pattern regex = likeToRegex(pattern); return v1 -> regex.matcher(v1).matches(); }
@Test public void testSemiJoin() { assertThat( EnumerableDefaults.semiJoin(EMPS, DEPTS, e -> e.deptno, d -> d.deptno, Functions.identityComparer()).toList().toString(), equalTo("[Emp(20, Theodore), Emp(20, Sebastian)]")); }
/** * Invokes a transform function on each element of a * sequence and returns the maximum long value. */ public static <TSource> long max(Enumerable<TSource> source, LongFunction1<TSource> selector) { return aggregate(source.select(adapt(selector)), null, Extensions.LONG_MAX); }
/** * Creates a new HepPlanner with the option to keep the graph a * tree(noDAG=true) or allow DAG(noDAG=false). * * @param program program controlling rule application * @param onCopyHook Function to call when a node is copied */ public HepPlanner( HepProgram program, Context context, boolean noDAG, Function2<RelNode, RelNode, Void> onCopyHook, RelOptCostFactory costFactory) { super(costFactory, context); this.mainProgram = program; this.onCopyHook = Util.first(onCopyHook, Functions.ignore2()); mapDigestToVertex = new HashMap<>(); graph = DefaultDirectedGraph.create(); // NOTE jvs 24-Apr-2006: We use LinkedHashSet here and below // in order to provide deterministic behavior. allRules = new LinkedHashSet<>(); this.noDAG = noDAG; }
/** * Creates a Map<TKey, TValue> from an * Enumerable<TSource> according to a specified key selector * function. * * <p>NOTE: Called {@code toDictionary} in LINQ.NET.</p> */ public static <TSource, TKey> Map<TKey, TSource> toMap( Enumerable<TSource> source, Function1<TSource, TKey> keySelector) { return toMap(source, keySelector, Functions.identitySelector()); }
static Predicate1<String> matcher(final Pat pattern) { if (pattern.s == null || pattern.s.equals("%")) { return Functions.truePredicate1(); } final Pattern regex = likeToRegex(pattern); return v1 -> regex.matcher(v1).matches(); }
/** Returns a list that contains the values lower to upper - 1. * * <p>For example, {@code range(1, 3)} contains [1, 2]. */ public static List<Integer> range(final int lower, final int upper) { return Functions.generate(upper - lower, new Function1<Integer, Integer>() { /** @see Bug#upgrade(String) Upgrade to {@code IntFunction} when we * drop support for JDK 1.7 */ public Integer apply(Integer index) { return lower + index; } }); }
@Test public void testSemiJoin() { assertThat( EnumerableDefaults.semiJoin(EMPS, DEPTS, e -> e.deptno, d -> d.deptno, Functions.identityComparer()).toList().toString(), equalTo("[Emp(20, Theodore), Emp(20, Sebastian)]")); }
/** * Invokes a transform function on each element of a * sequence and returns the minimum long value. */ public static <TSource> long min(Enumerable<TSource> source, LongFunction1<TSource> selector) { return aggregate(source.select(adapt(selector)), null, Extensions.LONG_MIN); }
/** * Creates a Lookup<TKey, TElement> from an * Enumerable<TSource> according to a specified key selector * function. */ public static <TSource, TKey> Lookup<TKey, TSource> toLookup( Enumerable<TSource> source, Function1<TSource, TKey> keySelector) { return toLookup(source, keySelector, Functions.identitySelector()); }
static Predicate1<String> matcher(final Pat pattern) { if (pattern.s == null || pattern.s.equals("%")) { return Functions.truePredicate1(); } final Pattern regex = likeToRegex(pattern); return new Predicate1<String>() { public boolean apply(String v1) { return regex.matcher(v1).matches(); } }; }
/** Returns a list that contains the values lower to upper - 1. * * <p>For example, {@code range(1, 3)} contains [1, 2]. */ public static List<Integer> range(final int lower, final int upper) { return Functions.generate(upper - lower, new Function1<Integer, Integer>() { /** @see Bug#upgrade(String) Upgrade to {@code IntFunction} when we * drop support for JDK 1.7 */ public Integer apply(Integer index) { return lower + index; } }); }
/** * Produces the set intersection of two sequences by * using the specified {@code EqualityComparer<TSource>} to compare * values. */ public static <TSource> Enumerable<TSource> intersect( Enumerable<TSource> source0, Enumerable<TSource> source1, EqualityComparer<TSource> comparer) { if (comparer == Functions.identityComparer()) { return intersect(source0, source1); } Set<Wrapped<TSource>> set0 = new HashSet<>(); Function1<TSource, Wrapped<TSource>> wrapper = wrapperFor(comparer); source0.select(wrapper).into(set0); Set<Wrapped<TSource>> set1 = new HashSet<>(); try (Enumerator<Wrapped<TSource>> os = source1.select(wrapper).enumerator()) { while (os.moveNext()) { Wrapped<TSource> o = os.current(); if (set0.contains(o)) { set1.add(o); } } } Function1<Wrapped<TSource>, TSource> unwrapper = unwrapper(); return Linq4j.asEnumerable(set1).select(unwrapper); }
/** * Invokes a transform function on each element of a * sequence and returns the minimum Float value. */ public static <TSource> float min(Enumerable<TSource> source, FloatFunction1<TSource> selector) { return aggregate(source.select(adapt(selector)), null, Extensions.FLOAT_MIN); }