本文整理了Java中java.util.Comparator.comparingLong()
方法的一些代码示例,展示了Comparator.comparingLong()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Comparator.comparingLong()
方法的具体详情如下:
包路径:java.util.Comparator
类名称:Comparator
方法名:comparingLong
暂无
代码示例来源:origin: stackoverflow.com
Comparator<PositionReport> byTimestamp =
Comparator.comparingLong(PositionReport::getTimestamp);
Supplier<TreeSet<PositionReport>> supplier =
() -> new TreeSet<PositionReport>(byTimestamp);
positionReports = positionReports.stream()
.filter(p -> p.getTimeStamp() >= oldestKept)
.collect(Collectors.toCollection(supplier));
代码示例来源:origin: org.apache.ant/ant
/**
* Compare two Resources.
* @param foo the first Resource.
* @param bar the second Resource.
* @return a negative integer, zero, or a positive integer as the first
* argument is less than, equal to, or greater than the second.
*/
protected int resourceCompare(Resource foo, Resource bar) {
return Comparator.comparingLong(Resource::getSize).compare(foo, bar);
}
代码示例来源:origin: org.apache.ant/ant
/**
* Compare two Resources.
* @param foo the first Resource.
* @param bar the second Resource.
* @return a negative integer, zero, or a positive integer as the first
* argument is less than, equal to, or greater than the second.
*/
protected int resourceCompare(Resource foo, Resource bar) {
return Comparator.comparingLong(Resource::getLastModified).compare(foo,
bar);
}
代码示例来源:origin: SonarSource/sonarqube
private static Changeset computeLatestChangeset(Map<Integer, Changeset> lineChangesets) {
return lineChangesets.values().stream().max(Comparator.comparingLong(Changeset::getDate))
.orElseThrow(() -> new IllegalStateException("Expecting at least one Changeset to be present"));
}
代码示例来源:origin: apache/incubator-gobblin
private List<Config> getSortedConfigs(List<ConfigWithTimeStamp> configsWithTimeStamps) {
List<Config> sortedConfigs = Lists.newArrayList();
Collections.sort(configsWithTimeStamps, Comparator.comparingLong(o -> o.timeStamp));
for (ConfigWithTimeStamp configWithTimeStamp : configsWithTimeStamps) {
sortedConfigs.add(configWithTimeStamp.config);
}
return sortedConfigs;
}
代码示例来源:origin: AxonFramework/AxonFramework
@Override
public Optional<DomainEventMessage<?>> readSnapshot(String aggregateIdentifier) {
return snapshots.getOrDefault(aggregateIdentifier, Collections.emptyList())
.stream()
.max(Comparator.comparingLong(DomainEventMessage::getSequenceNumber));
}
代码示例来源:origin: SonarSource/sonarqube
private static List<RegisteredMigrationStep> toOrderedList(Map<Long, RegisteredMigrationStep> migrations) {
return migrations.entrySet().stream()
.sorted(Comparator.comparingLong(Map.Entry::getKey))
.map(Map.Entry::getValue)
.collect(MoreCollectors.toList(migrations.size()));
}
代码示例来源:origin: knowm/XChange
public static Map<String, List<BxTradeHistory>> prepareHistory(BxTradeHistory[] histories) {
Map<String, List<BxTradeHistory>> historyMap = new HashMap<>();
for (BxTradeHistory history : histories) {
List<BxTradeHistory> list =
historyMap.computeIfAbsent(String.valueOf(history.getRefId()), k -> new ArrayList<>());
list.add(history);
}
for (String key : historyMap.keySet()) {
historyMap.get(key).sort(Comparator.comparingLong(BxTradeHistory::getTransactionId));
}
return historyMap;
}
}
代码示例来源:origin: Graylog2/graylog2-server
private void loadExtractors(final String inputId) {
LOG.debug("Re-loading extractors for input <{}>", inputId);
try {
final Input input = inputService.find(inputId);
final List<Extractor> sortedExtractors = inputService.getExtractors(input).stream()
.sorted(Comparator.comparingLong(Extractor::getOrder))
.collect(Collectors.toList());
extractors.put(inputId, ImmutableList.copyOf(sortedExtractors));
} catch (NotFoundException e) {
LOG.warn("Unable to load input <{}>: {}", inputId, e.getMessage());
}
}
代码示例来源:origin: apache/ignite
/**
*
* @return Queue for evict partitions.
*/
private Queue<PartitionEvictionTask> createEvictPartitionQueue() {
switch (QUEUE_TYPE) {
case 1:
return new PriorityBlockingQueue<>(
1000, Comparator.comparingLong(p -> p.part.fullSize()));
default:
return new LinkedBlockingQueue<>();
}
}
}
代码示例来源:origin: ben-manes/caffeine
private Comparator<PolicyStats> makeComparator() {
switch (settings.report().sortBy().toLowerCase(US)) {
case "policy":
return Comparator.comparing(PolicyStats::name);
case "hit rate":
return Comparator.comparingDouble(PolicyStats::hitRate);
case "hits":
return Comparator.comparingLong(PolicyStats::hitCount);
case "misses":
return Comparator.comparingLong(PolicyStats::missCount);
case "evictions":
return Comparator.comparingLong(PolicyStats::evictionCount);
case "admit rate":
return Comparator.comparingLong(PolicyStats::admissionCount);
case "steps":
return Comparator.comparingLong(PolicyStats::operationCount);
case "time":
return Comparator.comparingLong(stats -> stats.stopwatch().elapsed(TimeUnit.NANOSECONDS));
default:
throw new IllegalArgumentException("Unknown sort order: " + settings.report().sortBy());
}
}
}
代码示例来源:origin: apache/flink
private Optional<Event> verifyWindowContiguity(List<Event> newValues, Collector<String> out) {
return newValues.stream()
.sorted(Comparator.comparingLong(Event::getSequenceNumber))
.reduce((event, event2) -> {
if (event2.getSequenceNumber() - 1 != event.getSequenceNumber()) {
out.collect("Alert: events in window out ouf order!");
}
return event2;
});
}
}
代码示例来源:origin: SonarSource/sonarqube
private static Optional<Changeset> getLatestChangeset(Component component, ScmInfo scmInfo, DefaultIssue issue) {
Optional<Changeset> mostRecentChangeset = IssueLocations.allLinesFor(issue, component.getUuid())
.filter(scmInfo::hasChangesetForLine)
.mapToObj(scmInfo::getChangesetForLine)
.max(Comparator.comparingLong(Changeset::getDate));
if (mostRecentChangeset.isPresent()) {
return mostRecentChangeset;
}
return Optional.of(scmInfo.getLatestChangeset());
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public void dumpRingStructure(IgniteLogger log) {
ClusterNode[] serverNodes = getRemoteNodes().stream()
.filter(node -> !node.isClient())
.sorted(Comparator.comparingLong(ClusterNode::order))
.toArray(ClusterNode[]::new);
U.quietAndInfo(log, Arrays.toString(serverNodes));
}
代码示例来源:origin: prestodb/presto
@Override
public Optional<QueryId> chooseQueryToKill(List<QueryMemoryInfo> runningQueries, List<MemoryInfo> nodes)
{
Map<QueryId, Long> memoryReservationOnBlockedNodes = new HashMap<>();
for (MemoryInfo node : nodes) {
MemoryPoolInfo generalPool = node.getPools().get(GENERAL_POOL);
if (generalPool == null) {
continue;
}
if (generalPool.getFreeBytes() + generalPool.getReservedRevocableBytes() > 0) {
continue;
}
Map<QueryId, Long> queryMemoryReservations = generalPool.getQueryMemoryReservations();
queryMemoryReservations.forEach((queryId, memoryReservation) -> {
memoryReservationOnBlockedNodes.compute(queryId, (id, oldValue) -> oldValue == null ? memoryReservation : oldValue + memoryReservation);
});
}
return memoryReservationOnBlockedNodes.entrySet().stream()
.max(comparingLong(Map.Entry::getValue))
.map(Map.Entry::getKey);
}
}
代码示例来源:origin: AxonFramework/AxonFramework
QueryProvider() {
queryQueue = new PriorityBlockingQueue<>(1000, Comparator.comparingLong(c -> -priority(c.getProcessingInstructionsList())));
IntStream.range(0, configuration.getQueryThreads()).forEach(i -> executor.submit(this::queryExecutor));
}
代码示例来源:origin: SonarSource/sonarqube
/**
* Author of the latest change on the lines involved by the issue.
* If no authors are set on the lines, then the author of the latest change on the file
* is returned.
*/
private Optional<String> guessScmAuthor(DefaultIssue issue, Component component) {
String author = null;
if (scmChangesets != null) {
author = IssueLocations.allLinesFor(issue, component.getUuid())
.filter(scmChangesets::hasChangesetForLine)
.mapToObj(scmChangesets::getChangesetForLine)
.filter(c -> StringUtils.isNotEmpty(c.getAuthor()))
.max(Comparator.comparingLong(Changeset::getDate))
.map(Changeset::getAuthor)
.orElse(null);
}
return Optional.ofNullable(defaultIfEmpty(author, lastCommitAuthor));
}
}
代码示例来源:origin: AxonFramework/AxonFramework
@Override
public TrackingToken createTokenAt(Instant dateTime) {
return events.values()
.stream()
.filter(event -> event.getTimestamp().equals(dateTime) || event.getTimestamp().isAfter(dateTime))
.min(Comparator.comparingLong(e -> ((GlobalSequenceTrackingToken) e.trackingToken())
.getGlobalIndex()))
.map(TrackedEventMessage::trackingToken)
.map(tt -> (GlobalSequenceTrackingToken) tt)
.map(tt -> new GlobalSequenceTrackingToken(tt.getGlobalIndex() - 1))
.orElse(null);
}
代码示例来源:origin: AxonFramework/AxonFramework
CommandRouterSubscriber() {
axonServerConnectionManager.addReconnectListener(this::resubscribe);
axonServerConnectionManager.addDisconnectListener(this::unsubscribeAll);
commandQueue = new PriorityBlockingQueue<>(1000, Comparator.comparingLong(c -> -priority(c.getProcessingInstructionsList())));
IntStream.range(0, configuration.getCommandThreads()).forEach( i -> executor.submit(this::commandExecutor));
}
代码示例来源:origin: Netflix/conductor
@Override
public Workflow getWorkflow(String workflowId, boolean includeTasks) {
Workflow workflow = getWithTransaction(tx -> readWorkflow(tx, workflowId));
if (workflow != null) {
if (includeTasks) {
List<Task> tasks = getTasksForWorkflow(workflowId);
tasks.sort(Comparator.comparingLong(Task::getScheduledTime).thenComparingInt(Task::getSeq));
workflow.setTasks(tasks);
}
}
return workflow;
}
内容来源于网络,如有侵权,请联系作者删除!