List of usage examples for java.lang Integer compare
public static int compare(int x, int y)
From source file:io.horizondb.model.core.fields.IntegerField.java
/** * {@inheritDoc}// w ww . j av a 2s .co m */ @Override public int compareTo(Field other) { return Integer.compare(this.value, other.getInt()); }
From source file:android.databinding.tool.util.XmlEditor.java
public static String strip(File f, String newTag) throws IOException { ANTLRInputStream inputStream = new ANTLRInputStream(new FileReader(f)); XMLLexer lexer = new XMLLexer(inputStream); CommonTokenStream tokenStream = new CommonTokenStream(lexer); XMLParser parser = new XMLParser(tokenStream); XMLParser.DocumentContext expr = parser.document(); XMLParser.ElementContext root = expr.element(); if (root == null || !"layout".equals(nodeName(root))) { return null; // not a binding layout }/*from www. j a va 2 s . c om*/ List<? extends ElementContext> childrenOfRoot = elements(root); List<? extends XMLParser.ElementContext> dataNodes = filterNodesByName("data", childrenOfRoot); if (dataNodes.size() > 1) { L.e("Multiple binding data tags in %s. Expecting a maximum of one.", f.getAbsolutePath()); } ArrayList<String> lines = new ArrayList<>(); lines.addAll(FileUtils.readLines(f, "utf-8")); for (android.databinding.parser.XMLParser.ElementContext it : dataNodes) { replace(lines, toPosition(it.getStart()), toEndPosition(it.getStop()), ""); } List<? extends XMLParser.ElementContext> layoutNodes = excludeNodesByName("data", childrenOfRoot); if (layoutNodes.size() != 1) { L.e("Only one layout element and one data element are allowed. %s has %d", f.getAbsolutePath(), layoutNodes.size()); } final XMLParser.ElementContext layoutNode = layoutNodes.get(0); ArrayList<Pair<String, android.databinding.parser.XMLParser.ElementContext>> noTag = new ArrayList<>(); recurseReplace(layoutNode, lines, noTag, newTag, 0); // Remove the <layout> Position rootStartTag = toPosition(root.getStart()); Position rootEndTag = toPosition(root.content().getStart()); replace(lines, rootStartTag, rootEndTag, ""); // Remove the </layout> ImmutablePair<Position, Position> endLayoutPositions = findTerminalPositions(root, lines); replace(lines, endLayoutPositions.left, endLayoutPositions.right, ""); StringBuilder rootAttributes = new StringBuilder(); for (AttributeContext attr : attributes(root)) { rootAttributes.append(' ').append(attr.getText()); } Pair<String, XMLParser.ElementContext> noTagRoot = null; for (Pair<String, XMLParser.ElementContext> pair : noTag) { if (pair.getRight() == layoutNode) { noTagRoot = pair; break; } } if (noTagRoot != null) { ImmutablePair<String, XMLParser.ElementContext> newRootTag = new ImmutablePair<>( noTagRoot.getLeft() + rootAttributes.toString(), layoutNode); int index = noTag.indexOf(noTagRoot); noTag.set(index, newRootTag); } else { ImmutablePair<String, XMLParser.ElementContext> newRootTag = new ImmutablePair<>( rootAttributes.toString(), layoutNode); noTag.add(newRootTag); } //noinspection NullableProblems Collections.sort(noTag, new Comparator<Pair<String, XMLParser.ElementContext>>() { @Override public int compare(Pair<String, XMLParser.ElementContext> o1, Pair<String, XMLParser.ElementContext> o2) { Position start1 = toPosition(o1.getRight().getStart()); Position start2 = toPosition(o2.getRight().getStart()); int lineCmp = Integer.compare(start2.line, start1.line); if (lineCmp != 0) { return lineCmp; } return Integer.compare(start2.charIndex, start1.charIndex); } }); for (Pair<String, android.databinding.parser.XMLParser.ElementContext> it : noTag) { XMLParser.ElementContext element = it.getRight(); String tag = it.getLeft(); Position endTagPosition = endTagPosition(element); fixPosition(lines, endTagPosition); String line = lines.get(endTagPosition.line); String newLine = line.substring(0, endTagPosition.charIndex) + " " + tag + line.substring(endTagPosition.charIndex); lines.set(endTagPosition.line, newLine); } return StringUtils.join(lines, System.getProperty("line.separator")); }
From source file:nars.truth.Truth.java
static int compare(@NotNull Truth a, @NotNull Truth b) { if (a == b)//from w w w. j ava 2 s . co m return 0; //see how Truth hash() is calculated to know why this works return Integer.compare(a.hashCode(), b.hashCode()); // tc = Float.compare(truth.getFrequency(), otruth.getFrequency()); // if (tc!=0) return tc; // tc = Float.compare(truth.getConfidence(), otruth.getConfidence()); // if (tc!=0) return tc; // // return 0; }
From source file:org.dragoneronca.nlp.wol.graph_building.FirstSenseGraphBuilder.java
private void linkSenseFromTerms(Sense sense, RangedSenseScanner.AlphabeticRange alphabeticRange, RangedSenseIteratorFactory rangedSenseIteratorFactory) { TAGGER.tagSenses(Arrays.asList(sense).iterator()); for (TaggedTerm taggedTerm : sense.getTaggedGloss()) { if (!alphabeticRange.isInRange(taggedTerm.getLemma())) { continue; }/*from w ww. j a v a 2 s . c om*/ Set<Sense> targetSenses = getTargetSenses(sense, Language.EN, taggedTerm.getPOS(), taggedTerm.getLemma(), rangedSenseIteratorFactory); if (targetSenses.isEmpty()) { return; } Sense firstSense = Collections.min(targetSenses, new Comparator<Sense>() { @Override public int compare(Sense sense1, Sense sense2) { return Integer.compare(sense1.getNumber(), sense2.getNumber()); } }); TermSemanticEdge semanticEdge = new TermSemanticEdge(firstSense, MAX_PROBABILITY, taggedTerm); semanticEdge.setOriginSense(sense); Set<SemanticEdge> outEdges = sense.getOutEdges(); if (outEdges == null) { outEdges = new HashSet<>(); sense.setOutEdges(outEdges); } outEdges.add(semanticEdge); entityManager.persist(semanticEdge); } }
From source file:ch.fork.AdHocRailway.domain.turnouts.Route.java
@Override public int compareTo(final Route o) { return Integer.compare(number, o.getNumber()); }
From source file:com.facebook.presto.kinesis.KinesisColumnHandle.java
@Override public int compareTo(KinesisColumnHandle otherHandle) { return Integer.compare(this.getOrdinalPosition(), otherHandle.getOrdinalPosition()); }
From source file:org.nuxeo.ecm.platform.picture.api.PictureConversion.java
@Override public int compareTo(PictureConversion other) { return Integer.compare(getOrder(), other.getOrder()); }
From source file:uni.bielefeld.cmg.sparkhit.util.HelpParam.java
public void printScriptPiperHelp() { 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 www.j a v a 2 s . c om }); 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 ScriptPiper (bwa, bowtie2 or other aligner)"); 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("\tParallelize your own tool like bwa mem:"); err.println(executable + " [parameters] -fastq query.fq.tar.bz2 -outfile ./outbams_dir -tool \"/mypath/bwa mem\" -toolparam \"/mypath/reference.fa -t 32\""); err.println(); }
From source file:org.eclipse.collections.impl.jmh.AnagramSetTest.java
@Benchmark public void parallel_lazy_ec() { UnsortedSetMultimap<Alphagram, String> multimap = this.ecWords.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.linkedin.pinot.tools.StarTreeIndexViewer.java
private int build(StarTreeIndexNodeInterf indexNode, StarTreeJsonNode json) { Iterator<? extends StarTreeIndexNodeInterf> childrenIterator = indexNode.getChildrenIterator(); if (!childrenIterator.hasNext()) { return 0; }/*from w w w .j av a 2 s.c o m*/ int childDimensionId = indexNode.getChildDimensionName(); String childDimensionName = dimensionNameToIndexMap.inverse().get(childDimensionId); Dictionary dictionary = dictionaries.get(childDimensionName); int totalChildNodes = indexNode.getNumChildren(); Comparator<Pair<String, Integer>> comparator = new Comparator<Pair<String, Integer>>() { @Override public int compare(Pair<String, Integer> o1, Pair<String, Integer> o2) { return -1 * Integer.compare(o1.getRight(), o2.getRight()); } }; MinMaxPriorityQueue<Pair<String, Integer>> queue = MinMaxPriorityQueue.orderedBy(comparator) .maximumSize(MAX_CHILDREN).create(); StarTreeJsonNode allNode = null; while (childrenIterator.hasNext()) { StarTreeIndexNodeInterf childIndexNode = childrenIterator.next(); int childDimensionValueId = childIndexNode.getDimensionValue(); String childDimensionValue = "ALL"; if (childDimensionValueId != StarTreeIndexNodeInterf.ALL) { childDimensionValue = dictionary.get(childDimensionValueId).toString(); } StarTreeJsonNode childJson = new StarTreeJsonNode(childDimensionValue); totalChildNodes += build(childIndexNode, childJson); if (childDimensionValueId != StarTreeIndexNodeInterf.ALL) { json.addChild(childJson); queue.add(ImmutablePair.of(childDimensionValue, totalChildNodes)); } else { allNode = childJson; } } //put ALL node at the end if (allNode != null) { json.addChild(allNode); } if (totalChildNodes > MAX_CHILDREN) { Iterator<Pair<String, Integer>> qIterator = queue.iterator(); Set<String> topKDimensions = new HashSet<>(); topKDimensions.add("ALL"); while (qIterator.hasNext()) { topKDimensions.add(qIterator.next().getKey()); } Iterator<StarTreeJsonNode> iterator = json.getChildren().iterator(); while (iterator.hasNext()) { StarTreeJsonNode next = iterator.next(); if (!topKDimensions.contains(next.getName())) { iterator.remove(); } } } return totalChildNodes; }