/** * Returns elements of {@code outer} for which there is a member of * {@code inner} with a matching key. */ public static <TSource, TInner, TKey> Enumerable<TSource> semiJoin( final Enumerable<TSource> outer, final Enumerable<TInner> inner, final Function1<TSource, TKey> outerKeySelector, final Function1<TInner, TKey> innerKeySelector) { return semiJoin(outer, inner, outerKeySelector, innerKeySelector, null); }
public Enumerable<T> enumerable(DataContext dataContext) { Enumerable<T> enumerable = bindable.bind(dataContext); if (maxRowCount >= 0) { // Apply limit. In JDBC 0 means "no limit". But for us, -1 means // "no limit", and 0 is a valid limit. enumerable = EnumerableDefaults.take(enumerable, maxRowCount); } return enumerable; }
/** * Correlates the elements of two sequences based on * matching keys. The default equality comparer is used to compare * keys. */ public static <TSource, TInner, TKey, TResult> Enumerable<TResult> join( final Enumerable<TSource> outer, final Enumerable<TInner> inner, final Function1<TSource, TKey> outerKeySelector, final Function1<TInner, TKey> innerKeySelector, final Function2<TSource, TInner, TResult> resultSelector) { return join( outer, inner, outerKeySelector, innerKeySelector, resultSelector, null, false, false); }
/** * Returns the minimum value in a generic * sequence. */ public static <TSource extends Comparable<TSource>> TSource min( Enumerable<TSource> source) { Function2<TSource, TSource, TSource> min = minFunction(); return aggregate(source, null, min); }
/** * Returns the maximum value in a generic * sequence. */ public static <TSource extends Comparable<TSource>> TSource max( Enumerable<TSource> source) { Function2<TSource, TSource, TSource> max = maxFunction(); return aggregate(source, null, max); }
@Test public void testThetaFullJoin() { assertThat( EnumerableDefaults.thetaJoin(EMPS, DEPTS, EQUAL_DEPTNO, EMP_DEPT_TO_STRING, true, true).toList().toString(), equalTo("[{Fred, 10, null, null}, {Theodore, 20, 20, Sales}, " + "{Sebastian, 20, 20, Sales}, {Joe, 30, null, null}, " + "{null, null, 15, Marketing}]")); }
private static <T extends Comparable<T>> Enumerable<T> intersect( List<T> list0, List<T> list1) { return EnumerableDefaults.mergeJoin( Linq4j.asEnumerable(list0), Linq4j.asEnumerable(list1), Functions.identitySelector(), Functions.identitySelector(), (v0, v1) -> v0, false, false); }
public <TAccumulate, TResult> TResult aggregate(TAccumulate seed, Function2<TAccumulate, T, TAccumulate> func, Function1<TAccumulate, TResult> selector) { return EnumerableDefaults.aggregate(getThis(), seed, func, selector); }
public boolean all(Predicate1<T> predicate) { return EnumerableDefaults.all(getThis(), predicate); }
@Test public void testThetaJoin() { assertThat( EnumerableDefaults.thetaJoin(EMPS, DEPTS, EQUAL_DEPTNO, EMP_DEPT_TO_STRING, false, false).toList().toString(), equalTo("[{Theodore, 20, 20, Sales}, {Sebastian, 20, 20, Sales}]")); }
private static <T extends Comparable<T>> Enumerable<T> intersect( List<T> list0, List<T> list1) { return EnumerableDefaults.mergeJoin( Linq4j.asEnumerable(list0), Linq4j.asEnumerable(list1), Functions.identitySelector(), Functions.identitySelector(), (v0, v1) -> v0, false, false); }
public <TAccumulate, TResult> TResult aggregate(TAccumulate seed, Function2<TAccumulate, T, TAccumulate> func, Function1<TAccumulate, TResult> selector) { return EnumerableDefaults.aggregate(getThis(), seed, func, selector); } }
/** * Invokes a transform function on each element of a * generic sequence and returns the maximum resulting * value. */ public static <TSource, TResult extends Comparable<TResult>> TResult max( Enumerable<TSource> source, Function1<TSource, TResult> selector) { Function2<TResult, TResult, TResult> max = maxFunction(); return aggregate(source.select(selector), null, max); }
/** * Invokes a transform function on each element of a * generic sequence and returns the minimum resulting * value. */ public static <TSource, TResult extends Comparable<TResult>> TResult min( Enumerable<TSource> source, Function1<TSource, TResult> selector) { Function2<TResult, TResult, TResult> min = minFunction(); return aggregate(source.select(selector), null, min); }
public boolean all(FunctionExpression<Predicate1<T>> predicate) { return EnumerableDefaults.all(getThis(), predicate.getFunction()); }
@Test public void testThetaRightJoin() { assertThat( EnumerableDefaults.thetaJoin(EMPS, DEPTS, EQUAL_DEPTNO, EMP_DEPT_TO_STRING, true, false).toList().toString(), equalTo("[{Theodore, 20, 20, Sales}, {Sebastian, 20, 20, Sales}, " + "{null, null, 15, Marketing}]")); }
@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)]")); }
public Enumerable<T> enumerable(DataContext dataContext) { Enumerable<T> enumerable = bindable.bind(dataContext); if (maxRowCount >= 0) { // Apply limit. In JDBC 0 means "no limit". But for us, -1 means // "no limit", and 0 is a valid limit. enumerable = EnumerableDefaults.take(enumerable, maxRowCount); } return enumerable; }
@Test public void testMergeJoin() { assertThat( EnumerableDefaults.mergeJoin( Linq4j.asEnumerable( Arrays.asList( new Emp(10, "Fred"), new Emp(20, "Theodore"), new Emp(20, "Sebastian"), new Emp(30, "Joe"), new Emp(30, "Greg"))), Linq4j.asEnumerable( Arrays.asList( new Dept(15, "Marketing"), new Dept(20, "Sales"), new Dept(30, "Research"), new Dept(30, "Development"))), e -> e.deptno, d -> d.deptno, (v0, v1) -> v0 + ", " + v1, false, false).toList().toString(), equalTo("[Emp(20, Theodore), Dept(20, Sales)," + " Emp(20, Sebastian), Dept(20, Sales)," + " Emp(30, Joe), Dept(30, Research)," + " Emp(30, Joe), Dept(30, Development)," + " Emp(30, Greg), Dept(30, Research)," + " Emp(30, Greg), Dept(30, Development)]")); }