<T2 extends T> Ordering<Entry<T2, ?>> onKeys() { return onResultOf(Maps.<T2>keyFunction()); }
private static List<Artifact> sortedArtifacts(List<Artifact> artifacts) { List<Artifact> list = new ArrayList<>(artifacts); Collections.sort(list, Ordering.natural().nullsLast().onResultOf(Artifact::getFile)); return list; } }
public AllAtOnceExecutionSchedule(Collection<SqlStageExecution> stages) { requireNonNull(stages, "stages is null"); List<PlanFragmentId> preferredScheduleOrder = getPreferredScheduleOrder(stages.stream() .map(SqlStageExecution::getFragment) .collect(toImmutableList())); Ordering<SqlStageExecution> ordering = Ordering.explicit(preferredScheduleOrder) .onResultOf(PlanFragment::getId) .onResultOf(SqlStageExecution::getFragment); schedulingStages = new LinkedHashSet<>(ordering.sortedCopy(stages)); }
<T2 extends T> Ordering<Entry<T2, ?>> onKeys() { return onResultOf(Maps.<T2>keyFunction()); }
entries, 0, size, Ordering.from(valueComparator).onResultOf(Maps.<V>valueFunction()));
ImmutableMap<Service, Long> startupTimes() { List<Entry<Service, Long>> loadTimes; monitor.enter(); try { loadTimes = Lists.newArrayListWithCapacity(startupTimers.size()); // N.B. There will only be an entry in the map if the service has started for (Entry<Service, Stopwatch> entry : startupTimers.entrySet()) { Service service = entry.getKey(); Stopwatch stopWatch = entry.getValue(); if (!stopWatch.isRunning() && !(service instanceof NoOpService)) { loadTimes.add(Maps.immutableEntry(service, stopWatch.elapsed(MILLISECONDS))); } } } finally { monitor.leave(); } Collections.sort( loadTimes, Ordering.natural() .onResultOf( new Function<Entry<Service, Long>, Long>() { @Override public Long apply(Entry<Service, Long> input) { return input.getValue(); } })); return ImmutableMap.copyOf(loadTimes); }
@VisibleForTesting JoinEnumerator(CostComparator costComparator, Expression filter, Context context) { this.context = requireNonNull(context); this.session = requireNonNull(context.getSession(), "session is null"); this.costProvider = requireNonNull(context.getCostProvider(), "costProvider is null"); this.resultComparator = costComparator.forSession(session).onResultOf(result -> result.cost); this.idAllocator = requireNonNull(context.getIdAllocator(), "idAllocator is null"); this.allFilter = requireNonNull(filter, "filter is null"); this.allFilterInference = createEqualityInference(filter); this.lookup = requireNonNull(context.getLookup(), "lookup is null"); }
private static Ordering<String> byCharAt(int index) { return Ordering.natural().onResultOf(CharAtFunction.values()[index]); }
0, size, Ordering.from(valueComparator).onResultOf(Maps.<V>valueFunction()));
private static Ordering<ComponentDto> levelMetricOrdering(boolean isAscending, @Nullable MetricDto metric, Table<String, MetricDto, ComponentTreeData.Measure> measuresByComponentUuidAndMetric) { Ordering<Integer> ordering = Ordering.natural(); // inverse the order of org.sonar.api.measures.Metric.Level if (isAscending) { ordering = ordering.reverse(); } return ordering.nullsLast().onResultOf(new ComponentDtoToLevelIndex(metric, measuresByComponentUuidAndMetric)); }
@Override <T> Scenario<?> mutate(final Scenario<T> scenario) { Ordering<Integer> ordering = scenario.ordering.onResultOf( new Function<Integer, T>() { @Override public T apply(@Nullable Integer from) { return scenario.strictlyOrderedList.get(from); } }); List<Integer> list = Lists.newArrayList(); for (int i = 0; i < scenario.strictlyOrderedList.size(); i++) { list.add(i); } return new Scenario<>(ordering, list, new Integer[0]); } },
private PlanNode getCostBasedJoin(JoinNode joinNode, Context context) { List<PlanNodeWithCost> possibleJoinNodes = new ArrayList<>(); addJoinsWithDifferentDistributions(joinNode, possibleJoinNodes, context); addJoinsWithDifferentDistributions(joinNode.flipChildren(), possibleJoinNodes, context); if (possibleJoinNodes.stream().anyMatch(result -> result.getCost().hasUnknownComponents()) || possibleJoinNodes.isEmpty()) { return getSyntacticOrderJoin(joinNode, context, AUTOMATIC); } // Using Ordering to facilitate rule determinism Ordering<PlanNodeWithCost> planNodeOrderings = costComparator.forSession(context.getSession()).onResultOf(PlanNodeWithCost::getCost); return planNodeOrderings.min(possibleJoinNodes).getPlanNode(); }
public void testOnResultOf_natural() { Comparator<String> comparator = Ordering.natural().onResultOf(StringLengthFunction.StringLength); assertTrue(comparator.compare("to", "be") == 0); assertTrue(comparator.compare("or", "not") < 0); assertTrue(comparator.compare("that", "to") > 0); new EqualsTester() .addEqualityGroup( comparator, Ordering.natural().onResultOf(StringLengthFunction.StringLength)) .addEqualityGroup(DECREASING_INTEGER) .testEquals(); reserializeAndAssert(comparator); assertEquals("Ordering.natural().onResultOf(StringLength)", comparator.toString()); }
@SuppressWarnings("unchecked") // raw array @Override <T> Scenario<?> mutate(Scenario<T> scenario) { List<Composite<T>> composites = Lists.newArrayList(); for (T t : scenario.strictlyOrderedList) { composites.add(new Composite<T>(t, 1)); } for (T t : scenario.strictlyOrderedList) { composites.add(new Composite<T>(t, 2)); } Ordering<Composite<T>> ordering = Ordering.natural() .compound(scenario.ordering.onResultOf(Composite.<T>getValueFunction())); return new Scenario<Composite<T>>(ordering, composites, new Composite[0]); } },
@SuppressWarnings("unchecked") // raw array @Override <T> Scenario<?> mutate(Scenario<T> scenario) { List<Composite<T>> composites = Lists.newArrayList(); for (T t : scenario.strictlyOrderedList) { composites.add(new Composite<T>(t, 1)); composites.add(new Composite<T>(t, 2)); } Ordering<Composite<T>> ordering = scenario .ordering .onResultOf(Composite.<T>getValueFunction()) .compound(Ordering.natural()); return new Scenario<Composite<T>>(ordering, composites, new Composite[0]); } },
public void testOnResultOf_chained() { Comparator<String> comparator = DECREASING_INTEGER.onResultOf(StringLengthFunction.StringLength); assertTrue(comparator.compare("to", "be") == 0); assertTrue(comparator.compare("not", "or") < 0); assertTrue(comparator.compare("to", "that") > 0); new EqualsTester() .addEqualityGroup( comparator, DECREASING_INTEGER.onResultOf(StringLengthFunction.StringLength)) .addEqualityGroup(DECREASING_INTEGER.onResultOf(Functions.constant(1))) .addEqualityGroup(Ordering.natural()) .testEquals(); reserializeAndAssert(comparator); assertEquals("Ordering.natural().reverse().onResultOf(StringLength)", comparator.toString()); }
private PlanNode getCostBasedDistributionType(SemiJoinNode node, Context context) { if (!canReplicate(node, context)) { return node.withDistributionType(PARTITIONED); } List<PlanNodeWithCost> possibleJoinNodes = new ArrayList<>(); possibleJoinNodes.add(getSemiJoinNodeWithCost(node.withDistributionType(REPLICATED), context)); possibleJoinNodes.add(getSemiJoinNodeWithCost(node.withDistributionType(PARTITIONED), context)); if (possibleJoinNodes.stream().anyMatch(result -> result.getCost().hasUnknownComponents())) { return node.withDistributionType(PARTITIONED); } // Using Ordering to facilitate rule determinism Ordering<PlanNodeWithCost> planNodeOrderings = costComparator.forSession(context.getSession()).onResultOf(PlanNodeWithCost::getCost); return planNodeOrderings.min(possibleJoinNodes).getPlanNode(); }
public void testCreation_arrayOfArray() { Comparator<String[]> comparator = Ordering.natural() .lexicographical() .onResultOf( new Function<String[], Iterable<Comparable>>() { @Override public Iterable<Comparable> apply(String[] input) { return Arrays.<Comparable>asList(input); } }); String[] array = new String[] {"a"}; Multiset<String[]> multiset = ImmutableSortedMultiset.orderedBy(comparator).add(array).build(); Multiset<String[]> expected = HashMultiset.create(); expected.add(array); assertEquals(expected, multiset); }
public void testBulkGetReturnsSorted() { for (Striped<?> striped : allImplementations()) { Map<Object, Integer> indexByLock = Maps.newHashMap(); for (int i = 0; i < striped.size(); i++) { indexByLock.put(striped.getAt(i), i); } // ensure that bulkGet returns locks in monotonically increasing order for (int objectsNum = 1; objectsNum <= striped.size() * 2; objectsNum++) { Set<Object> objects = Sets.newHashSetWithExpectedSize(objectsNum); for (int i = 0; i < objectsNum; i++) { objects.add(new Object()); } Iterable<?> locks = striped.bulkGet(objects); assertTrue(Ordering.natural().onResultOf(Functions.forMap(indexByLock)).isOrdered(locks)); // check idempotency Iterable<?> locks2 = striped.bulkGet(objects); assertEquals(Lists.newArrayList(locks), Lists.newArrayList(locks2)); } } }
private List<GroupDto> findGroups(DbSession dbSession, PermissionQuery dbQuery, PermissionTemplateDto template) { List<String> orderedNames = dbClient.permissionTemplateDao().selectGroupNamesByQueryAndTemplate(dbSession, dbQuery, template.getId()); List<GroupDto> groups = dbClient.groupDao().selectByNames(dbSession, template.getOrganizationUuid(), orderedNames); if (orderedNames.contains(DefaultGroups.ANYONE)) { groups.add(0, new GroupDto().setId(0).setName(DefaultGroups.ANYONE)); } return Ordering.explicit(orderedNames).onResultOf(GroupDto::getName).immutableSortedCopy(groups); }