List of usage examples for java.lang Integer compare
public static int compare(int x, int y)
From source file:com.gs.collections.impl.jmh.AnagramSetTest.java
@Benchmark public void parallel_lazy_gsc() { UnsortedSetMultimap<Alphagram, String> multimap = this.gscWords.asParallel(this.executorService, BATCH_SIZE) .groupBy(Alphagram::new); FastList<Pair<Integer, String>> pairs = (FastList<Pair<Integer, String>>) FastList .newList(multimap.multiValuesView()).asParallel(this.executorService, BATCH_SIZE) .select(iterable -> iterable.size() >= SIZE_THRESHOLD) .collect(iterable -> Tuples.pair(iterable.size(), iterable.size() + ": " + iterable)) .toSortedList((pair1, pair2) -> Integer.compare(pair2.getOne(), pair1.getOne())); pairs.asParallel(this.executorService, BATCH_SIZE).collect(Pair::getTwo) .forEach(Procedures.cast(e -> Assert.assertFalse(e.isEmpty()))); }
From source file:com.vmware.admiral.compute.container.volume.VolumeUtil.java
/** * Creates additional affinity rules between container descriptions which share * local volumes. Each container group should be deployed on a single host. *//* ww w.j av a 2 s. c o m*/ public static void applyLocalNamedVolumeConstraints(Collection<ComponentDescription> componentDescriptions) { Map<String, ContainerVolumeDescription> volumes = filterDescriptions(ContainerVolumeDescription.class, componentDescriptions); List<String> localVolumes = volumes.values().stream().filter(v -> DEFAULT_VOLUME_DRIVER.equals(v.driver)) .map(v -> v.name).collect(Collectors.toList()); if (localVolumes.isEmpty()) { return; } Map<String, ContainerDescription> containers = filterDescriptions(ContainerDescription.class, componentDescriptions); // sort containers by local volume: each set is a group of container names // that share a particular local volume List<Set<String>> localVolumeContainers = localVolumes.stream() .map(v -> filterByVolume(v, containers.values())).filter(s -> !s.isEmpty()) .collect(Collectors.toList()); if (localVolumeContainers.isEmpty()) { return; } /** Merge sets of containers sharing local volumes * * C1 C2 C3 C4 C5 C6 * \ /\ / | \ / * L1 L2 L3 L4 * * Input: [C1, C2], [C2, C3], [C4], [C5, C6] * Output: [C1, C2, C3], [C4], [C5, C6] */ localVolumeContainers = mergeSets(localVolumeContainers); Map<String, List<ContainerVolumeDescription>> containerToVolumes = containers.values().stream() .collect(Collectors.toMap(cd -> cd.name, cd -> filterVolumes(cd, volumes.values()))); Map<String, Integer> containerToDriverCount = containerToVolumes.entrySet().stream() .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().stream().map(vd -> vd.driver).collect(Collectors.toSet()).size())); for (Set<String> s : localVolumeContainers) { if (s.size() > 1) { // find the container with highest number of required drivers int max = s.stream().map(cn -> containerToDriverCount.get(cn)) .max((vc1, vc2) -> Integer.compare(vc1, vc2)).get(); Set<String> maxDrivers = s.stream().filter(cn -> containerToDriverCount.get(cn) == max) .collect(Collectors.toSet()); String maxCont = maxDrivers.iterator().next(); s.remove(maxCont); s.stream().forEach(cn -> addAffinity(maxCont, containers.get(cn))); } } }
From source file:org.mitre.mpf.wfm.data.entities.transients.Detection.java
@Override public int compareTo(Detection other) { int comparison; if (other == null) { comparison = 1;//from w ww .j a v a 2 s. c o m } else if ((comparison = Integer.compare(mediaOffsetFrame, other.mediaOffsetFrame)) == 0 && (comparison = Integer.compare(mediaOffsetTime, other.mediaOffsetTime)) == 0 && (comparison = Integer.compare(x, other.x)) == 0 && (comparison = Integer.compare(y, other.y)) == 0 && (comparison = Integer.compare(width, other.width)) == 0 && (comparison = Integer.compare(height, other.height)) == 0 && (comparison = Float.compare(confidence, other.confidence)) == 0 && (comparison = TextUtils.nullSafeCompare(artifactPath, other.artifactPath)) == 0 && (comparison = compareMap(detectionProperties, other.detectionProperties)) == 0) { comparison = 0; } return comparison; }
From source file:de.sanandrew.mods.turretmod.client.render.world.RenderTurretPointed.java
private void renderLabel(EntityTurret turret, double x, double y, double z, LabelEntry lbl) { final Minecraft mc = Minecraft.getMinecraft(); final FontRenderer fontrenderer = mc.fontRenderer; final float scale = 0.010F; final List<ILabelElement> fltElem = this.elements.stream().filter(el -> el.showElement(turret)) .sorted((el1, el2) -> Integer.compare(el2.getPriority(), el1.getPriority())) .collect(Collectors.toList()); lbl.maxWidth = fltElem.stream()/*w ww . ja v a 2 s . co m*/ .collect(() -> new MutableFloat(MIN_WIDTH), (f, l) -> f.setValue(Math.max(f.getValue(), l.getWidth(turret, fontrenderer))), (f1, f2) -> f1.setValue(Math.max(f1.getValue(), f2.getValue()))) .floatValue(); lbl.maxHeight = fltElem.stream().collect(() -> new MutableFloat(0.0F), (f, l) -> f.add(l.getHeight(turret, fontrenderer)), (f1, f2) -> f1.add(f2.getValue())).floatValue(); Tessellator tessellator = Tessellator.getInstance(); BufferBuilder buffer = tessellator.getBuffer(); GlStateManager.pushMatrix(); GlStateManager.translate(x, y + (turret.isUpsideDown() ? 1.4F : 0.7F), z); GlStateManager.glNormal3f(0.0F, 1.0F, 0.0F); GlStateManager.rotate(lbl.angleY, 0.0F, 1.0F, 0.0F); GlStateManager.rotate(lbl.angleX, 1.0F, 0.0F, 0.0F); GlStateManager.scale(-scale, -scale, scale); GlStateManager.translate(-lbl.maxWidth / 2.0D, -32.0D, 0.0D); GlStateManager.disableLighting(); GlStateManager.depthMask(false); GlStateManager.disableDepth(); GlStateManager.enableBlend(); GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); GlStateManager.disableTexture2D(); GlStateManager.shadeModel(GL11.GL_SMOOTH); buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR); float alphaMulti = Math.min(1.0F, lbl.progress); ColorObj clrTop = new ColorObj(0x0050FF00 | (Math.max(Math.round(0xCC * alphaMulti), 4) << 24)); ColorObj clrBottom = new ColorObj(0x00288000 | (Math.max(Math.round(0xCC * alphaMulti), 4) << 24)); ColorObj clrMain = new ColorObj(0x00001000 | (Math.max(Math.round(0xA0 * alphaMulti), 4) << 24)); // main bg addQuad(buffer, -2.0D, -2.0D, lbl.maxWidth + 2.0D, lbl.maxHeight + 2.0D, clrMain); // inner frame [top, bottom, left, right] addQuad(buffer, -3.0D, -3.0D, lbl.maxWidth + 3.0D, -2.0D, clrTop); addQuad(buffer, -3.0D, lbl.maxHeight + 2.0D, lbl.maxWidth + 3.0D, lbl.maxHeight + 3.0D, clrBottom); addQuad(buffer, -3.0D, -2.0D, -2.0D, lbl.maxHeight + 2.0D, clrTop, clrBottom); addQuad(buffer, lbl.maxWidth + 2.0D, -2.0D, lbl.maxWidth + 3.0D, lbl.maxHeight + 2.0D, clrTop, clrBottom); // outer frame [top, bottom, left, right] addQuad(buffer, -3.0D, -4.0D, lbl.maxWidth + 3.0D, -3.0D, clrMain); addQuad(buffer, -3.0D, lbl.maxHeight + 3.0D, lbl.maxWidth + 3.0D, lbl.maxHeight + 4.0D, clrMain); addQuad(buffer, -4.0D, -3.0D, -3.0D, lbl.maxHeight + 3.0D, clrMain); addQuad(buffer, lbl.maxWidth + 3.0D, -3.0D, lbl.maxWidth + 4.0D, lbl.maxHeight + 3.0D, clrMain); if (lbl.progress >= 1.0F) { final MutableFloat currHeight = new MutableFloat(0.0F); fltElem.forEach(elem -> { elem.doRenderQuads(turret, lbl.maxWidth, lbl.progress - 1.0F, fontrenderer, currHeight.floatValue(), buffer); currHeight.add(elem.getHeight(turret, fontrenderer)); }); } tessellator.draw(); GlStateManager.shadeModel(GL11.GL_FLAT); GlStateManager.enableTexture2D(); if (lbl.progress >= 1.0F) { final MutableFloat currHeight = new MutableFloat(0.0F); fltElem.forEach(elem -> { GlStateManager.pushMatrix(); GlStateManager.translate(0.0F, currHeight.floatValue(), 0.0F); elem.doRenderTextured(turret, lbl.maxWidth, lbl.progress - 1.0F, fontrenderer); GlStateManager.popMatrix(); currHeight.add(elem.getHeight(turret, fontrenderer)); }); } GlStateManager.enableDepth(); GlStateManager.depthMask(true); GlStateManager.disableBlend(); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); GlStateManager.popMatrix(); }
From source file:org.dragoneronca.nlp.wol.disambiguation.SenseSolver.java
private void disambiguateSense(LightSense sense) { Set<LightSemanticEdge> outEdges = sense.getOutEdges(); // group semantic edges by referred term Multimap<Integer, LightSemanticEdge> wordMap = LinkedHashMultimap.create(); for (LightSemanticEdge lightSemanticEdge : outEdges) { wordMap.put(lightSemanticEdge.getTargetWordHash(), lightSemanticEdge); }/* ww w. j av a 2 s . c om*/ // disambiguate each term for (int wordHash : wordMap.keySet()) { processedTerms++; if (disambiguateSenseTerm(sense, wordHash, wordMap.get(wordHash))) { convergedTerms++; } } // update weights in the light wol graph ArrayList<LightSemanticEdge> semanticEdgeList = new ArrayList<>(outEdges); Collections.sort(semanticEdgeList, new Comparator<LightSemanticEdge>() { @Override public int compare(LightSemanticEdge lightSemanticEdge, LightSemanticEdge lightSemanticEdge2) { return Integer.compare(lightSemanticEdge.getId(), lightSemanticEdge2.getId()); } }); EdgeList outEdgesOf = sense.getLightWolGraph().getOutEdgesOf(sense.getId()); for (int i = 0; i < outEdges.size(); i++) { outEdgesOf.setWeight(i, semanticEdgeList.get(i).getWeight()); } }
From source file:io.gravitee.management.service.impl.PageServiceImpl.java
private void reorderAndSavePages(final Page pageToReorder) throws TechnicalException { final Collection<Page> pages = pageRepository.findByApi(pageToReorder.getApi()); final List<Boolean> increment = asList(true); pages.stream().sorted((o1, o2) -> Integer.compare(o1.getOrder(), o2.getOrder())).forEachOrdered(page -> { try {/*from w w w . jav a2 s . co m*/ if (page.equals(pageToReorder)) { increment.set(0, false); page.setOrder(pageToReorder.getOrder()); } else { final int newOrder; final Boolean isIncrement = increment.get(0); if (page.getOrder() < pageToReorder.getOrder()) { newOrder = page.getOrder() - (isIncrement ? 0 : 1); } else if (page.getOrder() > pageToReorder.getOrder()) { newOrder = page.getOrder() + (isIncrement ? 1 : 0); } else { newOrder = page.getOrder() + (isIncrement ? 1 : -1); } page.setOrder(newOrder); } pageRepository.update(page); } catch (final TechnicalException ex) { throw onUpdateFail(page.getId(), ex); } }); }
From source file:org.apache.impala.analysis.TupleDescriptor.java
/** * Returns all materialized slots ordered by their offset. Valid to call after the * mem layout has been computed./*from ww w .ja v a2 s .c om*/ */ public ArrayList<SlotDescriptor> getSlotsOrderedByOffset() { Preconditions.checkState(hasMemLayout_); ArrayList<SlotDescriptor> result = getMaterializedSlots(); Collections.sort(result, new Comparator<SlotDescriptor>() { public int compare(SlotDescriptor a, SlotDescriptor b) { return Integer.compare(a.getByteOffset(), b.getByteOffset()); } }); return result; }
From source file:uni.bielefeld.cmg.sparkhit.util.HelpParam.java
public void printStatisticerHelp() { HelpFormatter formatter = new HelpFormatter(); formatter.setOptionComparator(new Comparator<Option>() { public int compare(Option o1, Option o2) { return Integer.compare(parameterMap.get(o1.getOpt()), parameterMap.get(o2.getOpt())); }//from ww w.jav a 2 s .co m }); final String executable = System.getProperty("executable", "spark-submit [spark parameter] --class uni.bielefeld.cmg.sparkhit.main.MainOfPiper Sparkhit.jar"); err.println("Name:"); err.println("\tSparkHit Machine Learning library"); err.println(); err.println("Options:"); formatter.printOptions(new PrintWriter(err, true), 85, parameter, 2, 3); /* print formatted parameters */ err.println(); err.println("Usage:"); err.println("\tMachine learning library for vcf or tabular file:"); err.println(executable + " [parameters] -vcf genotype.vcf -outfile ./result -column 2-10 -cache"); err.println(); }
From source file:com.github.veqryn.net.Ip4.java
@Override public final int compareTo(final Ip4 other) { return Integer.compare(this.address, other.address); }
From source file:org.semanticweb.owlapi.io.RDFTriple.java
private static int comparePredicates(RDFResourceIRI predicate, RDFResourceIRI otherPredicate) { IRI predicateIRI = predicate.getIRI(); int specialPredicateRank = specialPredicateRanks.get(predicateIRI); IRI otherPredicateIRI = otherPredicate.getIRI(); int otherSpecialPredicateRank = specialPredicateRanks.get(otherPredicateIRI); if (specialPredicateRank != specialPredicateRanks.getNoEntryValue()) { if (otherSpecialPredicateRank != specialPredicateRanks.getNoEntryValue()) { return Integer.compare(specialPredicateRank, otherSpecialPredicateRank); } else {/*from ww w. j av a2s. co m*/ return -1; } } else { if (otherSpecialPredicateRank != specialPredicateRanks.getNoEntryValue()) { return +1; } else { return predicateIRI.compareTo(otherPredicateIRI); } } }