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.jahia.utils.maven.plugin.contentgenerator.wise.WiseService.java

public String generateWise(ExportBO wiseExport) throws IOException {
    OutputService os = new OutputService();
    UserGroupService userGroupService = new UserGroupService();
    SiteService siteService = new SiteService();
    TagService tagService = new TagService();
    List<File> globalFilesToZip = new ArrayList<File>();

    // System site and categories
    Document systemSiteRepository = siteService.createSystemSiteRepository();

    // Creates tags
    Element tagsList = tagService.createTagListElement();
    List<TagBO> tags = tagService.createTagsBO(wiseExport.getNumberOfTags());
    wiseExport.setTags(tags);//from w ww . ja  v a2 s. c o  m
    for (TagBO tag : tags) {
        tagsList.addContent(tag.getTagElement());
    }

    // Wise instance files
    // Light users for the privileges groups 
    List<UserBO> users = userGroupService.generateUsers(wiseExport.getNumberOfUsers(), 0, 0, 0);
    WiseBO wiseInstance = generateWiseInstance(wiseExport, users);

    File wiseInstanceOutputDir = new File(wiseExport.getOutputDir() + "/wise");
    File wiseInstanceContentDir = new File(wiseInstanceOutputDir + "/content");

    wiseInstanceOutputDir.mkdir();
    logger.info("Creating repository file");

    insertWiseInstanceIntoSiteRepository(systemSiteRepository, wiseInstance.getElement());
    insertTagsListIntoWiseInstance(systemSiteRepository, tagsList, wiseExport.getSiteKey());

    CategoryService cs = new CategoryService();
    Element categories = cs.createCategories(wiseExport.getNumberOfCategories(),
            wiseExport.getNumberOfCategoryLevels(), wiseExport);
    cs.insertCategoriesIntoSiteRepository(systemSiteRepository, categories);

    File repositoryFile = new File(wiseInstanceOutputDir + "/repository.xml");
    os.writeJdomDocumentToFile(systemSiteRepository, repositoryFile);

    // create properties file
    logger.info("Creating site properties file");
    siteService.createPropertiesFile(wiseExport.getSiteKey(), wiseExport.getSiteLanguages(), "templates-wise",
            wiseInstanceOutputDir);

    // Zip wise instances files
    List<File> wiseInstanceFiles = new ArrayList<File>(FileUtils.listFiles(wiseInstanceOutputDir, null, false));
    if (wiseInstanceContentDir.exists()) {
        wiseInstanceFiles.add(wiseInstanceContentDir);
    }

    logger.info("Creating Wise site archive");
    File wiseArchive = os.createSiteArchive("wise.zip", wiseExport.getOutputDir(), wiseInstanceFiles);
    globalFilesToZip.add(wiseArchive);

    // Users
    Integer nbCollectionsPerUser = wiseExport.getNbCollectionsPerUser();
    Integer nbFilesPerCollection = wiseExport.getNbFilesPerCollection();
    // If there is not enough files we use all the files and that's it.
    if (nbFilesPerCollection.compareTo(wiseExport.getNbFilesPerFolder()) > 0) {
        nbFilesPerCollection = wiseExport.getNbFilesPerFolder();
    }
    logger.info("Creating users");
    users = userGroupService.generateUsers(wiseExport.getNumberOfUsers(), nbCollectionsPerUser,
            nbFilesPerCollection, wiseExport.getNbFilesPerFolder());
    File tmpUsers = new File(wiseExport.getOutputDir(), "users");
    tmpUsers.mkdir();

    File repositoryUsers = new File(tmpUsers, "repository.xml");
    Document usersRepositoryDocument = userGroupService.createUsersRepository(users);
    os.writeJdomDocumentToFile(usersRepositoryDocument, repositoryUsers);

    List<File> filesToZip = new ArrayList<File>();
    File contentUsers = userGroupService.createFileTreeForUsers(users, tmpUsers);

    filesToZip.add(repositoryUsers);
    filesToZip.add(contentUsers);
    File usersArchive = os.createSiteArchive("users.zip", wiseExport.getOutputDir(), filesToZip);
    globalFilesToZip.add(usersArchive);

    // Zip all of this
    logger.info("Creating Wise instance archive");
    File wiseImportArchive = os.createSiteArchive("wise_instance_generated.zip", wiseExport.getOutputDir(),
            globalFilesToZip);

    // Generate users list
    logger.info("Generating users, files and tags lists");
    List<String> userNames = new ArrayList<String>();
    List<String> collections = new ArrayList<String>();
    for (UserBO user : users) {
        userNames.add(user.getName());

        for (CollectionBO collection : user.getCollections()) {
            collections.add(collection.getTitle());
        }
    }
    File usersFile = new File(wiseExport.getOutputDir(), "users.txt");
    usersFile.delete();
    os.appendPathToFile(usersFile, userNames);

    // File collectionsFile = new File(wiseExport.getOutputDir(),
    // "collections.txt");
    // collectionsFile.delete();
    // os.appendPathToFile(collectionsFile, collections);

    // Generate files list
    List<String> filePaths = new ArrayList<String>();
    for (DocspaceBO docspace : wiseInstance.getDocspaces()) {
        filePaths.addAll(getFilePaths(docspace.getFolders()));
    }

    File filePathsFile = new File(wiseExport.getOutputDir(), "files.txt");
    filePathsFile.delete();
    os.appendPathToFile(filePathsFile, filePaths);

    // Generate tags list
    List<String> tagNames = new ArrayList<String>();
    for (TagBO tag : tags) {
        tagNames.add(tag.getTagName());
    }

    File tagsFile = new File(wiseExport.getOutputDir(), "tags.txt");
    tagsFile.delete();
    os.appendPathToFile(tagsFile, tagNames);

    return wiseImportArchive.getAbsolutePath();
}

