当前位置: 首页>>代码示例>>Java>>正文


Java Function2.apply方法代码示例

本文整理汇总了Java中org.apache.calcite.linq4j.function.Function2.apply方法的典型用法代码示例。如果您正苦于以下问题:Java Function2.apply方法的具体用法?Java Function2.apply怎么用?Java Function2.apply使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.calcite.linq4j.function.Function2的用法示例。


在下文中一共展示了Function2.apply方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: groupBy_

import org.apache.calcite.linq4j.function.Function2; //导入方法依赖的package包/类
private static <TSource, TKey, TAccumulate, TResult> Enumerable<TResult> groupBy_(
    final Map<TKey, TAccumulate> map, Enumerable<TSource> enumerable,
    Function1<TSource, TKey> keySelector,
    Function0<TAccumulate> accumulatorInitializer,
    Function2<TAccumulate, TSource, TAccumulate> accumulatorAdder,
    final Function2<TKey, TAccumulate, TResult> resultSelector) {
  try (Enumerator<TSource> os = enumerable.enumerator()) {
    while (os.moveNext()) {
      TSource o = os.current();
      TKey key = keySelector.apply(o);
      TAccumulate accumulator = map.get(key);
      if (accumulator == null) {
        accumulator = accumulatorInitializer.apply();
        accumulator = accumulatorAdder.apply(accumulator, o);
        map.put(key, accumulator);
      } else {
        TAccumulate accumulator0 = accumulator;
        accumulator = accumulatorAdder.apply(accumulator, o);
        if (accumulator != accumulator0) {
          map.put(key, accumulator);
        }
      }
    }
  }
  return new LookupResultEnumerable<>(map, resultSelector);
}
 
开发者ID:apache,项目名称:calcite,代码行数:27,代码来源:EnumerableDefaults.java

示例2: predicate

import org.apache.calcite.linq4j.function.Function2; //导入方法依赖的package包/类
private Predicate2<DataAccessor, DataAccessor> predicate(
        Function2<DataAccessor, DataAccessor, DataAccessor> projection,
        StatementEvaluationContext context) {
    return (DataAccessor v0, DataAccessor v1) -> {
        DataAccessor currentRow = projection.apply(v0, v1);
        return SQLRecordPredicate.toBoolean(condition.evaluate(currentRow, context));
    };
}
 
开发者ID:diennea,项目名称:herddb,代码行数:9,代码来源:ThetaJoinOp.java

示例3: applyResultSelector

import org.apache.calcite.linq4j.function.Function2; //导入方法依赖的package包/类
public <TResult> Enumerable<TResult> applyResultSelector(
    final Function2<K, Enumerable<V>, TResult> resultSelector) {
  return new AbstractEnumerable<TResult>() {
    public Enumerator<TResult> enumerator() {
      final Enumerator<Grouping<K, V>> groupingEnumerator =
          LookupImpl.this.enumerator();
      return new Enumerator<TResult>() {
        public TResult current() {
          final Grouping<K, V> grouping = groupingEnumerator.current();
          return resultSelector.apply(grouping.getKey(), grouping);
        }

        public boolean moveNext() {
          return groupingEnumerator.moveNext();
        }

        public void reset() {
          groupingEnumerator.reset();
        }

        public void close() {
          groupingEnumerator.close();
        }
      };
    }
  };
}
 
开发者ID:apache,项目名称:calcite,代码行数:28,代码来源:LookupImpl.java

示例4: aggregate

import org.apache.calcite.linq4j.function.Function2; //导入方法依赖的package包/类
/**
 * Applies an accumulator function over a sequence.
 */
