org.apache.calcite.util.Util.filter()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(152)

本文整理了Java中org.apache.calcite.util.Util.filter()方法的一些代码示例,展示了Util.filter()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.filter()方法的具体详情如下:
包路径:org.apache.calcite.util.Util
类名称:Util
方法名:filter

Util.filter介绍

[英]Makes a collection of untyped elements appear as a list of strictly typed elements, by filtering out those which are not of the correct type.

The returned object is an Iterable, which makes it ideal for use with the 'foreach' construct. For example,

List<Number> numbers = Arrays.asList(1, 2, 3.14, 4, null, 6E23); for (int myInt : filter(numbers, Integer.class)) {     print(i); }

will print 1, 2, 4.
[中]通过过滤掉那些类型不正确的元素,使非类型化元素的集合显示为严格类型化元素的列表。
返回的对象是一个Iterable,这使得它非常适合与“foreach”构造一起使用。例如
List<Number> numbers = Arrays.asList(1, 2, 3.14, 4, null, 6E23); for (int myInt : filter(numbers, Integer.class)) {     print(i); }
将打印1,2,4。

代码示例

代码示例来源:origin: org.apache.calcite/calcite-core

/** Returns sub-classes of relational expression. */
 public Iterable<Class<? extends RelNode>> subClasses(
   final Class<? extends RelNode> clazz) {
  return Util.filter(classes, clazz::isAssignableFrom);
 }
}

代码示例来源:origin: Qihoo360/Quicksql

/** Returns sub-classes of relational expression. */
 public Iterable<Class<? extends RelNode>> subClasses(
   final Class<? extends RelNode> clazz) {
  return Util.filter(classes, clazz::isAssignableFrom);
 }
}

代码示例来源:origin: Qihoo360/Quicksql

/** Filters an iterable. */
public static <E> Iterable<E> filter(Iterable<E> iterable,
  Predicate<E> predicate) {
 return () -> filter(iterable.iterator(), predicate);
}

代码示例来源:origin: org.apache.calcite/calcite-core

/** Filters an iterable. */
public static <E> Iterable<E> filter(Iterable<E> iterable,
  Predicate<E> predicate) {
 return () -> filter(iterable.iterator(), predicate);
}

代码示例来源:origin: org.apache.calcite/calcite-core

/** Returns all edges between one vertex to another. */
public Iterable<E> getEdges(V source, final V target) {
 final VertexInfo<V, E> info = vertexMap.get(source);
 return Util.filter(info.outEdges, outEdge -> outEdge.target.equals(target));
}

代码示例来源:origin: Qihoo360/Quicksql

@Test public void testBox() {
  final Number[] numbers = {1, 2, 3.14, 4, null, 6E23};
  List<Integer> result = new ArrayList<Integer>();
  for (int i : Util.filter(Arrays.asList(numbers), Integer.class)) {
   result.add(i);
  }
  assertEquals("[1, 2, 4]", result.toString());
 }
}

代码示例来源:origin: org.apache.calcite/calcite-core

@Test public void testBox() {
  final Number[] numbers = {1, 2, 3.14, 4, null, 6E23};
  List<Integer> result = new ArrayList<Integer>();
  for (int i : Util.filter(Arrays.asList(numbers), Integer.class)) {
   result.add(i);
  }
  assertEquals("[1, 2, 4]", result.toString());
 }
}

代码示例来源:origin: Qihoo360/Quicksql