From source file:com.moss.launch.tools.Scorecard.java

public int compareTo(Scorecard o) {
    final Integer scoreA = baseScore();
    final Integer scoreB = o.baseScore();

    if (scoreA == scoreB) {
        return osUpdateMatch.compareTo(o.osUpdateMatch) + vmVersionMatch.compareTo(vmVersionMatch)
                + javaPlatformMatch.compareTo(javaPlatformMatch);
    } else {//from   w w w .j a v a 2s  .  c  om
        return scoreA.compareTo(scoreB);
    }
}

From source file:org.libreplan.business.workreports.entities.WorkReportType.java

private boolean isValidIndexToMove(Integer position, List<Object> list) {
    return position.compareTo(0) >= 0 && position.compareTo(list.size()) < 0;
}

From source file:org.libreplan.business.workreports.entities.WorkReportType.java

private boolean isValidIndexToAdd(Integer position, List<Object> list) {
    return position.compareTo(0) >= 0 && position.compareTo(list.size()) <= 0;
}

From source file:dk.sdu.mmmi.featureous.views.featurecharacterization.FeatureViewChart.java

private void doItForPkg(boolean uniformSize) {
    // Sort according to category rank
    Set<String> pkgsSet = new HashSet<String>();
    List<String> pkgss = new ArrayList<String>();
    for (TraceModel tm : ftms) {
        for (ClassModel cm : tm.getClassSet()) {
            pkgsSet.add(cm.getPackageName());
        }/* w  ww  .  j a v  a 2 s. c om*/
    }
    pkgss.addAll(pkgsSet);
    Collections.sort(pkgss, new Comparator<String>() {

        public int compare(String o1, String o2) {
            Integer o1r = Controller.getInstance().getAffinity().getPkgAffinity(o1).weigth;
            Integer o2r = Controller.getInstance().getAffinity().getPkgAffinity(o2).weigth;
            return o1r.compareTo(o2r);
        }
    });
    // Insert data
    for (String cm : pkgss) {
        for (Result r : scattering) {
            TraceModel tm = null;
            for (TraceModel t : ftms) {
                if (t.getName().equals(r.name)) {
                    tm = t;
                    break;
                }
            }
            Set<String> pkgs = new HashSet<String>();
            for (ClassModel c : tm.getClassSet()) {
                pkgs.add(c.getPackageName());
            }

            if (!pkgs.contains(cm)) {
                continue;
            }
            Controller c = Controller.getInstance();
            double val = 0d;
            if (uniformSize) {
                val = 1f / pkgs.size();
            } else {
                val = r.value / pkgs.size();
            }
            data.addValue(val, cm, r.name);
        }
    }
    Controller c = Controller.getInstance();
    for (int i = 0; i < data.getRowCount(); i++) {
        for (String pk : pkgss) {
            if (pk.equals(data.getRowKey(i).toString())) {
                Color col = Controller.getInstance().getAffinity().getPkgAffinity(pk).color;
                plot.getRenderer().setSeriesPaint(i, col);
                plot.getRenderer().setSeriesOutlinePaint(i, col);
                break;
            }
        }
    }
}

