com.google.common.collect.Ordering#compound ( )源码实例Demo

下面列出了com.google.common.collect.Ordering#compound ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: swellrt   文件: QueryHelper.java
/**
 * Computes ordering for the search results. If none are specified - then
 * returns the default ordering. The resulting ordering is always compounded
 * with ordering by wave id for stability.
 */
public static Ordering<WaveViewData> computeSorter(
    Map<TokenQueryType, Set<String>> queryParams) {
  Ordering<WaveViewData> ordering = null;
  Set<String> orderBySet = queryParams.get(TokenQueryType.ORDERBY);
  if (orderBySet != null) {
    for (String orderBy : orderBySet) {
      QueryHelper.OrderByValueType orderingType =
          QueryHelper.OrderByValueType.fromToken(orderBy);
      if (ordering == null) {
        // Primary ordering.
        ordering = orderingType.getOrdering();
      } else {
        // All other ordering are compounded to the primary one.
        ordering = ordering.compound(orderingType.getOrdering());
      }
    }
  } else {
    ordering = QueryHelper.DEFAULT_ORDERING;
  }
  // For stability order also by wave id.
  ordering = ordering.compound(QueryHelper.ID_COMPARATOR);
  return ordering;
}
 
源代码2 项目: phoenix   文件: OrderedResultIterator.java
/**
 * Builds a comparator from the list of columns in ORDER BY clause.
 * @param orderByExpressions the columns in ORDER BY clause.
 * @return the comparator built from the list of columns in ORDER BY clause.
 */
// ImmutableBytesWritable.Comparator doesn't implement generics
@SuppressWarnings("unchecked")
private static Comparator<ResultEntry> buildComparator(List<OrderByExpression> orderByExpressions) {
    Ordering<ResultEntry> ordering = null;
    int pos = 0;
    for (OrderByExpression col : orderByExpressions) {
        Expression e = col.getExpression();
        Comparator<ImmutableBytesWritable> comparator = 
                e.getSortOrder() == SortOrder.DESC && !e.getDataType().isFixedWidth() 
                ? buildDescVarLengthComparator() 
                : new ImmutableBytesWritable.Comparator();
        Ordering<ImmutableBytesWritable> o = Ordering.from(comparator);
        if(!col.isAscending()) o = o.reverse();
        o = col.isNullsLast() ? o.nullsLast() : o.nullsFirst();
        Ordering<ResultEntry> entryOrdering = o.onResultOf(new NthKey(pos++));
        ordering = ordering == null ? entryOrdering : ordering.compound(entryOrdering);
    }
    return ordering;
}
 
源代码3 项目: incubator-retired-wave   文件: QueryHelper.java
/**
 * Computes ordering for the search results. If none are specified - then
 * returns the default ordering. The resulting ordering is always compounded
 * with ordering by wave id for stability.
 */
public static Ordering<WaveViewData> computeSorter(
    Map<TokenQueryType, Set<String>> queryParams) {
  Ordering<WaveViewData> ordering = null;
  Set<String> orderBySet = queryParams.get(TokenQueryType.ORDERBY);
  if (orderBySet != null) {
    for (String orderBy : orderBySet) {
      QueryHelper.OrderByValueType orderingType =
          QueryHelper.OrderByValueType.fromToken(orderBy);
      if (ordering == null) {
        // Primary ordering.
        ordering = orderingType.getOrdering();
      } else {
        // All other ordering are compounded to the primary one.
        ordering = ordering.compound(orderingType.getOrdering());
      }
    }
  } else {
    ordering = QueryHelper.DEFAULT_ORDERING;
  }
  // For stability order also by wave id.
  ordering = ordering.compound(QueryHelper.ID_COMPARATOR);
  return ordering;
}
 
源代码4 项目: Quicksql   文件: SortNode.java
private Comparator<Row> comparator() {
  if (rel.getCollation().getFieldCollations().size() == 1) {
    return comparator(rel.getCollation().getFieldCollations().get(0));
  }
  return Ordering.compound(
      Iterables.transform(rel.getCollation().getFieldCollations(),
          this::comparator));
}
 
源代码5 项目: Elasticsearch   文件: OrderingByPosition.java
public static Ordering<Object[]> arrayOrdering(int[] position, boolean[] reverse, Boolean[] nullsFirst) {
    if (position.length == 0) {
        return arrayOrdering(position[0], reverse[0], nullsFirst[0]);
    }

    // TODO: if the reverse/nullsFirst flags are the same for all positions this could be optimized
    // to use just one single "inner" Ordering instance that is re-used for all positions
    List<Comparator<Object[]>> comparators = new ArrayList<>(position.length);
    for (int i = 0, positionLength = position.length; i < positionLength; i++) {
        comparators.add(arrayOrdering(position[i], reverse[i], nullsFirst[i]));
    }
    return Ordering.compound(comparators);
}
 
源代码6 项目: phoenix   文件: OrderedResultIterator.java
/**
 * Builds a comparator from the list of columns in ORDER BY clause.
 * @param orderByExpressions the columns in ORDER BY clause.
 * @return the comparator built from the list of columns in ORDER BY clause.
 */
