Example usage for java.lang Integer compare

List of usage examples for java.lang Integer compare

Introduction

In this page you can find the example usage for java.lang Integer compare.

Prototype

public static int compare(int x, int y) 

Source Link

Document

Compares two int values numerically.

Usage

From source file:org.mitre.mpf.wfm.data.entities.transients.Track.java

@Override
public int compareTo(Track other) {
    int comparisonResult;
    if (other == null) {
        comparisonResult = 1; // non-null > null
    } else if ((comparisonResult = Long.compare(jobId, other.jobId)) == 0
            && (comparisonResult = Long.compare(mediaId, other.mediaId)) == 0
            && (comparisonResult = Integer.compare(stageIndex, other.stageIndex)) == 0
            && (comparisonResult = Integer.compare(actionIndex, other.actionIndex)) == 0
            && (comparisonResult = Integer.compare(startOffsetFrameInclusive,
                    other.startOffsetFrameInclusive)) == 0
            && (comparisonResult = Integer.compare(endOffsetFrameInclusive, other.endOffsetFrameInclusive)) == 0
            && (comparisonResult = Integer.compare(startOffsetTimeInclusive,
                    other.startOffsetTimeInclusive)) == 0
            && (comparisonResult = Integer.compare(endOffsetTimeInclusive, other.endOffsetTimeInclusive)) == 0
            && (comparisonResult = nullSafeCompare(type, other.type)) == 0
            && (comparisonResult = nullSafeCompare(exemplar, other.exemplar)) == 0
            && (comparisonResult = compareDetections(detections, other.detections)) == 0) {
        comparisonResult = 0;// ww w. ja va  2  s .c  om
    }

    return comparisonResult;
}

From source file:ch.fork.AdHocRailway.domain.turnouts.Turnout.java

@Override
public int compareTo(final Turnout o) {
    return Integer.compare(number, o.getNumber());
}

From source file:org.kontalk.model.KonThread.java

@Override
public int compareTo(KonThread o) {
    return Integer.compare(this.mID, o.mID);
}

From source file:org.apache.rya.indexing.smarturi.duplication.DuplicateDataDetector.java

/**
 * Removes any duplicate (nearly identical) entities from the collection
 * of entities.//from   ww  w .  ja  v a 2 s.  co  m
 * @param entities the {@link List} of {@link Entity}s. (not {@code null})
 * @throws SmartUriException
 */
public void removeDuplicatesFromCollection(final List<Entity> entities) throws SmartUriException {
    requireNonNull(entities);
    // Use a Sorted Set in reverse order to hold the indices
    final Set<Integer> indicesToRemove = new TreeSet<>((a, b) -> Integer.compare(b, a));
    if (entities != null && entities.size() > 1) {
        // Compare all entities to each other while avoiding making the
        // same comparisons again and not comparing an entity to itself.
        for (int i = 0; i < entities.size() - 1; i++) {
            final Entity entity1 = entities.get(i);
            for (int j = entities.size() - 1; j > i; j--) {
                final Entity entity2 = entities.get(j);
                final boolean areDuplicates = compareEntities(entity1, entity2);
                if (areDuplicates) {
                    indicesToRemove.add(j);
                }
            }
        }
    }
    if (!indicesToRemove.isEmpty()) {
        // Remove indices in reverse order (already sorted in descending
        // order so just loop through them)
        for (final int index : indicesToRemove) {
            entities.remove(index);
        }
    }
}

From source file:eu.project.ttc.engines.morpho.CompostAE.java