From source file:org.libreplan.business.qualityforms.entities.QualityForm.java

@SuppressWarnings("unused")
@AssertTrue(message = "The quality form item positions must be unique and consecutive.")
public boolean isConsecutivesAndUniquesQualityFormItemPositionsConstraint() {
    List<QualityFormItem> result = getListToNull(qualityFormItems);
    for (QualityFormItem qualityFormItem : qualityFormItems) {
        // Check if index is out of range
        Integer index = qualityFormItem.getPosition();

        if (index == null) {
            return false;
        }/*from www  .j a  v a 2s  .c  o m*/

        if ((index.compareTo(0) < 0) || (index.compareTo(result.size()) >= 0)) {
            return false;
        }
        // Check if index is repeated
        if (result.get(index) != null) {
            return false;
        }
        result.set(index, qualityFormItem);
    }

    // Check if the indexs are consecutives
    for (QualityFormItem item : result) {
        if (item == null) {
            return false;
        }
    }
    return true;
}

From source file:com.sonymobile.backlogtool.Story.java

/**
 * Rebuilds the priority order of the children
 * in case one or more tasks were removed.
 *//*w  w  w  .  jav a  2  s  .  c  o  m*/
public void rebuildChildrenOrder() {
    List<Task> taskList = new ArrayList<Task>();
    taskList.addAll(children);
    Collections.sort(taskList, new Comparator<Task>() {

        @Override
        public int compare(Task task1, Task task2) {
            Integer value1 = new Integer(task1.getPrioInStory());
            Integer value2 = new Integer(task2.getPrioInStory());
            return value1.compareTo(value2);
        }
    });

    int prioCounter = 1;
    for (Task task : taskList) {
        task.setPrioInStory(prioCounter++);
    }
}

From source file:org.libreplan.business.workreports.entities.WorkReportType.java

private boolean validateTheIndexFieldsAndLabels(List<Object> listFieldsAndLabels) {
    List<Object> result = getListToNull(listFieldsAndLabels);
    for (Object object : listFieldsAndLabels) {

        // Check if index is out of range
        Integer index = getIndex(object);
        if ((index.compareTo(0) < 0) || (index.compareTo(result.size()) >= 0)) {
            return false;
        }/*from ww  w  .  j a  v a  2  s .  c  om*/

        // Check if index is repeated
        if (result.get(getIndex(object)) != null) {
            return false;
        }

        result.set(getIndex(object), object);
    }

    // Check if the indexes are consecutive
    for (Object object : result) {
        if (object == null) {
            return false;
        }
    }

    return true;
}

From source file:io.apiman.manager.test.junit.ManagerRestTester.java

/**
 * Loads the test plans./*from  w  w w . j av  a  2s  .  co  m*/
 * @param testClass
 * @throws InitializationError
 */
