本文整理了Java中java.util.Comparator.comparing()
方法的一些代码示例,展示了Comparator.comparing()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Comparator.comparing()
方法的具体详情如下:
包路径:java.util.Comparator
类名称:Comparator
方法名:comparing
暂无
代码示例来源:origin: apache/incubator-druid
@VisibleForTesting
static void sortByInsertionTime(List<RemoteTaskRunnerWorkItem> tasks)
{
Collections.sort(tasks, Comparator.comparing(RemoteTaskRunnerWorkItem::getQueueInsertionTime));
}
代码示例来源:origin: neo4j/neo4j
public void forEach( BiConsumer<String,URI> consumer )
{
entries.stream().collect( Collectors.groupingBy( e -> e.key ) )
.forEach( ( key, list ) -> list.stream()
.max( Comparator.comparing( e -> e.precedence ) )
.ifPresent( e -> consumer.accept( key, e.uri ) ) );
}
代码示例来源:origin: org.apache.ant/ant
@Override
public Enumeration<Object> keys() {
return keyList.stream()
.sorted(Comparator.comparing(Object::toString))
.collect(Collectors.collectingAndThen(Collectors.toList(),
Collections::enumeration));
}
代码示例来源:origin: neo4j/neo4j
@Override
public String toString()
{
return params.entrySet().stream()
.sorted( Comparator.comparing( Map.Entry::getKey ) )
.map( entry -> entry.getKey() + "=" + obsfucateIfSecret( entry ) )
.collect( Collectors.joining( ", ") );
}
}
代码示例来源:origin: SonarSource/sonarqube
@Override
public boolean matches(Issue issue) {
DefaultIssue defaultIssue = (DefaultIssue) issue;
Optional<String> lastPreviousStatus = defaultIssue.changes().stream()
// exclude current change (if any)
.filter(change -> change != defaultIssue.currentChange())
.filter(change -> change.creationDate() != null)
.sorted(Comparator.comparing(FieldDiffs::creationDate).reversed())
.map(change -> change.get("status"))
.filter(Objects::nonNull)
.findFirst()
.map(t -> (String) t.oldValue());
return lastPreviousStatus.filter(this.expectedPreviousStatus::equals).isPresent();
}
}
代码示例来源:origin: Graylog2/graylog2-server
/**
* Assigns the minimum TTL found in the supplied DnsAnswers. The minimum makes sense, because this is the least
* amount of time that at least one of the records is valid for.
*/
private void assignMinimumTTL(List<? extends DnsAnswer> dnsAnswers, LookupResult.Builder builder) {
if (config.hasOverrideTTL()) {
builder.cacheTTL(config.getCacheTTLOverrideMillis());
} else {
// Deduce minimum TTL on all TXT records. A TTL will always be returned by DNS server.
builder.cacheTTL(dnsAnswers.stream()
.map(DnsAnswer::dnsTTL)
.min(Comparator.comparing(Long::valueOf)).get() * 1000);
}
}
代码示例来源:origin: neo4j/neo4j
private void printCommands( Consumer<String> output )
{
Map<AdminCommandSection,List<AdminCommand.Provider>> groupedProviders = groupProvidersBySection();
AdminCommandSection.general()
.printAllCommandsUnderSection( output, groupedProviders.remove( AdminCommandSection.general() ) );
groupedProviders.entrySet().stream()
.sorted( Comparator.comparing( groupedProvider -> groupedProvider.getKey().printable() ) )
.forEach(entry -> entry.getKey().printAllCommandsUnderSection( output, entry.getValue() ) );
}
代码示例来源:origin: hs-web/hsweb-framework
private static Map<String, ClassProperty> createProperty(Class type) {
List<String> fieldNames = Arrays.stream(type.getDeclaredFields())
.map(Field::getName).collect(Collectors.toList());
return Stream.of(propertyUtils.getPropertyDescriptors(type))
.filter(property -> !property.getName().equals("class") && property.getReadMethod() != null && property.getWriteMethod() != null)
.map(BeanClassProperty::new)
//让字段有序
.sorted(Comparator.comparing(property -> fieldNames.indexOf(property.name)))
.collect(Collectors.toMap(ClassProperty::getName, Function.identity(), (k, k2) -> k, LinkedHashMap::new));
}
代码示例来源:origin: stackoverflow.com
Comparator<Song> songRatingComparator = Comparator.comparing(Song::getRating);
Collections.sort(songList, songRatingComparator.reversed());
代码示例来源:origin: Netflix/conductor
/**
* Get the details about each queue.
*
* @return map of details about each queue.
*/
public Map<String, Long> getAllQueueDetails() {
return queueDAO.queuesDetail().entrySet().stream()
.sorted(Comparator.comparing(Entry::getKey))
.collect(Collectors.toMap(Entry::getKey, Entry::getValue, (v1, v2) -> v1, LinkedHashMap::new));
}
代码示例来源:origin: SonarSource/sonarqube
@Override
public void execute(Context context) {
DefaultIssue defaultIssue = (DefaultIssue) context.issue();
String previousResolution = defaultIssue.changes().stream()
// exclude current change (if any)
.filter(change -> change != defaultIssue.currentChange())
.filter(change -> change.creationDate() != null)
.sorted(Comparator.comparing(FieldDiffs::creationDate).reversed())
.map(this::parse)
.filter(Objects::nonNull)
.filter(StatusAndResolutionDiffs::hasResolution)
.findFirst()
.map(t -> t.newStatusClosed ? t.oldResolution : t.newResolution)
.orElse(null);
context.setResolution(previousResolution);
}
代码示例来源:origin: google/error-prone
@Override
public OrganizedImports organizeImports(List<Import> imports) {
// Group into static and non-static. Each group is a set sorted by type.
Map<Boolean, ImmutableSortedSet<Import>> partionedByStatic =
imports.stream()
.collect(
Collectors.partitioningBy(
Import::isStatic, toImmutableSortedSet(Comparator.comparing(Import::getType))));
return new OrganizedImports()
// Add groups, in the appropriate order.
.addGroups(partionedByStatic, order.groupOrder());
}
}
代码示例来源:origin: allure-framework/allure2
private static Optional<ExecutorInfo> extractLatestExecutor(final List<LaunchResults> launches) {
final Comparator<ExecutorInfo> comparator = comparing(ExecutorInfo::getBuildOrder, nullsFirst(naturalOrder()));
return launches.stream()
.map(launch -> launch.getExtra(EXECUTORS_BLOCK_NAME))
.filter(Optional::isPresent)
.map(Optional::get)
.filter(ExecutorInfo.class::isInstance)
.map(ExecutorInfo.class::cast)
.max(comparator);
}
代码示例来源:origin: SonarSource/sonarqube
private void indexModulesRecursively(DefaultInputModule module, ExclusionCounter exclusionCounter) {
inputModuleHierarchy.children(module).stream().sorted(Comparator.comparing(DefaultInputModule::key)).forEach(m -> indexModulesRecursively(m, exclusionCounter));
index(module, exclusionCounter);
}
代码示例来源:origin: shekhargulati/java8-the-missing-tutorial
public List<String> allReadingTasks(List<Task> tasks) {
return tasks.stream().
filter(task -> task.getType() == TaskType.READING).
sorted(comparing(Task::getCreatedOn)).
map(Task::getTitle).
collect(toList());
}
代码示例来源:origin: apache/geode
public static void sortByDistanceAscending(List<GeoRadiusResponseElement> elements) {
Collections.sort(elements, Comparator.comparing(GeoRadiusResponseElement::getDistFromCenter));
}
代码示例来源:origin: speedment/speedment
private String sqlColumnList(Predicate<Column> preFilter, Function<String, String> postMapper) {
return table.columns()
.sorted(comparing(Column::getOrdinalPosition))
.filter(Column::isEnabled)
.filter(preFilter)
.map(Column::getName)
.map(naming::encloseField)
.map(postMapper)
.collect(joining(","));
}
代码示例来源:origin: SonarSource/sonarqube
private UnaryOperator<ListResponse.Builder> addNotifications(DbSession dbSession, UserDto user) {
return response -> {
List<PropertyDto> properties = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setUserId(user.getId()).build(), dbSession);
Map<Long, ComponentDto> componentsById = searchProjects(dbSession, properties);
Map<String, OrganizationDto> organizationsByUuid = getOrganizations(dbSession, componentsById.values());
Predicate<PropertyDto> isNotification = prop -> prop.getKey().startsWith("notification.");
Predicate<PropertyDto> isComponentInDb = prop -> prop.getResourceId() == null || componentsById.containsKey(prop.getResourceId());
Notification.Builder notification = Notification.newBuilder();
properties.stream()
.filter(isNotification)
.filter(channelAndDispatcherAuthorized())
.filter(isComponentInDb)
.map(toWsNotification(notification, organizationsByUuid, componentsById))
.sorted(comparing(Notification::getProject, nullsFirst(naturalOrder()))
.thenComparing(comparing(Notification::getChannel))
.thenComparing(comparing(Notification::getType)))
.forEach(response::addNotifications);
return response;
};
}
代码示例来源:origin: allure-framework/allure2
private static Optional<ExecutorInfo> extractLatestExecutor(final List<LaunchResults> launches) {
final Comparator<ExecutorInfo> comparator = comparing(ExecutorInfo::getBuildOrder, nullsFirst(naturalOrder()));
return launches.stream()
.map(launch -> launch.getExtra(EXECUTORS_BLOCK_NAME))
.filter(Optional::isPresent)
.map(Optional::get)
.filter(ExecutorInfo.class::isInstance)
.map(ExecutorInfo.class::cast)
.max(comparator);
}
代码示例来源:origin: neo4j/neo4j
@Admin
@Description( "List the currently active config of Neo4j." )
@Procedure( name = "dbms.listConfig", mode = DBMS )
public Stream<ConfigResult> listConfig( @Name( value = "searchString", defaultValue = "" ) String searchString )
{
Config config = graph.getDependencyResolver().resolveDependency( Config.class );
String lowerCasedSearchString = searchString.toLowerCase();
return config.getConfigValues().values().stream()
.filter( c -> !c.internal() )
.filter( c -> c.name().toLowerCase().contains( lowerCasedSearchString ) )
.map( ConfigResult::new )
.sorted( Comparator.comparing( c -> c.name ) );
}
内容来源于网络,如有侵权,请联系作者删除!