@Override
public void collectionProcessComplete() throws AnalysisEngineProcessException {
    SubTaskObserver observer = observerResource.getTaskObserver(TASK_NAME);
    observer.setTotalTaskWork(termIndexResource.getTermIndex().getWords().size());
    LOGGER.info("Starting morphologyical compound detection for TermIndex {}",
            this.termIndexResource.getTermIndex().getName());
    LOGGER.debug(this.toString());
    wrMeasure = termIndexResource.getTermIndex().getWRMeasure();
    swtLemmaIndex = termIndexResource.getTermIndex().getCustomIndex(TermIndexes.SINGLE_WORD_LEMMA);
    buildCompostIndex();//from w  ww  .  j a  v a 2 s  .  co  m

    final MutableLong cnt = new MutableLong(0);

    Timer progressLoggerTimer = new Timer("Morphosyntactic splitter AE");
    progressLoggerTimer.schedule(new TimerTask() {
        @Override
        public void run() {
            int total = termIndexResource.getTermIndex().getWords().size();
            CompostAE.LOGGER.info("Progress: {}% ({} on {})",
                    String.format("%.2f", ((float) cnt.longValue() * 100) / total), cnt.longValue(), total);
        }
    }, 5000l, 5000l);

    int observingStep = 100;
    for (Term swt : termIndexResource.getTermIndex().getTerms()) {
        if (!swt.isSingleWord())
            continue;
        cnt.increment();
        if (cnt.longValue() % observingStep == 0) {
            observer.work(observingStep);
        }

        /*
         * Do not do native morphology splitting 
         * if a composition already exists.
         */
        Word word = swt.getWords().get(0).getWord();
        if (word.isCompound())
            continue;

        Map<Segmentation, Double> scores = computeScores(word.getLemma());
        if (scores.size() > 0) {

            List<Segmentation> segmentations = Lists.newArrayList(scores.keySet());

            /*
             *  compare segmentations in a deterministic way.
             */
            segmentations.sort(new Comparator<Segmentation>() {
                @Override
                public int compare(Segmentation o1, Segmentation o2) {
                    int comp = Double.compare(scores.get(o2), scores.get(o1));
                    if (comp != 0)
                        return comp;
                    comp = Integer.compare(o1.getSegments().size(), o2.getSegments().size());
                    if (comp != 0)
                        return comp;
                    for (int i = 0; i < o1.getSegments().size(); i++) {
                        comp = Integer.compare(o2.getSegments().get(i).getEnd(),
                                o1.getSegments().get(i).getEnd());
                        if (comp != 0)
                            return comp;
                    }
                    return 0;
                }
            });

            Segmentation bestSegmentation = segmentations.get(0);

            // build the word component from segmentation
            WordBuilder builder = new WordBuilder(word);

            for (Segment seg : bestSegmentation.getSegments()) {
                String lemma = segmentLemmaCache.getUnchecked(seg.getLemma());
                builder.addComponent(seg.getBegin(), seg.getEnd(), lemma);
                if (seg.isNeoclassical())
                    builder.setCompoundType(CompoundType.NEOCLASSICAL);
                else
                    builder.setCompoundType(CompoundType.NATIVE);
            }
            builder.create();

            // log the word composition
            if (LOGGER.isTraceEnabled()) {
                List<String> componentStrings = Lists.newArrayList();
                for (Component component : word.getComponents())
                    componentStrings.add(component.toString());
                LOGGER.trace("{} [{}]", word.getLemma(), Joiner.on(' ').join(componentStrings));
            }
        }
    }

    //finalize
    progressLoggerTimer.cancel();

    LOGGER.debug("segment score cache size: {}", segmentScoreEntries.size());
    LOGGER.debug("segment score hit count: " + segmentScoreEntries.stats().hitCount());
    LOGGER.debug("segment score hit rate: " + segmentScoreEntries.stats().hitRate());
    LOGGER.debug("segment score eviction count: " + segmentScoreEntries.stats().evictionCount());
    termIndexResource.getTermIndex().dropCustomIndex(TermIndexes.SINGLE_WORD_LEMMA);
    segmentScoreEntries.invalidateAll();
    segmentLemmaCache.invalidateAll();
}

From source file:de.bund.bfr.knime.pmmlite.core.PmmUtils.java

public static <T> T getMaxCounted(Collection<T> values) {
    return Collections.max(LinkedHashMultiset.create(values).entrySet(),
            (o1, o2) -> Integer.compare(o1.getCount(), o2.getCount())).getElement();
}

From source file:org.lightjason.agentspeak.common.CPath.java

@Override
public final int compareTo(final IPath p_path) {
    return Integer.compare(this.hashCode(), p_path.hashCode());
}

From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrPath.java

@Override
public int compareTo(Path other) {
    int len = Math.min(other.getNameCount(), getNameCount());

    for (int idx = 0; idx < len; idx++) {
        int value = other.getName(idx).toString().compareTo(getName(idx).toString());
        if (value != 0) {
            return value;
        }/*from  w w  w .  j  ava  2 s.  c  o  m*/
    }

    return Integer.compare(other.getNameCount(), getNameCount());
}

From source file:uk.ac.bbsrc.tgac.miso.core.data.impl.PoolImpl.java

private static String getCombinedIndexSequences(PoolableElementView view) {
    return view.getIndices().stream().sorted((i1, i2) -> Integer.compare(i1.getPosition(), i2.getPosition()))
            .map(Index::getSequence).collect(Collectors.joining());
}

From source file:org.kontalk.model.KonMessage.java

@Override
public int compareTo(KonMessage o) {
    if (this.equals(o))
        return 0;

    return Integer.compare(mID, o.getID());
}