// ImmutableBytesWritable.Comparator doesn't implement generics
@SuppressWarnings("unchecked")
private static Comparator<ResultEntry> buildComparator(List<OrderByExpression> orderByExpressions) {
    Ordering<ResultEntry> ordering = null;
    int pos = 0;
    for (OrderByExpression col : orderByExpressions) {
        Ordering<ImmutableBytesWritable> o = Ordering.from(new ImmutableBytesWritable.Comparator());
        if(!col.isAscending()) o = o.reverse();
        o = col.isNullsLast() ? o.nullsLast() : o.nullsFirst();
        Ordering<ResultEntry> entryOrdering = o.onResultOf(new NthKey(pos++));
        ordering = ordering == null ? entryOrdering : ordering.compound(entryOrdering);
    }
    return ordering;
}
 
源代码7 项目: calcite   文件: EnumerableValues.java
@Override public RelNode passThrough(final RelTraitSet required) {
  RelCollation collation = required.getCollation();
  if (collation == null || collation.isDefault()) {
    return null;
  }

  // A Values with 0 or 1 rows can be ordered by any collation.
  if (tuples.size() > 1) {
    Ordering<List<RexLiteral>> ordering = null;
    // Generate ordering comparator according to the required collations.
    for (RelFieldCollation fc : collation.getFieldCollations()) {
      Ordering<List<RexLiteral>> comparator = RelMdCollation.comparator(fc);
      if (ordering == null) {
        ordering = comparator;
      } else {
        ordering = ordering.compound(comparator);
      }
    }
    // Check whether the tuples are sorted by required collations.
    if (!ordering.isOrdered(tuples)) {
      return null;
    }
  }

  // The tuples order satisfies the collation, we just create a new
  // relnode with required collation info.
  return copy(traitSet.replace(collation), ImmutableList.of());
}
 
源代码8 项目: calcite   文件: SortNode.java
private Comparator<Row> comparator() {
  if (rel.getCollation().getFieldCollations().size() == 1) {
    return comparator(rel.getCollation().getFieldCollations().get(0));
  }
  return Ordering.compound(
      Iterables.transform(rel.getCollation().getFieldCollations(),
          this::comparator));
}
 
源代码9 项目: phoenix   文件: OrderedResultIterator.java
/**
 * Builds a comparator from the list of columns in ORDER BY clause.
 * @param orderByExpressions the columns in ORDER BY clause.
 * @return the comparator built from the list of columns in ORDER BY clause.
 */
// ImmutableBytesWritable.Comparator doesn't implement generics
@SuppressWarnings("unchecked")
private static Comparator<ResultEntry> buildComparator(List<OrderByExpression> orderByExpressions) {
    Ordering<ResultEntry> ordering = null;
    int pos = 0;
    for (OrderByExpression col : orderByExpressions) {
        Ordering<ImmutableBytesWritable> o = Ordering.from(new ImmutableBytesWritable.Comparator());
        if(!col.isAscending()) o = o.reverse();
        o = col.isNullsLast() ? o.nullsLast() : o.nullsFirst();
        Ordering<ResultEntry> entryOrdering = o.onResultOf(new NthKey(pos++));
        ordering = ordering == null ? entryOrdering : ordering.compound(entryOrdering);
    }
    return ordering;
}
 
源代码10 项目: attic-aurora   文件: OfferOrderBuilder.java
private static Ordering<HostOffer> getOrdering(Ordering<HostOffer> base, OfferOrder order) {
  // Random is Ordering<Object> so accepting base as a parameter and compounding in here is the
  // cleanest way I could come up with to avoid a whole bunch of type finagling.
  switch(order) {
    case CPU: return base.compound(CPU_COMPARATOR);
    case DISK: return base.compound(DISK_COMPARATOR);
    case MEMORY: return base.compound(RAM_COMPARATOR);
    case REVOCABLE_CPU: return base.compound(REVOCABLE_CPU_COMPARATOR);
    default: return base.compound(RANDOM_COMPARATOR);
  }
}
 
源代码11 项目: crate   文件: Comparators.java
private static <T extends CollectExpression<Row, ?>> Comparator<Object[]> createComparatorWithEval(
    Supplier<InputFactory.Context<T>> createInputFactoryCtx,
    OrderBy orderBy) {

    var orderBySymbols = orderBy.orderBySymbols();
    ArrayList<Comparator<Object[]>> comparators = new ArrayList<>(orderBySymbols.size());
    for (int i = 0; i < orderBySymbols.size(); i++) {
        var orderSymbol = orderBySymbols.get(i);
        var ctx = createInputFactoryCtx.get();
        var input = (Input<Object>) ctx.add(orderSymbol);
        var expressionsInput = new ExpressionsInput<>(input, ctx.expressions());
        var row = new ArrayRow();
        comparators.add(new NullAwareComparator<>(
            cells -> {
                Comparable<Object> value;
                synchronized (row) {
                    row.cells(cells);
                    value = (Comparable<Object>) expressionsInput.value(row);
                }
                return value;
            },
            orderBy.reverseFlags()[i],
            orderBy.nullsFirst()[i]
        ));
    }
    return Ordering.compound(comparators);
}
 
