本文整理了Java中java.util.stream.Stream.min()
方法的一些代码示例,展示了Stream.min()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Stream.min()
方法的具体详情如下:
包路径:java.util.stream.Stream
类名称:Stream
方法名:min
[英]Returns the minimum element of this stream according to the provided Comparator. This is a special case of a reduction.
This is a terminal operation.
[中]
代码示例来源:origin: ben-manes/caffeine
@Override Node select(List<Node> sample, Random random, long tick) {
return sample.stream().min((first, second) ->
Long.compare(first.accessTime, second.accessTime)).get();
}
},
代码示例来源:origin: ben-manes/caffeine
@Override Node select(List<Node> sample, Random random, long tick) {
return sample.stream().min((first, second) ->
Long.compare(first.insertionTime, second.insertionTime)).get();
}
},
代码示例来源:origin: ben-manes/caffeine
@Override Node select(List<Node> sample, Random random, long tick) {
return sample.stream().min((first, second) ->
Long.compare(first.frequency, second.frequency)).get();
}
},
代码示例来源:origin: Alluxio/alluxio
private Set<WorkerNetAddress> handleFailedWorkers(Set<WorkerNetAddress> workers,
Map<WorkerNetAddress, Long> failedWorkers) {
if (workers.isEmpty()) {
return Collections.EMPTY_SET;
}
Set<WorkerNetAddress> nonFailed =
workers.stream().filter(worker -> !failedWorkers.containsKey(worker)).collect(toSet());
if (nonFailed.isEmpty()) {
return Collections.singleton(workers.stream()
.min((x, y) -> Long.compare(failedWorkers.get(x), failedWorkers.get(y))).get());
}
return nonFailed;
}
代码示例来源:origin: wildfly/wildfly
private static void printStats(Map<String, List<Long>> results) {
for (Map.Entry<String, List<Long>> entry : results.entrySet()) {
System.out.printf("Results for %s%n", entry.getKey());
System.out.printf("Min merge time=%d%n", entry.getValue().stream().min(Long::compare).get());
System.out.printf("Max merge time=%d%n", entry.getValue().stream().max(Long::compare).get());
System.out.printf("Avg merge time=%s%n", entry.getValue().stream().mapToLong(x -> x).average().getAsDouble());
System.out.printf("===================================================================%n");
}
}
}
代码示例来源:origin: goldmansachs/gs-collections
@Benchmark
public int serial_lazy_jdk()
{
return this.integersJDK.stream().min(Comparator.<Integer>naturalOrder()).get();
}
代码示例来源:origin: speedment/speedment
@Override
public Optional<T> execute() {
try (final Stream<T> stream = buildPrevious()) {
return stream.min(comparator);
}
}
}
代码示例来源:origin: ben-manes/caffeine
@Override Node select(List<Node> sample, Random random, long tick) {
return sample.stream().min((first, second) ->
Double.compare(hyperbolic(first, tick), hyperbolic(second, tick))).get();
}
double hyperbolic(Node node, long tick) {
代码示例来源:origin: apache/storm
public void initLocalRecvQueues() {
Integer minTaskId = workerData.getLocalReceiveQueues().keySet().stream().min(Integer::compareTo).get();
this.localReceiveQueues = Utils.convertToArray(workerData.getLocalReceiveQueues(), minTaskId);
this.indexingBase = minTaskId;
this.queuesToFlush = new AtomicReferenceArray<JCQueue>(localReceiveQueues.size());
}
代码示例来源:origin: apache/ignite
/**
* Find best split point, based on feature statistics.
*
* @return Best split point if it exists.
*/
public Optional<NodeSplit> findBestSplit() {
return perFeatureStatistics.values().stream()
.flatMap(x -> x.findBestSplit().map(Stream::of).orElse(Stream.empty()))
.min(Comparator.comparingDouble(NodeSplit::getImpurity));
}
}
代码示例来源: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: google/error-prone
@Override
public Description report(
Set<MethodTree> affectedTrees, SuggestedFix fix, VisitorState state, BugChecker checker) {
return affectedTrees.stream()
.min(Comparator.comparingInt(t -> ((JCTree) t).getStartPosition()))
.map(t -> checker.describeMatch(t.getModifiers(), fix))
.orElse(NO_MATCH);
}
},
代码示例来源:origin: spring-projects/spring-framework
private Mono<String> resolveResourceUrl(ServerWebExchange exchange, PathContainer lookupPath) {
return this.handlerMap.entrySet().stream()
.filter(entry -> entry.getKey().matches(lookupPath))
.min((entry1, entry2) ->
PathPattern.SPECIFICITY_COMPARATOR.compare(entry1.getKey(), entry2.getKey()))
.map(entry -> {
PathContainer path = entry.getKey().extractPathWithinPattern(lookupPath);
int endIndex = lookupPath.elements().size() - path.elements().size();
PathContainer mapping = lookupPath.subPath(0, endIndex);
ResourceWebHandler handler = entry.getValue();
List<ResourceResolver> resolvers = handler.getResourceResolvers();
ResourceResolverChain chain = new DefaultResourceResolverChain(resolvers);
return chain.resolveUrlPath(path.value(), handler.getLocations())
.map(resolvedPath -> mapping.value() + resolvedPath);
})
.orElseGet(() ->{
if (logger.isTraceEnabled()) {
logger.trace(exchange.getLogPrefix() + "No match for \"" + lookupPath + "\"");
}
return Mono.empty();
});
}
代码示例来源:origin: goldmansachs/gs-collections
@Benchmark
public Position minByMarketValue_serial_lazy_direct_methodref_jdk()
{
return this.positions.getJdkPositions().stream().min(MARKET_VALUE_COMPARATOR_METHODREF).get();
}
代码示例来源:origin: goldmansachs/gs-collections
@Benchmark
public int parallel_lazy_streams_gsc()
{
return this.integersGSC.parallelStream().min(Comparator.<Integer>naturalOrder()).get();
}
代码示例来源:origin: goldmansachs/gs-collections
@Benchmark
public int serial_lazy_streams_gsc()
{
return this.integersGSC.stream().min(Comparator.<Integer>naturalOrder()).get();
}
代码示例来源:origin: goldmansachs/gs-collections
@Benchmark
public Position minByMarketValue_serial_lazy_direct_lambda_jdk()
{
return this.positions.getJdkPositions().stream().min(MARKET_VALUE_COMPARATOR_LAMBDA).get();
}
代码示例来源:origin: apache/incubator-druid
public int deletePendingSegments(String dataSource, Interval deleteInterval)
{
// Check the given interval overlaps the interval(minCreatedDateOfActiveTasks, MAX)
final Optional<DateTime> minCreatedDateOfActiveTasks = taskStorageQueryAdapter
.getActiveTaskInfo(dataSource)
.stream()
.map(TaskInfo::getCreatedTime)
.min(Comparator.naturalOrder());
final Interval activeTaskInterval = new Interval(
minCreatedDateOfActiveTasks.orElse(DateTimes.MAX),
DateTimes.MAX
);
Preconditions.checkArgument(
!deleteInterval.overlaps(activeTaskInterval),
"Cannot delete pendingSegments because there is at least one active task created at %s",
activeTaskInterval.getStart()
);
return indexerMetadataStorageCoordinator.deletePendingSegments(dataSource, deleteInterval);
}
}
代码示例来源:origin: goldmansachs/gs-collections
@Benchmark
public Position minByQuantity_parallel_lazy_direct_methodref_jdk()
{
return this.positions.getJdkPositions().parallelStream().min(
QUANTITY_COMPARATOR_METHODREF).get();
}
代码示例来源:origin: goldmansachs/gs-collections
@Benchmark
public Position minByQuantity_parallel_lazy_direct_lambda_jdk()
{
return this.positions.getJdkPositions().parallelStream().min(
QUANTITY_COMPARATOR_LAMBDA).get();
}
内容来源于网络,如有侵权,请联系作者删除!