private static ImmutableWorkerInfo selectFromEligibleWorkers(final Map<String, ImmutableWorkerInfo> eligibleWorkers) { return eligibleWorkers.values().stream().max( Comparator.comparing(ImmutableWorkerInfo::getCurrCapacityUsed) ).orElse(null); }
private static ImmutableWorkerInfo selectFromEligibleWorkers(final Map<String, ImmutableWorkerInfo> eligibleWorkers) { return eligibleWorkers.values().stream().max( Comparator.comparing(ImmutableWorkerInfo::getAvailableCapacity) ).orElse(null); }
@Override Node select(List<Node> sample, Random random, long tick) { return sample.stream().max((first, second) -> Long.compare(first.frequency, second.frequency)).get(); } },
@Override Node select(List<Node> sample, Random random, long tick) { return sample.stream().max((first, second) -> Long.compare(first.accessTime, second.accessTime)).get(); } },
private static int getMaxTaskId(Map<String, List<Integer>> componentToSortedTasks) { int maxTaskId = -1; for (List<Integer> integers : componentToSortedTasks.values()) { if (!integers.isEmpty()) { int tempMax = integers.stream().max(Integer::compareTo).get(); if (tempMax > maxTaskId) { maxTaskId = tempMax; } } } return maxTaskId; }
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 ) ) ); }
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")); }
@VisibleForTesting static Estimate calculateDistinctValuesCount(List<HiveColumnStatistics> columnStatistics) { return columnStatistics.stream() .map(MetastoreHiveStatisticsProvider::getDistinctValuesCount) .filter(OptionalLong::isPresent) .map(OptionalLong::getAsLong) .peek(distinctValuesCount -> verify(distinctValuesCount >= 0, "distinctValuesCount must be greater than or equal to zero")) .max(Long::compare) .map(Estimate::of) .orElse(Estimate.unknown()); }
public static <V> ArrayList<V> convertToArray(Map<Integer, V> srcMap, int start) { Set<Integer> ids = srcMap.keySet(); Integer largestId = ids.stream().max(Integer::compareTo).get(); int end = largestId - start; ArrayList<V> result = new ArrayList<>(Collections.nCopies(end + 1, null)); // creates array[largestId+1] filled with nulls for (Map.Entry<Integer, V> entry : srcMap.entrySet()) { int id = entry.getKey(); if (id < start) { LOG.debug("Entry {} will be skipped it is too small {} ...", id, start); } else { result.set(id - start, entry.getValue()); } } return result; }
/** * Gets the align format according to the longest mount point/under storage path. * @param mountTable the mount table to get information from * @return the align format for printing mounted info */ private static String getAlignFormat(Map<String, MountPointInfo> mountTable) { int mountPointLength = mountTable.entrySet().stream().map(w -> w.getKey().length()) .max(Comparator.comparing(Integer::intValue)).get(); int usfLength = mountTable.entrySet().stream().map(w -> w.getValue().getUfsUri().length()) .max(Comparator.comparing(Integer::intValue)).get(); String leftAlignFormat = "%-" + usfLength + "s on %-" + mountPointLength + "s (%s, capacity=%s, used=%s, %sread-only, %sshared, "; return leftAlignFormat; } }
Optional<ServerName> getLargestQueueFromServersNotCompacting() { lock.readLock().lock(); try { return compactionQueues.entrySet().stream() .filter(entry -> !compactingServers.contains(entry.getKey())) .max(Map.Entry.comparingByValue( (o1, o2) -> Integer.compare(o1.size(), o2.size()))).map(Map.Entry::getKey); } finally { lock.readLock().unlock(); } }
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"); } } }
/** * Print cache command arguments usage. * * @param paramsDesc Cache command arguments description. * @param indentsNum Number of indents. */ private void usageCacheParams(Map<String, String> paramsDesc, int indentsNum) { int maxParamLen = paramsDesc.keySet().stream().max(Comparator.comparingInt(String::length)).get().length(); for (Map.Entry<String, String> param : paramsDesc.entrySet()) log(i(extendToLen(param.getKey(), maxParamLen) + INDENT + "- " + param.getValue(), indentsNum)); }
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()); }
public int getPriority() { Optional<Action> result = actions.values().stream().flatMap(List::stream) .max((action1, action2) -> Math.max(action1.getPriority(), action2.getPriority())); return result.isPresent() ? result.get().getPriority() : HConstants.PRIORITY_UNSET; } }
@Benchmark public Position maxByMarketValue_serial_lazy_direct_methodref_jdk() { return this.positions.getJdkPositions().stream().max(MARKET_VALUE_COMPARATOR_METHODREF).get(); }
@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); } }
private long nextRelId( AbstractBaseRecord[] existingRecords ) { return filterType( existingRecords, RelationshipRecord.class ).map( AbstractBaseRecord::getId ).max( Long::compareTo ).orElse( -1L ) + 1; } }
private static Optional<List<Ticket>> ticketsBruteForce(Map<String, Fare> fares, Trip trip) { // Recursively enumerate all packages of tickets with which the trip can be done. // Take the cheapest. TicketPurchaseScoreCalculator ticketPurchaseScoreCalculator = new TicketPurchaseScoreCalculator(); return allShoppingCarts(fares, trip) .max(Comparator.comparingDouble(ticketPurchaseScoreCalculator::calculateScore)) .map(TicketPurchase::getTickets); }
/** * Gets the largest file (with reader) out of the list of files. * @param candidates The files to choose from. * @return The largest file; null if no file has a reader. */ static Optional<HStoreFile> getLargestFile(Collection<HStoreFile> candidates) { return candidates.stream().filter(f -> f.getReader() != null) .max((f1, f2) -> Long.compare(f1.getReader().length(), f2.getReader().length())); }