List of usage examples for java.util Comparator comparingInt
public static <T> Comparator<T> comparingInt(ToIntFunction<? super T> keyExtractor)
From source file:Main.java
public static void main(String... args) { Comparator<Food> dishCaloriesComparator = Comparator.comparingInt(Food::getCalories); BinaryOperator<Food> moreCaloricOf = BinaryOperator.maxBy(dishCaloriesComparator); Food o = Food.menu.stream().collect(Collectors.reducing(moreCaloricOf)).get(); System.out.println(o);//www. j a v a 2 s . c o m }
From source file:Main.java
public static void main(String... args) { Map<Boolean, Food> o = Food.menu.stream().collect(Collectors.partitioningBy(Food::isVegetarian, Collectors .collectingAndThen(Collectors.maxBy(Comparator.comparingInt(Food::getCalories)), Optional::get))); System.out.println(o);//ww w. ja v a 2 s. co m }
From source file:io.redlink.solrlib.SolrCoreDescriptor.java
@SuppressWarnings("squid:S3725") static void unpackSolrCoreDir(Path solrCoreBundle, Path solrCoreDir) throws IOException { LoggerFactory.getLogger(SolrCoreDescriptor.class).debug("Unpacking SolrCore directory {} to {}", solrCoreBundle, solrCoreDir); try (Stream<Path> pathStream = Files.find(solrCoreBundle, Integer.MAX_VALUE, (p, a) -> Files.isRegularFile(p) && Files.isReadable(p) && "core.properties".equals(String.valueOf(p.getFileName())))) { final Optional<Path> coreProperties = pathStream.min(Comparator.comparingInt(Path::getNameCount)); final Path sourceDir = coreProperties .orElseThrow(() -> new IllegalArgumentException( "Invalid solrCoreBundle '" + solrCoreBundle + "': no core.properties found")) .getParent();// w w w. j ava 2 s . c om PathUtils.copyRecursive(sourceDir, solrCoreDir); } }
From source file:com.kantenkugel.discordbot.moduleutils.DocParser.java
public static String get(String name) { String[] split = name.toLowerCase().split("[#\\.]", 2); if (split.length != 2) return "Incorrect Method declaration"; List<Documentation> methods; synchronized (docs) { if (!docs.containsKey(split[0])) return "Class not Found!"; methods = docs.get(split[0]);/* ww w . j a v a 2 s . co m*/ } methods = methods.parallelStream().filter(doc -> doc.matches(split[1])) .sorted(Comparator.comparingInt(doc -> doc.argTypes.size())).collect(Collectors.toList()); if (methods.size() == 0) return "Method not found/documented in Class!"; if (methods.size() > 1 && methods.get(0).argTypes.size() != 0) return "Multiple methods found: " + methods.parallelStream() .map(m -> '(' + StringUtils.join(m.argTypes, ", ") + ')').collect(Collectors.joining(", ")); Documentation doc = methods.get(0); StringBuilder b = new StringBuilder(); b.append("```\n").append(doc.functionHead).append("\n```\n").append(doc.desc); if (doc.args.size() > 0) { b.append('\n').append('\n').append("**Arguments:**"); doc.args.entrySet().stream().map(e -> "**" + e.getKey() + "** - " + e.getValue()) .forEach(a -> b.append('\n').append(a)); } if (doc.returns != null) b.append('\n').append('\n').append("**Returns:**\n").append(doc.returns); if (doc.throwing.size() > 0) { b.append('\n').append('\n').append("**Throws:**"); doc.throwing.entrySet().stream().map(e -> "**" + e.getKey() + "** - " + e.getValue()) .forEach(a -> b.append('\n').append(a)); } return b.toString(); }
From source file:io.syndesis.model.integration.Integration.java
default IntegrationRevision lastRevision() { return getRevisions().stream().max(Comparator.comparingInt(r -> r.getVersion().orElse(0))).get(); }
From source file:com.netflix.imfutility.itunes.destcontext.VideoDestContextResolveStrategy.java
private Comparator<DestContextMapWrapper> comparator() { return Comparator.comparingInt(this::getWidth).thenComparingInt(this::getHeight) .thenComparing(this::getFrameRate); }
From source file:com.streamsets.pipeline.lib.jdbc.multithread.TableRuntimeContext.java
public static SortedSetMultimap<TableContext, TableRuntimeContext> buildSortedPartitionMap() { return MultimapBuilder.hashKeys() .treeSetValues(Comparator.comparingInt(TableRuntimeContext::getPartitionSequence)).build(); }
From source file:oct.util.Util.java
public static List<LinePoint> findMaxAndMins(List<LinePoint> line) { //create list of all positive Y values to get peaks ArrayList<LinePoint> convList = new ArrayList<>(line.size()); line.forEach(p -> {//from w w w . ja v a 2 s. c o m convList.add(new LinePoint(p.getX(), Math.abs(p.getY()))); }); //find X values of peaks List<LinePoint> peaks = getMaximums(convList); //collect peak points List<LinePoint> ret = line.parallelStream() .filter(p -> peaks.stream().anyMatch(pk -> pk.getX() == p.getX())).collect(Collectors.toList()); //sort by X position ret.sort(Comparator.comparingInt(peak -> peak.getX())); return ret; }
From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.op.manifest.KubernetesDeployManifestOperation.java
@Override public OperationResult operate(List _unused) { getTask().updateStatus(OP_NAME, "Beginning deployment of manifest..."); List<KubernetesManifest> inputManifests = description.getManifests(); List<KubernetesManifest> deployManifests = new ArrayList<>(); if (inputManifests == null || inputManifests.isEmpty()) { log.warn("Relying on deprecated single manifest input: " + description.getManifest()); inputManifests = Collections.singletonList(description.getManifest()); }/*from w w w .java 2 s. c o m*/ inputManifests = inputManifests.stream().filter(Objects::nonNull).collect(Collectors.toList()); List<Artifact> requiredArtifacts = description.getRequiredArtifacts(); if (requiredArtifacts == null) { requiredArtifacts = new ArrayList<>(); } List<Artifact> optionalArtifacts = description.getOptionalArtifacts(); if (optionalArtifacts == null) { optionalArtifacts = new ArrayList<>(); } List<Artifact> artifacts = new ArrayList<>(); artifacts.addAll(requiredArtifacts); artifacts.addAll(optionalArtifacts); Set<Artifact> boundArtifacts = new HashSet<>(); for (KubernetesManifest manifest : inputManifests) { if (StringUtils.isEmpty(manifest.getNamespace()) && manifest.getKind().isNamespaced()) { manifest.setNamespace(credentials.getDefaultNamespace()); } KubernetesResourceProperties properties = findResourceProperties(manifest); if (properties == null) { throw new IllegalArgumentException("Unsupported Kubernetes object kind '" + manifest.getKind().toString() + "', unable to continue."); } KubernetesHandler deployer = properties.getHandler(); if (deployer == null) { throw new IllegalArgumentException("No deployer available for Kubernetes object kind '" + manifest.getKind().toString() + "', unable to continue."); } getTask().updateStatus(OP_NAME, "Swapping out artifacts in " + manifest.getFullResourceName() + " from context..."); ReplaceResult replaceResult = deployer.replaceArtifacts(manifest, artifacts); deployManifests.add(replaceResult.getManifest()); boundArtifacts.addAll(replaceResult.getBoundArtifacts()); } Set<Artifact> unboundArtifacts = new HashSet<>(requiredArtifacts); unboundArtifacts.removeAll(boundArtifacts); getTask().updateStatus(OP_NAME, "Checking if all requested artifacts were bound..."); if (!unboundArtifacts.isEmpty()) { throw new IllegalArgumentException("The following artifacts could not be bound: '" + unboundArtifacts + "' . Failing the stage as this is likely a configuration error."); } getTask().updateStatus(OP_NAME, "Sorting manifests by priority..."); deployManifests.sort(Comparator.comparingInt(m -> findResourceProperties(m).getHandler().deployPriority())); getTask().updateStatus(OP_NAME, "Deploy order is: " + String.join(", ", deployManifests.stream() .map(KubernetesManifest::getFullResourceName).collect(Collectors.toList()))); OperationResult result = new OperationResult(); for (KubernetesManifest manifest : deployManifests) { KubernetesResourceProperties properties = findResourceProperties(manifest); boolean versioned = description.getVersioned() == null ? properties.isVersioned() : description.getVersioned(); KubernetesArtifactConverter converter = versioned ? properties.getVersionedConverter() : properties.getUnversionedConverter(); KubernetesHandler deployer = properties.getHandler(); Moniker moniker = description.getMoniker(); Artifact artifact = converter.toArtifact(provider, manifest); getTask().updateStatus(OP_NAME, "Annotating manifest " + manifest.getFullResourceName() + " with artifact, relationships & moniker..."); KubernetesManifestAnnotater.annotateManifest(manifest, artifact); namer.applyMoniker(manifest, moniker); manifest.setName(converter.getDeployedName(artifact)); getTask().updateStatus(OP_NAME, "Swapping out artifacts in " + manifest.getFullResourceName() + " from other deployments..."); ReplaceResult replaceResult = deployer.replaceArtifacts(manifest, new ArrayList<>(result.getCreatedArtifacts())); boundArtifacts.addAll(replaceResult.getBoundArtifacts()); manifest = replaceResult.getManifest(); getTask().updateStatus(OP_NAME, "Submitting manifest " + manifest.getFullResourceName() + " to kubernetes master..."); result.merge(deployer.deploy(credentials, manifest)); result.getCreatedArtifacts().add(artifact); } result.getBoundArtifacts().addAll(boundArtifacts); result.removeSensitiveKeys(registry, accountName); return result; }
From source file:oct.util.Util.java
public static List<LinePoint> findPeaksAndVallies(List<LinePoint> line) { //first find peaks List<LinePoint> peaks = getMaximums(line); //create inverse of line to find vallies ArrayList<LinePoint> convList = new ArrayList<>(line.size()); line.forEach(p -> {/* w w w . j a v a2 s . co m*/ convList.add(new LinePoint(p.getX(), 0D - p.getY())); }); //find X values of vallies List<LinePoint> vallies = getMaximums(convList); //collect valley points List<LinePoint> ret = line.parallelStream() .filter(p -> vallies.stream().anyMatch(pk -> pk.getX() == p.getX())).collect(Collectors.toList()); //sort by X position ret.addAll(peaks); ret.sort(Comparator.comparingInt(peak -> peak.getX())); return ret; }