final RexCall call = (RexCall) e;
if (call.getOperands().get(1) instanceof RexLiteral) {
 notTerms = Util.filter(notTerms,
   e2 -> {
    switch (e2.getKind()) {

代码示例来源:origin: org.apache.calcite/calcite-core

final RexCall call = (RexCall) e;
if (call.getOperands().get(1) instanceof RexLiteral) {
 notTerms = Util.filter(notTerms,
   e2 -> {
    switch (e2.getKind()) {

代码示例来源:origin: Qihoo360/Quicksql

/** Tests {@link Util#filter(Iterable, java.util.function.Predicate)}. */
@Test public void testFilter() {
 final List<String> beatles =
   Arrays.asList("John", "Paul", "George", "Ringo");
 final List<String> empty = Collections.emptyList();
 final List<String> nullBeatles =
   Arrays.asList("John", "Paul", null, "Ringo");
 assertThat(Util.filter(beatles, s -> s.length() == 4),
   isIterable(Arrays.asList("John", "Paul")));
 assertThat(Util.filter(empty, s -> s.length() == 4), isIterable(empty));
 assertThat(Util.filter(empty, s -> false), isIterable(empty));
 assertThat(Util.filter(empty, s -> true), isIterable(empty));
 assertThat(Util.filter(beatles, s -> false), isIterable(empty));
 assertThat(Util.filter(beatles, s -> true), isIterable(beatles));
 assertThat(Util.filter(nullBeatles, s -> false), isIterable(empty));
 assertThat(Util.filter(nullBeatles, s -> true), isIterable(nullBeatles));
 assertThat(Util.filter(nullBeatles, Objects::isNull),
   isIterable(Collections.singletonList(null)));
 assertThat(Util.filter(nullBeatles, Objects::nonNull),
   isIterable(Arrays.asList("John", "Paul", "Ringo")));
}

代码示例来源:origin: org.apache.calcite/calcite-core

/** Tests {@link Util#filter(Iterable, java.util.function.Predicate)}. */
@Test public void testFilter() {
 final List<String> beatles =
   Arrays.asList("John", "Paul", "George", "Ringo");
 final List<String> empty = Collections.emptyList();
 final List<String> nullBeatles =
   Arrays.asList("John", "Paul", null, "Ringo");
 assertThat(Util.filter(beatles, s -> s.length() == 4),
   isIterable(Arrays.asList("John", "Paul")));
 assertThat(Util.filter(empty, s -> s.length() == 4), isIterable(empty));
 assertThat(Util.filter(empty, s -> false), isIterable(empty));
 assertThat(Util.filter(empty, s -> true), isIterable(empty));
 assertThat(Util.filter(beatles, s -> false), isIterable(empty));
 assertThat(Util.filter(beatles, s -> true), isIterable(beatles));
 assertThat(Util.filter(nullBeatles, s -> false), isIterable(empty));
 assertThat(Util.filter(nullBeatles, s -> true), isIterable(nullBeatles));
 assertThat(Util.filter(nullBeatles, Objects::isNull),
   isIterable(Collections.singletonList(null)));
 assertThat(Util.filter(nullBeatles, Objects::nonNull),
   isIterable(Arrays.asList("John", "Paul", "Ringo")));
}

代码示例来源:origin: Qihoo360/Quicksql

private static void addWindows(
   Multimap<WindowKey, RexOver> windowMap,
   RexOver over, final int inputFieldCount) {
  final RexWindow aggWindow = over.getWindow();

  // Look up or create a window.
  RelCollation orderKeys = getCollation(
    Lists.newArrayList(
      Util.filter(aggWindow.orderKeys,
        rexFieldCollation ->
          // If ORDER BY references constant (i.e. RexInputRef),
          // then we can ignore such ORDER BY key.
          rexFieldCollation.left instanceof RexLocalRef)));
  ImmutableBitSet groupSet =
    ImmutableBitSet.of(getProjectOrdinals(aggWindow.partitionKeys));
  final int groupLength = groupSet.length();
  if (inputFieldCount < groupLength) {
   // If PARTITION BY references constant, we can ignore such partition key.
   // All the inputs after inputFieldCount are literals, thus we can clear.
   groupSet =
     groupSet.except(ImmutableBitSet.range(inputFieldCount, groupLength));
  }

  WindowKey windowKey =
    new WindowKey(
      groupSet, orderKeys, aggWindow.isRows(),
      aggWindow.getLowerBound(), aggWindow.getUpperBound());
  windowMap.put(windowKey, over);
 }
}

代码示例来源:origin: org.apache.calcite/calcite-core

private static void addWindows(
   Multimap<WindowKey, RexOver> windowMap,
   RexOver over, final int inputFieldCount) {
  final RexWindow aggWindow = over.getWindow();

  // Look up or create a window.
  RelCollation orderKeys = getCollation(
    Lists.newArrayList(
      Util.filter(aggWindow.orderKeys,
        rexFieldCollation ->
          // If ORDER BY references constant (i.e. RexInputRef),
          // then we can ignore such ORDER BY key.
          rexFieldCollation.left instanceof RexLocalRef)));
  ImmutableBitSet groupSet =
    ImmutableBitSet.of(getProjectOrdinals(aggWindow.partitionKeys));
  final int groupLength = groupSet.length();
  if (inputFieldCount < groupLength) {
   // If PARTITION BY references constant, we can ignore such partition key.
   // All the inputs after inputFieldCount are literals, thus we can clear.
   groupSet =
     groupSet.except(ImmutableBitSet.range(inputFieldCount, groupLength));
  }

  WindowKey windowKey =
    new WindowKey(
      groupSet, orderKeys, aggWindow.isRows(),
      aggWindow.getLowerBound(), aggWindow.getUpperBound());
  windowMap.put(windowKey, over);
 }
}

相关文章