Example usage for java.lang Integer compareTo

List of usage examples for java.lang Integer compareTo

Introduction

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

Prototype

public int compareTo(Integer anotherInteger) 

Source Link

Document

Compares two Integer objects numerically.

Usage

From source file:org.searsia.Hit.java

@Override
public int compareTo(Hit hit2) {
    Float score1 = getScore();/*from w w w  . j  a  v  a2s  .  c  o  m*/
    Float score2 = hit2.getScore();
    if (score1.compareTo(score2) == 0) {
        Integer rank1 = getRank();
        Integer rank2 = hit2.getRank();
        if (rank1 != null && rank2 != null) {
            return rank2.compareTo(rank1); // yes reversed!
        } else {
            return 0;
        }
    } else {
        return score1.compareTo(score2);
    }
}

From source file:com.aionemu.gameserver.model.instance.instancereward.EternalBastionWarReward.java

public List<EternalBastionWarPlayerReward> sortPoints() {
    return sort(getInstanceRewards(), on(PvPArenaPlayerReward.class).getScorePoints(),
            new Comparator<Integer>() {
                @Override/*from   www. jav  a2  s  .  c  o m*/
                public int compare(Integer o1, Integer o2) {
                    return o2 != null ? o2.compareTo(o1) : -o1.compareTo(o2);
                }
            });
}

From source file:com.aionemu.gameserver.model.instance.instancereward.OphidanBridgeWarReward.java

public List<OphidanBridgeWarPlayerReward> sortPoints() {
    return sort(getInstanceRewards(), on(PvPArenaPlayerReward.class).getScorePoints(),
            new Comparator<Integer>() {
                @Override/*from  ww w . ja  v a  2  s  . co m*/
                public int compare(Integer o1, Integer o2) {
                    return o2 != null ? o2.compareTo(o1) : -o1.compareTo(o2);
                }
            });
}

From source file:com.agileapes.couteau.context.spring.event.SpringEventTranslator.java

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    this.applicationContext = applicationContext;
    schemes.addAll(applicationContext.getBeansOfType(TranslationScheme.class, false, true).values());
    Collections.sort(schemes, new OrderedBeanComparator());
    Collections.sort(schemes, new Comparator<TranslationScheme>() {
        @Override//from   ww w .ja va 2 s.c o m
        public int compare(TranslationScheme o1, TranslationScheme o2) {
            final Integer first = o1 instanceof Ordered ? ((Ordered) o1).getOrder() : 0;
            final Integer second = o2 instanceof Ordered ? ((Ordered) o2).getOrder() : 0;
            return first.compareTo(second);
        }
    });
}

From source file:org.polymap.rhei.fulltext.store.lucene.LuceneFulltextIndex.java

@Override
public Iterable<String> propose(String term, int maxResults, String field) throws Exception {
    // no proposals for empty term
    if (term.length() == 0) {
        return Collections.EMPTY_LIST;
    }//from   w ww  . j a  va 2  s .c  om
    IndexSearcher searcher = store.getIndexSearcher();
    TermEnum terms = searcher.getIndexReader().terms(new Term(field != null ? field : FIELD_ANALYZED, term));
    try {
        // sort descending; accept equal keys
        TreeMap<Integer, String> result = new TreeMap(new Comparator<Integer>() {
            public int compare(Integer o1, Integer o2) {
                return o1.equals(o2) ? -1 : -o1.compareTo(o2);
            }
        });
        // sort
        for (int i = 0; i < maxResults * 3; i++) {
            String proposalTerm = terms.term().text();
            int docFreq = terms.docFreq();
            if (!proposalTerm.startsWith(term)) {
                break;
            }
            log.debug("Proposal: term: " + proposalTerm + ", docFreq: " + docFreq);
            result.put(docFreq, proposalTerm);
            if (!terms.next()) {
                break;
            }
        }
        // take first maxResults
        return limit(result.values(), maxResults);
    } catch (Exception e) {
        log.warn("", e);
        return Collections.EMPTY_LIST;
    } finally {
        terms.close();
    }
}

From source file:edu.ku.brc.specify.tasks.DataEntryView.java

public int compareTo(TaskConfigItemIFace o) {
    Integer o1 = getOrder();
    Integer o2 = o.getOrder();
    return o1.compareTo(o2);
}

From source file:org.kuali.rice.kew.actionrequest.ActionRequestValue.java

/**
 * Allows comparison of action requests to see which is greater responsibility. -1 : indicates type 1 is lesser responsibility than type 2 0 : indicates the same responsibility 1 : indicates type1 is greater responsibility than type 2
 *
 * @param type1//from  w  w  w. j a v a2 s  .c o  m
 * @param type2
 * @return -1 if less than, 0 if equal, 1 if greater than
 */
public static int compareRecipientType(String type1, String type2) {
    Integer type1Index = RECIPIENT_TYPE_RANK.indexOf(type1);
    Integer type2Index = RECIPIENT_TYPE_RANK.indexOf(type2);
    return type1Index.compareTo(type2Index);
}

From source file:org.kuali.rice.kew.actionrequest.ActionRequestValue.java

public static int compareDelegationType(DelegationType type1, DelegationType type2) {
    Integer type1Index = DELEGATION_TYPE_RANK.indexOf(type1);
    Integer type2Index = DELEGATION_TYPE_RANK.indexOf(type2);
    return type1Index.compareTo(type2Index);
}

From source file:arena.httpclient.redundant.HostPool.java

public int compare(HostConfig one, HostConfig two) {
    Integer order1 = one.getOrderIndex() != null ? one.getOrderIndex() : 100;
    Integer order2 = two.getOrderIndex() != null ? two.getOrderIndex() : 100;
    return order1.compareTo(order2);
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.teacher.onlineTests.DeleteExercise.java

private void removeTestQuestionFromTest(TestQuestion testQuestion) throws FenixServiceException {
    Test test = testQuestion.getTest();/*from w w  w. j a v  a  2  s  . co  m*/
    if (test == null) {
        throw new FenixServiceException();
    }

    List<TestQuestion> testQuestionList = new ArrayList<TestQuestion>(test.getTestQuestionsSet());
    Collections.sort(testQuestionList, new BeanComparator("testQuestionOrder"));

    Integer questionOrder = testQuestion.getTestQuestionOrder();
    for (TestQuestion iterTestQuestion : testQuestionList) {
        Integer iterQuestionOrder = iterTestQuestion.getTestQuestionOrder();
        if (questionOrder.compareTo(iterQuestionOrder) <= 0) {
            iterTestQuestion.setTestQuestionOrder(iterQuestionOrder - 1);
        }
    }
    testQuestion.delete();
    test.setLastModifiedDate(Calendar.getInstance().getTime());
}