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));
/** * 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); }
/** * 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); }
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")); }
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; }
@Override public Optional<DomainEventMessage<?>> readSnapshot(String aggregateIdentifier) { return snapshots.getOrDefault(aggregateIdentifier, Collections.emptyList()) .stream() .max(Comparator.comparingLong(DomainEventMessage::getSequenceNumber)); }
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())); }
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; } }
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()); } }
/** * * @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<>(); } } }
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()); } } }
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; }); } }
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()); }
/** {@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)); }
@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); } }
QueryProvider() { queryQueue = new PriorityBlockingQueue<>(1000, Comparator.comparingLong(c -> -priority(c.getProcessingInstructionsList()))); IntStream.range(0, configuration.getQueryThreads()).forEach(i -> executor.submit(this::queryExecutor)); }
/** * 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)); } }
@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); }
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)); }
@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; }