public static <TSource> TSource aggregate(Enumerable<TSource> source,
    Function2<TSource, TSource, TSource> func) {
  TSource result = null;
  try (Enumerator<TSource> os = source.enumerator()) {
    while (os.moveNext()) {
      TSource o = os.current();
      result = func.apply(result, o);
    }
    return result;
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:15,代码来源:EnumerableDefaults.java

示例5: groupByMultiple_

import org.apache.calcite.linq4j.function.Function2; //导入方法依赖的package包/类
private static <TSource, TKey, TAccumulate, TResult> Enumerable<TResult> groupByMultiple_(
    final Map<TKey, TAccumulate> map, Enumerable<TSource> enumerable,
    List<Function1<TSource, TKey>> keySelectors,
    Function0<TAccumulate> accumulatorInitializer,
    Function2<TAccumulate, TSource, TAccumulate> accumulatorAdder,
    final Function2<TKey, TAccumulate, TResult> resultSelector) {
  try (Enumerator<TSource> os = enumerable.enumerator()) {
    while (os.moveNext()) {
      for (Function1<TSource, TKey> keySelector : keySelectors) {
        TSource o = os.current();
        TKey key = keySelector.apply(o);
        TAccumulate accumulator = map.get(key);
        if (accumulator == null) {
          accumulator = accumulatorInitializer.apply();
          accumulator = accumulatorAdder.apply(accumulator, o);
          map.put(key, accumulator);
        } else {
          TAccumulate accumulator0 = accumulator;
          accumulator = accumulatorAdder.apply(accumulator, o);
          if (accumulator != accumulator0) {
            map.put(key, accumulator);
          }
        }
      }
    }
  }
  return new LookupResultEnumerable<>(map, resultSelector);
}
 
开发者ID:apache,项目名称:calcite,代码行数:29,代码来源:EnumerableDefaults.java

示例6: groupJoin

import org.apache.calcite.linq4j.function.Function2; //导入方法依赖的package包/类
/**
 * Correlates the elements of two sequences based on
 * equality of keys and groups the results. The default equality
 * comparer is used to compare keys.
 */
public static <TSource, TInner, TKey, TResult> Enumerable<TResult> groupJoin(
    final Enumerable<TSource> outer, final Enumerable<TInner> inner,
    final Function1<TSource, TKey> outerKeySelector,
    final Function1<TInner, TKey> innerKeySelector,
    final Function2<TSource, Enumerable<TInner>, TResult> resultSelector) {
  return new AbstractEnumerable<TResult>() {
    final Map<TKey, TSource> outerMap = outer.toMap(outerKeySelector);
    final Lookup<TKey, TInner> innerLookup = inner.toLookup(innerKeySelector);
    final Enumerator<Map.Entry<TKey, TSource>> entries =
        Linq4j.enumerator(outerMap.entrySet());

    public Enumerator<TResult> enumerator() {
      return new Enumerator<TResult>() {
        public TResult current() {
          final Map.Entry<TKey, TSource> entry = entries.current();
          final Enumerable<TInner> inners = innerLookup.get(entry.getKey());
          return resultSelector.apply(entry.getValue(),
              inners == null ? Linq4j.<TInner>emptyEnumerable() : inners);
        }

        public boolean moveNext() {
          return entries.moveNext();
        }

        public void reset() {
          entries.reset();
        }

        public void close() {
        }
      };
    }
  };
}
 
开发者ID:apache,项目名称:calcite,代码行数:40,代码来源:EnumerableDefaults.java

示例7: select

import org.apache.calcite.linq4j.function.Function2; //导入方法依赖的package包/类
/**
 * Projects each element of a sequence into a new
 * form by incorporating the element's index.
 */
public static <TSource, TResult> Enumerable<TResult> select(
    final Enumerable<TSource> source,
    final Function2<TSource, Integer, TResult> selector) {
  return new AbstractEnumerable<TResult>() {
    public Enumerator<TResult> enumerator() {
      return new Enumerator<TResult>() {
        final Enumerator<TSource> enumerator = source.enumerator();
        int n = -1;

        public TResult current() {
          return selector.apply(enumerator.current(), n);
        }

        public boolean moveNext() {
          if (enumerator.moveNext()) {
            ++n;
            return true;
          } else {
            return false;
          }
        }

        public void reset() {
          enumerator.reset();
        }

        public void close() {
          enumerator.close();
        }
      };
    }
  };
}
 
开发者ID:apache,项目名称:calcite,代码行数:38,代码来源:EnumerableDefaults.java

示例8: zip

import org.apache.calcite.linq4j.function.Function2; //导入方法依赖的package包/类
/**
 * Applies a specified function to the corresponding
 * elements of two sequences, producing a sequence of the
 * results.
 */
public static <T0, T1, TResult> Enumerable<TResult> zip(
    final Enumerable<T0> first, final Enumerable<T1> second,
    final Function2<T0, T1, TResult> resultSelector) {
  return new AbstractEnumerable<TResult>() {
    public Enumerator<TResult> enumerator() {
      return new Enumerator<TResult>() {
        final Enumerator<T0> e1 = first.enumerator();
        final Enumerator<T1> e2 = second.enumerator();

        public TResult current() {
          return resultSelector.apply(e1.current(), e2.current());
        }
        public boolean moveNext() {
          return e1.moveNext() && e2.moveNext();
        }
        public void reset() {
          e1.reset();
          e2.reset();
        }
        public void close() {
          e1.close();
          e2.close();
        }
      };
    }
  };
}
 
开发者ID:apache,项目名称:calcite,代码行数:33,代码来源:EnumerableDefaults.java

示例9: selectMany

import org.apache.calcite.linq4j.function.Function2; //导入方法依赖的package包/类
/**
 * Projects each element of a sequence to an
 * {@code Enumerable<TSource>}, flattens the resulting sequences into one
 * sequence, and invokes a result selector function on each
 * element therein. The index of each source element is used in
 * the intermediate projected form of that element.
 */
public static <TSource, TCollection, TResult> Enumerable<TResult> selectMany(
    final Enumerable<TSource> source,
    final Function2<TSource, Integer, Enumerable<TCollection>> collectionSelector,
    final Function2<TSource, TCollection, TResult> resultSelector) {
  return new AbstractEnumerable<TResult>() {
    public Enumerator<TResult> enumerator() {
      return new Enumerator<TResult>() {
        int index = -1;
        Enumerator<TSource> sourceEnumerator = source.enumerator();
        Enumerator<TCollection> collectionEnumerator = Linq4j.emptyEnumerator();
        Enumerator<TResult> resultEnumerator = Linq4j.emptyEnumerator();

        public TResult current() {
          return resultEnumerator.current();
        }

        public boolean moveNext() {
          for (;;) {
            if (resultEnumerator.moveNext()) {
              return true;
            }
            if (!sourceEnumerator.moveNext()) {
              return false;
            }
            index += 1;
            final TSource sourceElement = sourceEnumerator.current();
            collectionEnumerator = collectionSelector.apply(sourceElement, index)
                .enumerator();
            resultEnumerator =
                new TransformedEnumerator<TCollection, TResult>(collectionEnumerator) {
                  protected TResult transform(TCollection collectionElement) {
                    return resultSelector.apply(sourceElement, collectionElement);
                  }
                };
          }
        }

        public void reset() {
          sourceEnumerator.reset();
          resultEnumerator = Linq4j.emptyEnumerator();
        }

        public void close() {
          sourceEnumerator.close();
          resultEnumerator.close();
        }
      };
    }
  };
}
 
开发者ID:apache,项目名称:calcite,代码行数:58,代码来源:EnumerableDefaults.java


注:本文中的org.apache.calcite.linq4j.function.Function2.apply方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。