本文整理了Java中java.util.stream.Collectors.maxBy()
方法的一些代码示例,展示了Collectors.maxBy()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Collectors.maxBy()
方法的具体详情如下:
包路径:java.util.stream.Collectors
类名称:Collectors
方法名:maxBy
暂无
代码示例来源:origin: RichardWarburton/java-8-lambdas-exercises
public static Artist byCollecting(List<Artist> artists) {
return artists.stream()
.collect(Collectors.maxBy(byNameLength))
.orElseThrow(RuntimeException::new);
}
代码示例来源:origin: RichardWarburton/java-8-lambdas-exercises
public Optional<Artist> biggestGroup(Stream<Artist> artists) {
Function<Artist,Long> getCount = artist -> artist.getMembers().count();
return artists.collect(maxBy(comparing(getCount)));
}
// END BIGGEST_GROUP
代码示例来源:origin: goldmansachs/gs-collections
@Benchmark
public Position maxByMarketValue_serial_lazy_collect_lambda_jdk()
{
return this.positions.getJdkPositions().stream().collect(
Collectors.maxBy(MARKET_VALUE_COMPARATOR_LAMBDA)).get();
}
代码示例来源:origin: goldmansachs/gs-collections
@Benchmark
public Position maxByQuantity_serial_lazy_collect_lambda_jdk()
{
return this.positions.getJdkPositions().stream().collect(
Collectors.maxBy(QUANTITY_COMPARATOR_LAMBDA)).get();
}
代码示例来源:origin: goldmansachs/gs-collections
@Benchmark
public Position maxByQuantity_serial_lazy_collect_methodref_jdk()
{
return this.positions.getJdkPositions().stream().collect(
Collectors.maxBy(QUANTITY_COMPARATOR_METHODREF)).get();
}
代码示例来源:origin: goldmansachs/gs-collections
@Benchmark
public Position maxByMarketValue_serial_lazy_collect_methodref_jdk()
{
return this.positions.getJdkPositions().stream().collect(
Collectors.maxBy(MARKET_VALUE_COMPARATOR_METHODREF)).get();
}
代码示例来源:origin: Netflix/conductor
/**
* Get all failed and cancelled tasks.
* for failed tasks - get one for each task reference name(latest failed using seq id)
*
* @param workflow
* @return list of latest failed tasks, one for each task reference reference type.
*/
@VisibleForTesting
List<Task> getFailedTasksToRetry(Workflow workflow) {
return workflow.getTasks().stream()
.filter(x -> FAILED.equals(x.getStatus()))
.collect(groupingBy(Task::getReferenceTaskName, maxBy(comparingInt(Task::getSeq))))
.values().stream()
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toList());
}
代码示例来源:origin: goldmansachs/gs-collections
@Benchmark
public Position maxByQuantity_parallel_lazy_collect_lambda_jdk()
{
return this.positions.getJdkPositions().parallelStream().collect(
Collectors.maxBy(QUANTITY_COMPARATOR_LAMBDA)).get();
}
代码示例来源:origin: goldmansachs/gs-collections
@Benchmark
public Position maxByQuantity_parallel_lazy_collect_methodref_jdk()
{
return this.positions.getJdkPositions().parallelStream().collect(
Collectors.maxBy(QUANTITY_COMPARATOR_METHODREF)).get();
}
代码示例来源:origin: goldmansachs/gs-collections
@Benchmark
public Position maxByMarketValue_parallel_lazy_collect_methodref_jdk()
{
return this.positions.getJdkPositions().parallelStream().collect(
Collectors.maxBy(MARKET_VALUE_COMPARATOR_METHODREF)).get();
}
代码示例来源:origin: goldmansachs/gs-collections
@Benchmark
public Position maxByMarketValue_parallel_lazy_collect_lambda_jdk()
{
return this.positions.getJdkPositions().parallelStream().collect(
Collectors.maxBy(MARKET_VALUE_COMPARATOR_LAMBDA)).get();
}
代码示例来源:origin: Graylog2/graylog2-server
@GET
@RequiresPermissions(RestPermissions.USERS_LIST)
@ApiOperation(value = "List all users", notes = "The permissions assigned to the users are always included.")
public UserList listUsers() {
final List<User> users = userService.loadAll();
final Collection<MongoDbSession> sessions = sessionService.loadAll();
// among all active sessions, find the last recently used for each user
//noinspection OptionalGetWithoutIsPresent
final Map<String, Optional<MongoDbSession>> lastSessionForUser = sessions.stream()
.filter(s -> s.getUsernameAttribute().isPresent())
.collect(groupingBy(s -> s.getUsernameAttribute().get(),
maxBy(Comparator.comparing(MongoDbSession::getLastAccessTime))));
final List<UserSummary> resultUsers = Lists.newArrayListWithCapacity(users.size() + 1);
final User adminUser = userService.getAdminUser();
resultUsers.add(toUserResponse(adminUser, lastSessionForUser.getOrDefault(adminUser.getName(), Optional.empty())));
for (User user : users) {
resultUsers.add(toUserResponse(user, lastSessionForUser.getOrDefault(user.getName(), Optional.empty())));
}
return UserList.create(resultUsers);
}
代码示例来源:origin: aol/cyclops
public final static <T> Optional<T> max(final Stream<T> stream, final Comparator<? super T> comparator) {
return stream.collect(java.util.stream.Collectors.maxBy(comparator));
}
代码示例来源:origin: biezhi/learn-java8
public static void main(String[] args) {
List<Project> projects = Project.buildData();
Collection<Project> collect = projects.stream()
.collect(toCollection(CopyOnWriteArrayList::new));
System.out.println(collect);
Map<String, Project> collect1 = projects.stream()
.collect(groupingBy(Project::getAuthor, collectingAndThen(
maxBy(Comparator.comparingInt(Project::getStars)),
Optional::get
)));
System.out.println(collect1);
}
}
代码示例来源:origin: senbox-org/s2tbx
public ImageMetadata getMaxResolutionImage() {
return componentMetadata.stream()
.filter(metadata -> metadata instanceof ImageMetadata)
.map(metadata -> (ImageMetadata) metadata)
.collect(Collectors.maxBy(Comparator.comparingInt(ImageMetadata::getRasterWidth)))
.get();
}
代码示例来源:origin: senbox-org/s2tbx
public int getSceneHeight() {
return componentMetadata.stream()
.filter(metadata -> metadata instanceof ImageMetadata)
.map(metadata -> (ImageMetadata) metadata)
.map(ImageMetadata::getRasterHeight)
.collect(Collectors.maxBy(Integer::compare))
.get();
}
代码示例来源:origin: hasadna/open-bus
private String calcLastServiceArrivalTime(String routeId, Map<String, List<GtfsRecord>> tripsOfRoute) {
List<GtfsRecord> allTrips = tripsOfRoute.get(routeId);
String lastArrival = allTrips.stream()
.map(gtfsRecord -> gtfsRecord.getLastStopTime().getArrivalTime())
.collect(Collectors.maxBy(Comparator.naturalOrder())).orElse("23:59");
return lastArrival;
}
代码示例来源:origin: org.opensingular/singular-form-wicket
public Optional<ValidationErrorLevel> findNestedErrorsMaxLevel(FeedbackFence feedbackFence, IPredicate<ValidationError> filter) {
return collectNestedErrors(feedbackFence, resolveRootInstances(feedbackFence.getMainContainer()), filter).stream()
.map(ValidationError::getErrorLevel)
.collect(Collectors.maxBy(Comparator.naturalOrder()));
}
代码示例来源:origin: org.opensingular/form-wicket
public Optional<ValidationErrorLevel> findNestedErrorsMaxLevel(FeedbackFence feedbackFence, IPredicate<IValidationError> filter) {
return collectNestedErrors(feedbackFence, resolveRootInstances(feedbackFence.getMainContainer()), filter).stream()
.map(IValidationError::getErrorLevel)
.collect(Collectors.maxBy(Comparator.naturalOrder()));
}
代码示例来源:origin: apache/james-project
private Mono<Integer> saveBlobParts(byte[] data, BlobId blobId) {
Stream<Pair<Integer, ByteBuffer>> chunks = dataChunker.chunk(data, configuration.getBlobPartSize());
return Flux.fromStream(chunks)
.publishOn(Schedulers.elastic(), PREFETCH)
.flatMap(pair -> writePart(pair.getValue(), blobId, getChunkNum(pair)))
.collect(Collectors.maxBy(Comparator.comparingInt(x -> x)))
.flatMap(Mono::justOrEmpty)
.map(this::numToCount)
.defaultIfEmpty(0);
}
内容来源于网络,如有侵权,请联系作者删除!