private static <K, V> ImmutableList<K> sortKeysByValue( final Map<K, V> map, final Comparator<? super V> valueComparator) { Ordering<K> keyOrdering = new Ordering<K>() { @Override public int compare(K left, K right) { return valueComparator.compare(map.get(left), map.get(right)); } }; return keyOrdering.immutableSortedCopy(map.keySet()); }
private static <K, V> ImmutableList<K> sortKeysByValue( final Map<K, V> map, final Comparator<? super V> valueComparator) { Ordering<K> keyOrdering = new Ordering<K>() { @Override public int compare(K left, K right) { return valueComparator.compare(map.get(left), map.get(right)); } }; return keyOrdering.immutableSortedCopy(map.keySet()); }
/** * Returns an {@code ImmutableList} containing all of the elements from this {@code * FluentIterable} in the order specified by {@code comparator}. To produce an {@code * ImmutableList} sorted by its natural ordering, use {@code toSortedList(Ordering.natural())}. * * <p><b>{@code Stream} equivalent:</b> pass {@link ImmutableList#toImmutableList} to {@code * stream.sorted(comparator).collect()}. * * @param comparator the function by which to sort list elements * @throws NullPointerException if any element of this iterable is {@code null} * @since 14.0 (since 13.0 as {@code toSortedImmutableList()}). */ public final ImmutableList<E> toSortedList(Comparator<? super E> comparator) { return Ordering.from(comparator).immutableSortedCopy(getDelegate()); }
@Nonnull @Override public Collection<? extends PoolClassDef> getSortedClasses() { if (sortedClasses == null) { sortedClasses = Ordering.natural().immutableSortedCopy(internedItems.values()); } return sortedClasses; }
/** Returns a newly-created immutable multimap. */ public ImmutableMultimap<K, V> build() { Collection<Map.Entry<K, Collection<V>>> mapEntries = builderMap.entrySet(); if (keyComparator != null) { mapEntries = Ordering.from(keyComparator).<K>onKeys().immutableSortedCopy(mapEntries); } return ImmutableListMultimap.fromMapEntries(mapEntries, valueComparator); } }
/** Returns a newly-created immutable set multimap. */ @Override public ImmutableSetMultimap<K, V> build() { Collection<Map.Entry<K, Collection<V>>> mapEntries = builderMap.entrySet(); if (keyComparator != null) { mapEntries = Ordering.from(keyComparator).<K>onKeys().immutableSortedCopy(mapEntries); } return fromMapEntries(mapEntries, valueComparator); } }
void testSortedCopy() { List<T> shuffledList = Lists.newArrayList(strictlyOrderedList); shuffledList = shuffledCopy(shuffledList, new Random(5)); assertEquals(strictlyOrderedList, ordering.sortedCopy(shuffledList)); if (!strictlyOrderedList.contains(null)) { assertEquals(strictlyOrderedList, ordering.immutableSortedCopy(shuffledList)); } } }
/** Returns a newly-created immutable multimap. */ public ImmutableMultimap<K, V> build() { Collection<Map.Entry<K, Collection<V>>> mapEntries = builderMap.entrySet(); if (keyComparator != null) { mapEntries = Ordering.from(keyComparator).<K>onKeys().immutableSortedCopy(mapEntries); } return ImmutableListMultimap.fromMapEntries(mapEntries, valueComparator); } }
/** Returns a newly-created immutable set multimap. */ @Override public ImmutableSetMultimap<K, V> build() { Collection<Map.Entry<K, Collection<V>>> mapEntries = builderMap.entrySet(); if (keyComparator != null) { mapEntries = Ordering.from(keyComparator).<K>onKeys().immutableSortedCopy(mapEntries); } return fromMapEntries(mapEntries, valueComparator); } }
private void sortProcessorChain() { final MessageProcessorsConfig config = clusterConfigService.get(MessageProcessorsConfig.class); if (config != null) { // if we have an explicit ordering use that (unknown last, partial ordering over the given list) classNameOrdering = new LenientExplicitOrdering<>(config.processorOrder()); } final ImmutableList<MessageProcessor> sortedCopy = classNameOrdering.onResultOf(mp -> mp.getClass().getCanonicalName()).immutableSortedCopy(processors); final Collection<MessageProcessor> enabledMessageProcessors = Collections2.filter(sortedCopy, mp -> config == null || !config.disabledProcessors().contains(mp.getClass().getCanonicalName())); LOG.debug("New active message processors: {}", enabledMessageProcessors); sortedProcessors.set(ImmutableList.copyOf(enabledMessageProcessors)); }
public void testImmutableSortedCopy() { ImmutableList<Integer> unsortedInts = ImmutableList.of(5, 3, 0, 9, 3); ImmutableList<Integer> sortedInts = numberOrdering.immutableSortedCopy(unsortedInts); assertEquals(Arrays.asList(0, 3, 3, 5, 9), sortedInts); assertEquals( Collections.<Integer>emptyList(), numberOrdering.immutableSortedCopy(Collections.<Integer>emptyList())); List<Integer> listWithNull = Arrays.asList(5, 3, null, 9); try { Ordering.natural().nullsFirst().immutableSortedCopy(listWithNull); fail(); } catch (NullPointerException expected) { } }
Schema(Iterable<ProtoFile> protoFiles) { this.protoFiles = PATH_ORDER.immutableSortedCopy(protoFiles); this.typesIndex = buildTypesIndex(protoFiles); this.servicesIndex = buildServicesIndex(protoFiles); }
.compound(BY_METHOD_NAME) .compound(BY_PARAMETERS) .immutableSortedCopy(factories);
@Override public Iterable<? extends Character> successors(Character node) { checkArgument( graphMap.containsKey(node) || graphMap.containsValue(node), "Node %s is not an element of this graph", node); return Ordering.natural().immutableSortedCopy(graphMap.get(node)); } };
default List<IssueDto> sort(Collection<IssueDto> issueDtos, boolean ascending) { Ordering<IssueDto> ordering = sortFieldOrdering(ascending).onResultOf(sortFieldFunction()); return ordering.immutableSortedCopy(issueDtos); } }
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); }
public void testAllEqual() { Ordering<Object> comparator = Ordering.allEqual(); assertSame(comparator, comparator.reverse()); assertEquals(0, comparator.compare(null, null)); assertEquals(0, comparator.compare(new Object(), new Object())); assertEquals(0, comparator.compare("apples", "oranges")); assertSame(comparator, reserialize(comparator)); assertEquals("Ordering.allEqual()", comparator.toString()); List<String> strings = ImmutableList.of("b", "a", "d", "c"); assertEquals(strings, comparator.sortedCopy(strings)); assertEquals(strings, comparator.immutableSortedCopy(strings)); }
private List<UserDto> findUsers(DbSession dbSession, PermissionQuery query) { List<Integer> orderedIds = dbClient.userPermissionDao().selectUserIdsByQuery(dbSession, query); return Ordering.explicit(orderedIds).onResultOf(UserDto::getId).immutableSortedCopy(dbClient.userDao().selectByIds(dbSession, orderedIds)); }
private List<GroupDto> findGroups(DbSession dbSession, OrganizationDto org, PermissionQuery dbQuery) { List<String> orderedNames = dbClient.groupPermissionDao().selectGroupNamesByQuery(dbSession, dbQuery); List<GroupDto> groups = dbClient.groupDao().selectByNames(dbSession, org.getUuid(), orderedNames); if (orderedNames.contains(DefaultGroups.ANYONE)) { groups.add(0, new GroupDto().setId(0).setName(DefaultGroups.ANYONE).setOrganizationUuid(org.getUuid())); } return Ordering.explicit(orderedNames).onResultOf(GroupDto::getName).immutableSortedCopy(groups); }
private List<UserDto> findUsers(DbSession dbSession, PermissionQuery query, PermissionTemplateDto template) { List<String> orderedLogins = dbClient.permissionTemplateDao().selectUserLoginsByQueryAndTemplate(dbSession, query, template.getId()); return Ordering.explicit(orderedLogins).onResultOf(UserDto::getLogin).immutableSortedCopy(dbClient.userDao().selectByLogins(dbSession, orderedLogins)); }