private void loadTestPlans(Class<?> testClass) throws InitializationError {
    try {
        ManagerRestTestPlan annotation = testClass.getAnnotation(ManagerRestTestPlan.class);
        if (annotation == null) {
            Method[] methods = testClass.getMethods();
            TreeSet<ManagerRestTestPlan> annotations = new TreeSet<>(new Comparator<ManagerRestTestPlan>() {
                @Override
                public int compare(ManagerRestTestPlan o1, ManagerRestTestPlan o2) {
                    Integer i1 = o1.order();
                    Integer i2 = o2.order();
                    return i1.compareTo(i2);
                }
            });
            for (Method method : methods) {
                annotation = method.getAnnotation(ManagerRestTestPlan.class);
                if (annotation != null) {
                    annotations.add(annotation);
                }
            }
            for (ManagerRestTestPlan anno : annotations) {
                TestPlanInfo planInfo = new TestPlanInfo();
                planInfo.planPath = anno.value();
                planInfo.name = new File(planInfo.planPath).getName();
                planInfo.endpoint = TestUtil.doPropertyReplacement(anno.endpoint());
                planInfo.plan = TestUtil.loadTestPlan(planInfo.planPath, testClass.getClassLoader());
                testPlans.add(planInfo);
            }
        } else {
            TestPlanInfo planInfo = new TestPlanInfo();
            planInfo.planPath = annotation.value();
            planInfo.name = new File(planInfo.planPath).getName();
            planInfo.plan = TestUtil.loadTestPlan(planInfo.planPath, testClass.getClassLoader());
            planInfo.endpoint = TestUtil.doPropertyReplacement(annotation.endpoint());
            testPlans.add(planInfo);
        }
    } catch (Throwable e) {
        throw new InitializationError(e);
    }

    if (testPlans.isEmpty()) {
        throw new InitializationError("No @ManagerRestTestPlan annotations found on test class: " + testClass);
    }
}

From source file:com.diversityarrays.kdxplore.stats.CategoricalSimpleStatistics.java

public CategoricalSimpleStatistics(String statsName, List<KdxSample> sampleMeasurements,
        CategoricalTraitValidationProcessor tvp) {
    super(statsName, String.class);

    nSampleMeasurements = sampleMeasurements.size();

    Bag<String> svalues = new HashBag<>();
    List<String> values = new ArrayList<>(nSampleMeasurements);

    for (KdxSample sm : sampleMeasurements) {
        String traitValue = sm.getTraitValue();
        switch (TraitValue.classify(traitValue)) {
        case NA:/* w w  w.  j a v a  2 s  .  com*/
            ++nNA;
            break;
        case SET:
            Either<TraitValueType, String> either = tvp.isTraitValueValid(traitValue);
            if (either.isRight()) {
                String tv = either.right();
                if (tv == null) {
                    ++nMissing;
                } else {
                    values.add(tv);
                }
            } else {
                ++nInvalid;
            }
            break;
        case MISSING:
        case UNSET:
        default:
            ++nMissing;
            break;
        }
    }

    nValidValues = values.size();
    switch (nValidValues) {
    case 0:
        minValue = null;
        maxValue = null;
        mode = null;
        median = null;
        break;
    case 1:
        mode = values.get(0);
        median = mode;
        minValue = mode;
        maxValue = mode;
        break;
    default:
        Map<String, Integer> orderByChoice = new HashMap<>();
        int order = 0;
        for (String choice : tvp.getChoices()) {
            orderByChoice.put(choice, ++order);
        }
        Comparator<String> comparator = new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                Integer lft = orderByChoice.get(o1);
                if (lft == null) {
                    lft = 0;
                }
                Integer ryt = orderByChoice.get(o2);
                if (ryt == null) {
                    ryt = 0;
                }
                return lft.compareTo(ryt);
            }
        };
        Collections.sort(values, comparator);

        minValue = values.get(0);
        maxValue = values.get(values.size() - 1);
        median = StatsUtil.computeStringMedian(values);
        // TODO q1, q3

        List<String> modes = StatsUtil.computeMode(svalues, null);

        StringBuilder sb = new StringBuilder();
        String sep = "";
        for (String s : modes) {
            sb.append(sep);
            if (tvp == null) {
                sb.append(s);
            } else {
                Either<TraitValueType, String> either = tvp.isTraitValueValid(s);
                if (either.isRight()) {
                    sb.append(either.right());
                } else {
                    sb.append(s);
                }
            }
            sep = " , ";
        }
        mode = sb.toString();
        break;
    }
}