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.kuali.kfs.gl.businessobject.CorrectionChange.java

public int compareTo(Object o) {
    CorrectionChange cc = (CorrectionChange) o;

    String thisFdocNbr = documentNumber == null ? "" : documentNumber;
    String thatFdocNbr = cc.documentNumber == null ? "" : cc.documentNumber;
    int c = thisFdocNbr.compareTo(thatFdocNbr);

    if (c == 0) {
        Integer thisGn = correctionChangeGroupLineNumber == null ? 0 : correctionChangeGroupLineNumber;
        Integer thatGn = cc.correctionChangeGroupLineNumber == null ? 0 : cc.correctionChangeGroupLineNumber;
        c = thisGn.compareTo(thatGn);
        if (c == 0) {
            Integer thisCln = correctionChangeLineNumber == null ? 0 : correctionChangeLineNumber;
            Integer thatCln = correctionChangeLineNumber == null ? 0 : cc.correctionChangeLineNumber;
            return c = thisCln.compareTo(thatCln);
        } else {//from  w  w w  .j a va  2s .  c om
            return c;
        }
    } else {
        return c;
    }
}

From source file:org.tinymediamanager.ui.movies.MovieExtendedComparator.java

@Override
public int compare(Movie movie1, Movie movie2) {
    int sortOrder = 0;

    try {/*from   ww  w.ja v a2 s .  c  om*/
        // try to sort the chosen column
        switch (sortColumn) {
        case TITLE:
            sortOrder = stringCollator.compare(movie1.getTitleSortable().toLowerCase(Locale.ROOT),
                    movie2.getTitleSortable().toLowerCase(Locale.ROOT));
            break;

        case SORT_TITLE:
            String title1 = StringUtils.isNotBlank(movie1.getSortTitle()) ? movie1.getSortTitle()
                    : movie1.getTitleSortable();
            String title2 = StringUtils.isNotBlank(movie2.getSortTitle()) ? movie2.getSortTitle()
                    : movie2.getTitleSortable();
            sortOrder = stringCollator.compare(title1.toLowerCase(Locale.ROOT),
                    title2.toLowerCase(Locale.ROOT));
            break;

        case YEAR:
            sortOrder = stringCollator.compare(movie1.getYear(), movie2.getYear());
            break;

        case DATE_ADDED:
            sortOrder = movie1.getDateAdded().compareTo(movie2.getDateAdded());
            break;

        case WATCHED:
            Boolean watched1 = movie1.isWatched();
            Boolean watched2 = movie2.isWatched();
            sortOrder = watched1.compareTo(watched2);
            break;

        case RATING:
            sortOrder = Float.compare(movie1.getRating(), movie2.getRating());
            break;

        case RUNTIME:
            Integer runtime1 = movie1.getRuntime();
            Integer runtime2 = movie2.getRuntime();
            sortOrder = runtime1.compareTo(runtime2);
            break;

        case VIDEO_BITRATE:
            Integer videoBitrate1 = movie1.getMediaInfoVideoBitrate();
            Integer videoBitrate2 = movie2.getMediaInfoVideoBitrate();
            sortOrder = videoBitrate1.compareTo(videoBitrate2);
            break;
        }
    } catch (NullPointerException e) {
        // do nothing here. there could be
    } catch (Exception e) {
        LOGGER.warn(e.getMessage());
    }

    // sort ascending or descending
    if (sortAscending) {
        return sortOrder;
    } else {
        return sortOrder * -1;
    }
}

From source file:org.dspace.EDMExport.service.EDMExportAuthenticationManager.java

/**
 * Autoridades de los permisos que se obtiene al validarse, mirar EDMExport-security.xml
 * /*from w w  w. j a  va2 s  .  c o m*/
 * @param access entero con el tipo de acceso requerido
 * @return Collection<SimpleGrantedAuthority>
 */