源代码12 项目: crate   文件: OrderingByPosition.java
public static Comparator<Object[]> arrayOrdering(int[] position, boolean[] reverse, boolean[] nullsFirst) {
    if (position.length == 1) {
        return arrayOrdering(position[0], reverse[0], nullsFirst[0]);
    }
    List<Comparator<Object[]>> comparators = new ArrayList<>(position.length);
    for (int i = 0, positionLength = position.length; i < positionLength; i++) {
        comparators.add(arrayOrdering(position[i], reverse[i], nullsFirst[i]));
    }
    return Ordering.compound(comparators);
}
 
源代码13 项目: crate   文件: OrderingByPositionTest.java
@Test
public void testMultipleOrderBy() throws Exception {
    Comparator<Object[]> ordering = Ordering.compound(Arrays.asList(
        OrderingByPosition.arrayOrdering(1, false, false),
        OrderingByPosition.arrayOrdering(0, false, false)
    ));

    assertThat(ordering.compare(new Object[]{0, 0}, new Object[]{4, 0}), is(-1));
    assertThat(ordering.compare(new Object[]{4, 0}, new Object[]{1, 1}), is(-1));
    assertThat(ordering.compare(new Object[]{5, 1}, new Object[]{2, 2}), is(-1));
    assertThat(ordering.compare(new Object[]{5, 1}, new Object[]{2, 2}), is(-1));
}
 
源代码14 项目: core   文件: Assignments.java
public static Ordering<Assignment> orderedByPrincipal() {
    Ordering<Assignment> byType = new Ordering<Assignment>() {
        @Override
        public int compare(final Assignment left, final Assignment right) {
            return left.getPrincipal().getType().compareTo(right.getPrincipal().getType());
        }
    };
    Ordering<Assignment> byName = Ordering.natural().onResultOf(input -> input.getPrincipal().getName());
    return byType.compound(byName);
}
 
源代码15 项目: core   文件: Assignments.java
public static Ordering<Assignment> orderedByRole() {
    Ordering<Assignment> byType = new Ordering<Assignment>() {
        @Override
        public int compare(final Assignment left, final Assignment right) {
            return left.getRole().getType().compareTo(right.getRole().getType());
        }
    };
    Ordering<Assignment> byName = Ordering.natural().onResultOf(input -> input.getRole().getName());
    return byType.compound(byName);
}
 
源代码16 项目: selenium   文件: CapabilitiesComparator.java
public CapabilitiesComparator(final Capabilities desiredCapabilities,
                              final Platform currentPlatform) {
  final CapabilityScorer<String> browserNameScorer =
      new CapabilityScorer<>(desiredCapabilities.getBrowserName());
  Comparator<Capabilities> byBrowserName =
      Comparator.comparingInt(c -> browserNameScorer.score(c.getBrowserName()));

  final CapabilityScorer<String> versionScorer =
      new VersionScorer(desiredCapabilities.getVersion());
  Comparator<Capabilities> byVersion =
      Comparator.comparingInt(c -> versionScorer.score(c.getVersion()));

  final CapabilityScorer<Boolean> jsScorer =
      new CapabilityScorer<>(desiredCapabilities.is(SUPPORTS_JAVASCRIPT));
  Comparator<Capabilities> byJavaScript =
      Comparator.comparingInt(c -> jsScorer.score(c.is(SUPPORTS_JAVASCRIPT)));

  Platform desiredPlatform = desiredCapabilities.getPlatform();
  if (desiredPlatform == null) {
    desiredPlatform = Platform.ANY;
  }

  final CapabilityScorer<Platform> currentPlatformScorer =
      new CurrentPlatformScorer(currentPlatform, desiredPlatform);
  Comparator<Capabilities> byCurrentPlatform =
      Comparator.comparingInt(c -> currentPlatformScorer.score(c.getPlatform()));

  final CapabilityScorer<Platform> strictPlatformScorer =
      new CapabilityScorer<>(desiredPlatform);
  Comparator<Capabilities> byStrictPlatform =
      Comparator.comparingInt(c -> strictPlatformScorer.score(c.getPlatform()));

  final CapabilityScorer<Platform> fuzzyPlatformScorer =
      new FuzzyPlatformScorer(desiredPlatform);
  Comparator<Capabilities> byFuzzyPlatform =
      Comparator.comparingInt(c -> fuzzyPlatformScorer.score(c.getPlatform()));

  compareWith = Ordering.compound(Arrays.asList(
      byBrowserName,
      byVersion,
      byJavaScript,
      byCurrentPlatform,
      byStrictPlatform,
      byFuzzyPlatform));
}
 
源代码17 项目: OpenModsLib   文件: StackComparatorBuilder.java
public Ordering<ItemStack> build() {
	return Ordering.compound(result);
}