ResultSetEnumerator( ResultSet resultSet, Function1<ResultSet, Function0<T>> rowBuilderFactory) { this.resultSet = resultSet; this.rowBuilder = rowBuilderFactory.apply(resultSet); }
public void run() { for (int i = 0; i < repeat; i++) { function.apply(statistician); } statistician.printDurations(); }
public void run() { for (int i = 0; i < repeat; i++) { function.apply(statistician); } statistician.printDurations(); }
ResultSetEnumerator( ResultSet resultSet, Function1<ResultSet, Function0<T>> rowBuilderFactory) { this.resultSet = resultSet; this.rowBuilder = rowBuilderFactory.apply(resultSet); }
/** * Creates child visitor. It is used to traverse nested class declarations. * * @return new {@code Visitor} that is used to optimize class declarations */ protected ClassDeclarationFinder goDeeper() { return childFactory.apply(this); } }
protected E transform(F from) { return func.apply(from); } };
public E get(int index) { return fn.apply(index); } }
public Object[] execute() { return compiledFunction.apply(dataContext); }
public Object[] execute() { return compiledFunction.apply(dataContext); }
public R get(int index) { return f.apply(ts[index]); }
public R get(int index) { return f.apply(list.get(index)); }
public int hashCode(T t) { return t == null ? 0x789d : selector.apply(t).hashCode(); } }
/** * Creates a copy of a list, applying a function to each element. */ public static <T1, R> List<R> apply(final List<T1> list, final Function1<T1, R> f) { final List<R> list2 = new ArrayList<>(list.size()); for (T1 t : list) { list2.add(f.apply(t)); } return list2; }
public Function1<LazySource<TSource>, TResult> singleGroupResultSelector( Function1<TOrigAccumulate, TResult> resultSelector) { return lazySource -> { final TOrigAccumulate accumulator = accumulatorInitializer.apply(); for (SourceSorter<TOrigAccumulate, TSource, TSortKey> acc : sourceSorters) { acc.sortAndAccumulate(lazySource, accumulator); } return resultSelector.apply(accumulator); }; }
/** * Creates a {@code Map<TKey, TValue>} from an * {@code Enumerable<TSource>} according to a specified key selector function, * a comparer, and an element selector function. */ public static <TSource, TKey, TElement> Map<TKey, TElement> toMap( Enumerable<TSource> source, Function1<TSource, TKey> keySelector, Function1<TSource, TElement> elementSelector, EqualityComparer<TKey> comparer) { // Use LinkedHashMap because groupJoin requires order of keys to be // preserved. final Map<TKey, TElement> map = new WrapMap<>( // Java 8 cannot infer return type with LinkedHashMap::new is used () -> new LinkedHashMap<Wrapped<TKey>, TElement>(), comparer); try (Enumerator<TSource> os = source.enumerator()) { while (os.moveNext()) { TSource o = os.current(); map.put(keySelector.apply(o), elementSelector.apply(o)); } } return map; }
public void reduce(RexBuilder rexBuilder, List<RexNode> constExps, List<RexNode> reducedValues) { Object[] values; try { values = compiledFunction.apply(dataContext); assert values.length == constExps.size(); final List<Object> valueList = Arrays.asList(values); for (Pair<RexNode, Object> value : Pair.zip(constExps, valueList)) { reducedValues.add( rexBuilder.makeLiteral(value.right, value.left.getType(), true)); } } catch (RuntimeException e) { // One or more of the expressions failed. // Don't reduce any of the expressions. reducedValues.addAll(constExps); values = new Object[constExps.size()]; } Hook.EXPRESSION_REDUCER.run(Pair.of(code, values)); }
public void reduce(RexBuilder rexBuilder, List<RexNode> constExps, List<RexNode> reducedValues) { Object[] values; try { values = compiledFunction.apply(dataContext); assert values.length == constExps.size(); final List<Object> valueList = Arrays.asList(values); for (Pair<RexNode, Object> value : Pair.zip(constExps, valueList)) { reducedValues.add( rexBuilder.makeLiteral(value.right, value.left.getType(), true)); } } catch (RuntimeException e) { // One or more of the expressions failed. // Don't reduce any of the expressions. reducedValues.addAll(constExps); values = new Object[constExps.size()]; } Hook.EXPRESSION_REDUCER.run(Pair.of(code, values)); }
public <R> R foreach(Function1<T, R> func) { R result = null; try (Enumerator<T> enumerator = enumerator()) { while (enumerator.moveNext()) { T t = enumerator.current(); result = func.apply(t); } return result; } }
private static <TSource, TKey, TResult> Enumerable<TResult> groupBy_( final Set<TKey> map, Enumerable<TSource> enumerable, Function1<TSource, TKey> keySelector, final Function1<TKey, TResult> resultSelector) { try (Enumerator<TSource> os = enumerable.enumerator()) { while (os.moveNext()) { TSource o = os.current(); TKey key = keySelector.apply(o); map.add(key); } } return Linq4j.asEnumerable(map).select(resultSelector); }