public Collection<SimpleGrantedAuthority> getAuthorities(Integer access) {
    List<SimpleGrantedAuthority> authList = new ArrayList<SimpleGrantedAuthority>(2);
    logger.debug("Grant ROLE_USER to this user");
    authList.add(new SimpleGrantedAuthority("ROLE_USER"));
    if (access.compareTo(1) == 0) {
        logger.debug("Grant ROLE_ADMIN to this user");
        authList.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
    }

    return authList;
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.resourceAllocationManager.exams.WrittenEvaluationsSearchByDegreeAndYear.java

private void prepareInformationToList(final ActionForm form, final HttpServletRequest request) {

    DynaActionForm dynaActionForm = (DynaActionForm) form;

    VariantBean bean = getRenderedObject();
    final AcademicInterval academicInterval = (AcademicInterval) bean.getObject();
    request.setAttribute("academicInterval", academicInterval);

    final Boolean selectAllCurricularYears = (Boolean) dynaActionForm.get("selectAllCurricularYears");
    final String[] selectedCurricularYears = (String[]) dynaActionForm.get("selectedCurricularYears");
    final String executionDegreeID = (String) dynaActionForm.get("executionDegreeID");

    final Set<Integer> years = new HashSet<Integer>();
    for (final String yearString : selectedCurricularYears) {
        years.add(Integer.valueOf(yearString));
    }/* w w  w  .  ja va 2s .  c o m*/

    final Map<ExecutionDegree, Map<Integer, Set<ExecutionCourse>>> executionCoursesByCurricularYearByExecutionDegree = new TreeMap<ExecutionDegree, Map<Integer, Set<ExecutionCourse>>>(
            new Comparator<ExecutionDegree>() {
                @Override
                public int compare(ExecutionDegree executionDegree1, ExecutionDegree executionDegree2) {
                    final Degree degree1 = executionDegree1.getDegreeCurricularPlan().getDegree();
                    final Degree degree2 = executionDegree2.getDegreeCurricularPlan().getDegree();
                    return (degree1.getDegreeType() == degree2.getDegreeType())
                            ? degree1.getNome().compareTo(degree2.getNome())
                            : degree1.getDegreeType().compareTo(degree2.getDegreeType());
                }
            });
    for (final ExecutionDegree executionDegree : ExecutionDegree.filterByAcademicInterval(academicInterval)) {
        if (executionDegreeID == null || executionDegreeID.length() == 0
                || executionDegreeID.equals(executionDegree.getExternalId().toString())) {
            final Map<Integer, Set<ExecutionCourse>> executionCoursesByCurricularYear = new TreeMap<Integer, Set<ExecutionCourse>>(
                    new Comparator<Integer>() {
                        @Override
                        public int compare(final Integer curricularYear1, final Integer curricularYear2) {
                            return curricularYear1.compareTo(curricularYear2);
                        }
                    });
            executionCoursesByCurricularYearByExecutionDegree.put(executionDegree,
                    executionCoursesByCurricularYear);
            for (final CurricularCourse curricularCourse : executionDegree.getDegreeCurricularPlan()
                    .getCurricularCoursesSet()) {
                for (final DegreeModuleScope degreeModuleScope : curricularCourse.getDegreeModuleScopes()) {
                    if (degreeModuleScope.isActiveForAcademicInterval(academicInterval)) {
                        final Integer curricularSemester = degreeModuleScope.getCurricularSemester();
                        final Integer curricularYear = degreeModuleScope.getCurricularYear();
                        if (curricularSemester.intValue() == AcademicInterval
                                .getCardinalityOfAcademicInterval(academicInterval)
                                && (selectAllCurricularYears != null && selectAllCurricularYears.booleanValue())
                                || years.contains(curricularYear)) {
                            final Set<ExecutionCourse> executionCourses;
                            if (!executionCoursesByCurricularYear.containsKey(curricularYear)) {
                                executionCourses = new TreeSet<ExecutionCourse>(
                                        new Comparator<ExecutionCourse>() {
                                            @Override
                                            public int compare(final ExecutionCourse executionCourse1,
                                                    final ExecutionCourse executionCourse2) {
                                                return executionCourse1.getNome()
                                                        .compareTo(executionCourse2.getNome());
                                            }
                                        });
                                executionCoursesByCurricularYear.put(curricularYear, executionCourses);
                            } else {
                                executionCourses = executionCoursesByCurricularYear.get(curricularYear);
                            }
                            for (final ExecutionCourse executionCourse : curricularCourse
                                    .getAssociatedExecutionCoursesSet()) {
                                if (academicInterval.equals(executionCourse.getAcademicInterval())) {
                                    executionCourses.add(executionCourse);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    request.setAttribute("executionCoursesByCurricularYearByExecutionDegree",
            executionCoursesByCurricularYearByExecutionDegree);

    request.setAttribute("semester", AcademicInterval.getCardinalityOfAcademicInterval(academicInterval));
}

From source file:com.sequoiadb.hadoop.io.BSONWritableComparator.java

private int compare(BSONObject obj1, BSONObject obj2) {

    Iterator<Entry<String, Object>> iter1 = getIterator(obj1);
    Iterator<Entry<String, Object>> iter2 = getIterator(obj2);

    while (iter1.hasNext()) {
        if (!iter2.hasNext()) {
            return -1;
        }//  ww w .j  a v  a  2  s.c om

        Entry<String, Object> entry1 = iter1.next();
        Entry<String, Object> entry2 = iter2.next();

        int diff = entry1.getKey().compareTo(entry2.getKey());
        if (diff != 0) {
            return diff;
        }

        Object one = entry1.getValue();
        Object two = entry2.getValue();

        if (one == null && two == null) {
            continue;
        }
        if (one == null && two != null) {
            return -1;
        }
        if (one != null && two == null) {
            return 1;
        } else {

            Integer oneValue = types.get(one.getClass());
            Integer twoValue = types.get(two.getClass());
            diff = oneValue.compareTo(twoValue);
            if (diff != 0) {
                return diff;
            }

            diff = compareValues(one, two);

            if (diff != 0) {
                return diff;
            }
        }

    }

    if (iter2.hasNext()) {
        return 1;
    }

    return 0;
}

From source file:org.kuali.rice.krms.impl.type.KrmsTypeServiceBase.java

protected void sortFields(List<TypeAttributeDefinition> results, final Map<String, Integer> sortCodeMap) {// sort the results
    Collections.sort(results, new Comparator<TypeAttributeDefinition>() {
        @Override//from   w ww . ja v  a 2  s  . c  o m
        public int compare(TypeAttributeDefinition o1, TypeAttributeDefinition o2) {
            if (o1 == o2 || o1.equals(o2))
                return 0;
            // we assume that each has a sort code based on our previous check
            Integer o1SortCode = sortCodeMap.get(o1.getName());
            Integer o2SortCode = sortCodeMap.get(o2.getName());

            if (o1SortCode.compareTo(o2SortCode) != 0) {
                return o1SortCode.compareTo(o2SortCode);
            } else {
                // if sort codes are the same, we still would like a consistent order
                return o1.getName().compareTo(o2.getName());
            }
        }
    });
}

From source file:net.sourceforge.vulcan.core.support.DependencyGroupImpl.java

private int compareTargets(BuildTarget lhs, BuildTarget rhs) {
    final Integer numProjectsDependingOnLhs = dependencyCounts.get(lhs.getProjectName());
    final Integer numProjectsDependingOnRhs = dependencyCounts.get(rhs.getProjectName());

    int signum = numProjectsDependingOnRhs.compareTo(numProjectsDependingOnLhs);

    if (signum != 0) {
        return signum;
    }/*from  www . j a v  a 2s.  c om*/

    if (lhs.dependsOn(rhs)) {
        return 1;
    }

    if (rhs.dependsOn(lhs)) {
        return -1;
    }

    signum = ((Integer) lhs.getNumberOfPendingDependencies()).compareTo(rhs.getNumberOfPendingDependencies());

    return signum;
}

From source file:com.feilong.core.lang.StringUtilTest.java

/**
 * Compare to.//from  ww w  .j  a  v  a 2s . co m
 */
@Test
public void compareTo() {
    LOGGER.debug("" + "8".compareTo("13"));
    Integer parseInt = Integer.parseInt("8");
    LOGGER.debug("" + parseInt.compareTo(Integer.parseInt("13")));
    LOGGER.debug("" + "10".compareTo("13"));
}

From source file:org.sakaiproject.importer.impl.handlers.SamigoPoolHandler.java

public void handle(Importable thing, String siteId) {
    QuestionPool importPool = (QuestionPool) thing;
    QuestionPoolFacade pool = new QuestionPoolFacade();
    pool.setOwnerId(SessionManager.getCurrentSessionUserId());
    pool.setTitle(importPool.getTitle());
    pool.setDescription(importPool.getDescription());
    // have no idea what the magic number 30 is for, but Samigo used it when I created a question pool in the tool
    pool.setAccessTypeId(Long.valueOf(30));
    Set questionItems = new HashSet();
    questionItems.addAll(doQuestions(importPool.getEssayQuestions(), siteId));
    questionItems.addAll(doQuestions(importPool.getFillBlankQuestions(), siteId));
    questionItems.addAll(doQuestions(importPool.getMatchQuestions(), siteId));
    questionItems.addAll(doQuestions(importPool.getMultiAnswerQuestions(), siteId));
    questionItems.addAll(doQuestions(importPool.getMultiChoiceQuestions(), siteId));
    // Samigo doesn't have native support for ordering questions. Maybe there's a workaround?
    // questionItems.addAll(doQuestions(importPool.getOrderingQuestions()));
    questionItems.addAll(doQuestions(importPool.getTrueFalseQuestions(), siteId));
    QuestionPoolFacade savedPool = qps.savePool(pool);

    Object[] questionItemsArray = questionItems.toArray();
    Arrays.sort(questionItemsArray, new Comparator() {
        public int compare(Object o1, Object o2) {
            Integer i1 = ((ItemFacade) o1).getSequence();
            Integer i2 = ((ItemFacade) o2).getSequence();
            return i1.compareTo(i2);
        }/*w ww. ja v  a 2s .c om*/
    });
    for (int i = 0; i < questionItemsArray.length; i++) {
        ItemFacade item = (ItemFacade) questionItemsArray[i];
        item.setSequence(Integer.valueOf(i + 1));
        qps.addItemToPool(item.getItemId(), savedPool.getQuestionPoolId());
    }
}

From source file:org.stem.db.MountPoint.java

public Collection<FatFile> findFull() {
    Collection<FatFile> collection = CollectionUtils.select(fatFiles.values(), new Predicate<FatFile>() {
        @Override/*from  w ww .  j a  v  a2  s  .  c  o  m*/
        public boolean evaluate(FatFile file) {
            return file.isFull();
        }
    });

    List<FatFile> sortedList = new ArrayList<FatFile>(collection);

    Collections.sort(sortedList, new Comparator<FatFile>() {
        @Override
        public int compare(FatFile f1, FatFile f2) {
            if (f1.getState() == f2.getState())
                return f1.id.compareTo(f2.id);

            else {
                Integer state1 = f1.getState().ordinal();
                Integer state2 = f2.getState().ordinal();
                return state1.compareTo(state2);
            }
        }
    });

    return sortedList;
}