Example usage for java.util Collections reverseOrder

List of usage examples for java.util Collections reverseOrder

Introduction

In this page you can find the example usage for java.util Collections reverseOrder.

Prototype

@SuppressWarnings("unchecked")
public static <T> Comparator<T> reverseOrder() 

Source Link

Document

Returns a comparator that imposes the reverse of the natural ordering on a collection of objects that implement the Comparable interface.

Usage

From source file:com.izforge.izpack.uninstaller.resource.InstallLog.java

/**
 * Returns the installed files, in leaf first order.
 *
 * @param reader the <em>install.log</em> reader
 * @return the installed files// w ww.  j  a  v a 2 s. c o m
 * @throws IOException for any I/O error
 */
private List<File> getFiles(BufferedReader reader) throws IOException {
    TreeSet<File> files = new TreeSet<File>(Collections.reverseOrder());
    String read = reader.readLine();
    while (read != null) {
        files.add(new File(read));
        read = reader.readLine();
    }

    // We return it
    return new ArrayList<File>(files);
}

From source file:org.evosuite.testcase.ConstantInliner.java

/**
 * Remove all unreferenced variables//from ww  w. ja v a2 s.  c  o  m
 * 
 * @param t
 *            The test case
 * @return True if something was deleted
 */
public boolean removeUnusedVariables(TestCase t) {
    List<Integer> toDelete = new ArrayList<Integer>();
    boolean hasDeleted = false;

    int num = 0;
    for (Statement s : t) {
        if (s instanceof PrimitiveStatement) {

            VariableReference var = s.getReturnValue();
            if (!t.hasReferences(var)) {
                toDelete.add(num);
                hasDeleted = true;
            }
        }
        num++;
    }
    Collections.sort(toDelete, Collections.reverseOrder());
    for (Integer position : toDelete) {
        t.remove(position);
    }

    return hasDeleted;
}

From source file:io.github.bonigarcia.wdm.BrowserManager.java

public String forceCache(String repository) {
    String driverInCache = null;/*  www  .j a v a 2s .c  o m*/
    for (String driverName : getDriverName()) {
        log.trace("Checking if {} exists in cache {}", driverName, repository);

        Collection<File> listFiles = FileUtils.listFiles(new File(repository), null, true);
        Object[] array = listFiles.toArray();
        Arrays.sort(array, Collections.reverseOrder());

        for (Object f : array) {
            driverInCache = f.toString();
            log.trace("Checking {}", driverInCache);
            if (driverInCache.contains(driverName)) {
                log.info("Found {} in cache: {} ", driverName, driverInCache);
                break;
            } else {
                driverInCache = null;
            }
        }

        if (driverInCache == null) {
            log.trace("{} do not exist in cache {}", driverName, repository);
        } else {
            break;
        }
    }
    return driverInCache;
}

From source file:org.sample.whiteboardapp.MyWhiteboard.java

static JSONObject findKNN(double[] Qpoint, Node root, int k) {
    JSONObject coordinates = new JSONObject();
    JSONArray lat_json = new JSONArray();
    JSONArray long_json = new JSONArray();
    PriorityQueue<Double> pq = new PriorityQueue<Double>(10, Collections.reverseOrder());
    HashMap<Double, Node> hm = new HashMap();
    searchKDSubtree(pq, hm, root, Qpoint, k, 0);
    System.out.println(pq.size());
    while (pq.size() != 0) {
        Node ans = hm.get(pq.poll());
        System.out.println(ans.point[0] + " " + ans.point[1]);
        System.out.println(pq.size());
        lat_json.add(ans.point[0]);/*  w  ww  . j  av a  2s.  c  o m*/
        long_json.add(ans.point[1]);

    }
    coordinates.put("latitude", lat_json);
    coordinates.put("longitude", long_json);
    return coordinates;

}

From source file:org.jactr.eclipse.ui.wizards.templates.DefaultACTRContributorTemplateSection.java

/**
 * stupid cosmetic bit to reorder the classpath entries so that models/,
 * java/, conf/ appear first/*w  w  w  . j  a v  a 2  s.  c o  m*/
 * 
 * @throws CoreException
 */
private void sortEntries() throws CoreException {
    IJavaProject javaProject = JavaCore.create(project);

    IClasspathEntry[] oldEntries = javaProject.getRawClasspath();
    SortedMap<String, IClasspathEntry> sortedMap = new TreeMap<String, IClasspathEntry>(
            Collections.reverseOrder());

    for (IClasspathEntry entry : oldEntries) {
        String name = entry.getPath().lastSegment();
        if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE
                && entry.getEntryKind() != IClasspathEntry.CPE_LIBRARY)
            name = "a" + name;
        sortedMap.put(name, entry);
    }

    oldEntries = sortedMap.values().toArray(oldEntries);
    javaProject.setRawClasspath(oldEntries, null);
}

From source file:org.codehaus.mojo.dbupgrade.sqlexec.DefaultSQLExec.java

/**
 * Sort the transaction list.//from  www  . j  a v a2 s.c  om
 */
private void sortTransactions(List<Transaction> transactions) {
    if (SQLExecConfig.FILE_SORTING_ASC.equalsIgnoreCase(this.config.getOrderFile())) {
        Collections.sort(transactions);
    } else if (SQLExecConfig.FILE_SORTING_DSC.equalsIgnoreCase(this.config.getOrderFile())) {
        Collections.sort(transactions, Collections.reverseOrder());
    }
}

From source file:serposcope.controllers.admin.LogController.java

protected String[] getLogFiles() {
    File logDir = new File(conf.logdir);

    String[] logs = logDir.list();
    if (logs == null) {
        logs = new String[0];
    } else {//from  ww w .j a va  2s .  c  om
        Arrays.sort(logs, Collections.reverseOrder());
    }

    return logs;
}

From source file:org.searsia.SearchResult.java

public void scoreResourceSelection(String query, ResourceIndex engines) {
    final float bias = 1.0f;
    Map<String, Float> maxScore = new HashMap<String, Float>();
    Map<String, Float> topEngines = engines.topValues(query, 20);
    for (Hit hit : this.hits) {
        String rid = hit.getString("rid");
        if (rid != null) {
            float prior = 0.0f;
            if (engines.containsKey(rid)) {
                prior = engines.get(rid).getPrior();
            }//w ww  .ja v a  2  s.com
            float score = hit.getScore() * bias + prior;
            Float top = topEngines.get(rid);
            if (top != null) {
                if (top > score) {
                    score = top;
                }
                topEngines.remove(rid);
            }
            Float max = maxScore.get(rid);
            if (max == null || max < score) {
                maxScore.put(rid, score);
                max = score;
            }
            hit.setScore(score);
            //hit.put("rscore", max);
        }
    }
    for (String rid : topEngines.keySet()) {
        Hit hit = new Hit();
        hit.put("rid", rid);
        hit.setScore(topEngines.get(rid));
        //hit.put("rscore", topEngines.get(rid));
        this.hits.add(hit);
    }
    Collections.sort(this.hits, Collections.reverseOrder());
}

From source file:org.bbreak.excella.reports.tag.ImageParamParserTest.java

/**
 * {@link org.bbreak.excella.reports.tag.ImageParamParser#parse(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell, java.lang.Object)} ????
 *//*  w w  w.  j a  v  a2 s . c om*/
@Test
public void testParseSheetCellObject() {
    // -----------------------
    // []?
    // -----------------------
    Workbook workbook = getWorkbook();

    Sheet sheet1 = workbook.getSheetAt(0);

    ImageParamParser parser = new ImageParamParser();

    ReportsParserInfo reportsParserInfo = new ReportsParserInfo();
    reportsParserInfo.setParamInfo(createTestData(ImageParamParser.DEFAULT_TAG));

    try {
        parseSheet(parser, sheet1, reportsParserInfo);
    } catch (ParseException e) {
        fail(e.toString());
    }

    // ???
    Set<Integer> delSheetIndexs = new TreeSet<Integer>(Collections.reverseOrder());
    for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
        if (i != 0) {
            delSheetIndexs.add(i);
        }
    }
    for (Integer i : delSheetIndexs) {
        workbook.removeSheetAt(i);
    }

    // ???
    Workbook expectedWorkbook = getExpectedWorkbook();
    Sheet expectedSheet = expectedWorkbook.getSheet("Sheet1");

    try {
        // ?
        ReportsTestUtil.checkSheet(expectedSheet, sheet1, false);
    } catch (ReportsCheckException e) {
        fail(e.getCheckMessagesToString());

    } finally {
        // ?????????????
        String tmpDirPath = System.getProperty("user.dir") + "/work/test/"; // System.getProperty( "java.io.tmpdir");
        File file = new File(tmpDirPath);
        if (!file.exists()) {
            file.mkdirs();
        }

        try {
            String filepath = null;
            if (version.equals("2007")) {
                filepath = tmpDirPath + "ImageParamParserTest1.xlsx";
            } else {
                filepath = tmpDirPath + "ImageParamParserTest1.xls";
            }
            PoiUtil.writeBook(workbook, filepath);
            log.info("????????" + filepath);

        } catch (IOException e) {
            fail(e.toString());
        }
    }

    // -----------------------
    // []
    // -----------------------
    workbook = getWorkbook();

    Sheet sheet2 = workbook.getSheetAt(1);

    parser = new ImageParamParser("$Image");

    reportsParserInfo = new ReportsParserInfo();
    reportsParserInfo.setParamInfo(createTestData("$Image"));

    try {
        parseSheet(parser, sheet2, reportsParserInfo);
    } catch (ParseException e) {
        fail(e.toString());
    }

    // ???
    delSheetIndexs.clear();
    for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
        if (i != 1) {
            delSheetIndexs.add(i);
        }
    }
    for (Integer i : delSheetIndexs) {
        workbook.removeSheetAt(i);
    }

    // ???
    expectedWorkbook = getExpectedWorkbook();
    expectedSheet = expectedWorkbook.getSheet("Sheet2");

    try {
        // ?
        ReportsTestUtil.checkSheet(expectedSheet, sheet2, false);
    } catch (ReportsCheckException e) {
        fail(e.getCheckMessagesToString());
    } finally {
        // ?????????????
        String tmpDirPath = System.getProperty("user.dir") + "/work/test/"; // System.getProperty( "java.io.tmpdir");;
        File file = new File(tmpDirPath);
        if (!file.exists()) {
            file.mkdir();
        }
        try {
            String filepath = null;
            if (version.equals("2007")) {
                filepath = tmpDirPath + "ImageParamParserTest2.xlsx";
            } else {
                filepath = tmpDirPath + "ImageParamParserTest2.xls";
            }
            PoiUtil.writeBook(workbook, filepath);
            log.info("????????" + filepath);

        } catch (IOException e) {
            fail(e.toString());
        }
    }

    String filename = this.getClass().getSimpleName();
    if (version.equals("2007")) {
        filename = filename + "_err.xlsx";
    } else if (version.equals("2003")) {
        filename = filename + "_err.xls";
    }

    URL url = this.getClass().getResource(filename);
    String path = null;
    try {
        path = URLDecoder.decode(url.getFile(), "UTF-8");

    } catch (UnsupportedEncodingException e) {
        Assert.fail();
    }

    // -----------------------
    // []?
    // -----------------------
    workbook = getWorkbook(path);

    Sheet sheet3 = workbook.getSheetAt(2);

    parser = new ImageParamParser();

    reportsParserInfo = new ReportsParserInfo();
    reportsParserInfo.setParamInfo(createTestData(ImageParamParser.DEFAULT_TAG));

    try {
        parseSheet(parser, sheet3, reportsParserInfo);
        fail("?????????");
    } catch (ParseException e) {
    }

    // -----------------------
    // []????
    // -----------------------
    workbook = getWorkbook();

    Sheet sheet4 = workbook.getSheetAt(2);

    parser = new ImageParamParser();

    reportsParserInfo = new ReportsParserInfo();
    reportsParserInfo.setParamInfo(createTestData(ImageParamParser.DEFAULT_TAG));

    try {
        parseSheet(parser, sheet4, reportsParserInfo);
    } catch (ParseException e) {
        fail(e.toString());
    }

    // ???
    expectedWorkbook = getExpectedWorkbook();
    expectedSheet = expectedWorkbook.getSheet("Sheet4");

    try {
        // ?
        ReportsTestUtil.checkSheet(expectedSheet, sheet4, false);
    } catch (ReportsCheckException e) {
        fail(e.getCheckMessagesToString());
    }

    // ----------------------------------------------------------------------
    // []1 / ?? / ???
    // ----------------------------------------------------------------------
    workbook = getWorkbook();

    Sheet sheet5 = workbook.getSheetAt(INDEX_OF_SHEET5);

    parser = new ImageParamParser();

    reportsParserInfo = new ReportsParserInfo();
    reportsParserInfo.setParamInfo(createPluralTestData(ImageParamParser.DEFAULT_TAG));

    try {
        parseSheet(parser, sheet5, reportsParserInfo);
    } catch (ParseException e) {
        fail(e.toString());
    }

    // ???
    delSheetIndexs.clear();
    for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
        if (i != INDEX_OF_SHEET5) {
            delSheetIndexs.add(i);
        }
    }
    for (Integer i : delSheetIndexs) {
        workbook.removeSheetAt(i);
    }

    // ???
    expectedWorkbook = getExpectedWorkbook();
    expectedSheet = expectedWorkbook.getSheet("Sheet5");

    try {
        // ?
        ReportsTestUtil.checkSheet(expectedSheet, sheet5, false);
    } catch (ReportsCheckException e) {
        fail(e.getCheckMessagesToString());
    } finally {
        // ?????????????
        String tmpDirPath = System.getProperty("user.dir") + "/work/test/"; // System.getProperty( "java.io.tmpdir");
        File file = new File(tmpDirPath);
        if (!file.exists()) {
            file.mkdirs();
        }

        try {
            String filepath = null;
            if (version.equals("2007")) {
                filepath = tmpDirPath + "ImageParamParserTest3.xlsx";
            } else {
                filepath = tmpDirPath + "ImageParamParserTest3.xls";
            }
            PoiUtil.writeBook(workbook, filepath);
            log.info("????????" + filepath);

        } catch (IOException e) {
            fail(e.toString());
        }
    }

    // ----------------------------------------------------------------------
    // []1 / ?? / ?1
    // ----------------------------------------------------------------------

    workbook = getWorkbook();

    Sheet sheet6 = workbook.cloneSheet(INDEX_OF_SHEET5);

    parser = new ImageParamParser();

    reportsParserInfo = new ReportsParserInfo();
    reportsParserInfo.setParamInfo(createPluralTestData(ImageParamParser.DEFAULT_TAG));

    try {
        parseSheet(parser, sheet6, reportsParserInfo);
    } catch (ParseException e) {
        fail(e.toString());
    }

    // ???
    delSheetIndexs.clear();
    for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
        if (i != workbook.getNumberOfSheets() - 1) {
            delSheetIndexs.add(i);
        }
    }
    for (Integer i : delSheetIndexs) {
        workbook.removeSheetAt(i);
    }

    // ???
    expectedWorkbook = getExpectedWorkbook();
    expectedSheet = expectedWorkbook.cloneSheet(INDEX_OF_SHEET5);

    try {
        // ?
        ReportsTestUtil.checkSheet(expectedSheet, sheet6, false);
    } catch (ReportsCheckException e) {
        fail(e.getCheckMessagesToString());
    } finally {
        // ?????????????
        String tmpDirPath = System.getProperty("user.dir") + "/work/test/"; // System.getProperty( "java.io.tmpdir");
        File file = new File(tmpDirPath);
        if (!file.exists()) {
            file.mkdirs();
        }

        try {
            String filepath = null;
            if (version.equals("2007")) {
                filepath = tmpDirPath + "ImageParamParserTest4.xlsx";
            } else {
                filepath = tmpDirPath + "ImageParamParserTest4.xls";
            }
            PoiUtil.writeBook(workbook, filepath);
            log.info("????????" + filepath);

        } catch (IOException e) {
            fail(e.toString());
        }
    }

    // ----------------------------------------------------------------------
    // []  / ?? / ?
    // ----------------------------------------------------------------------

    workbook = getWorkbook();

    for (int i = 1; i <= PLURAL_COPY_FIRST_NUM_OF_SHEETS; i++) {

        Sheet sheet = workbook.cloneSheet(INDEX_OF_SHEET5);

        parser = new ImageParamParser();

        reportsParserInfo = new ReportsParserInfo();
        reportsParserInfo.setParamInfo(createPluralTestData(ImageParamParser.DEFAULT_TAG));

        try {
            parseSheet(parser, sheet, reportsParserInfo);
        } catch (ParseException e) {
            fail(e.toString());
        }
    }

    // ???
    delSheetIndexs.clear();
    for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
        if (i < workbook.getNumberOfSheets() - PLURAL_COPY_FIRST_NUM_OF_SHEETS) {
            delSheetIndexs.add(i);
        }
    }
    for (Integer i : delSheetIndexs) {
        workbook.removeSheetAt(i);
    }

    // ???
    expectedWorkbook = getExpectedWorkbook();
    for (int i = 1; i <= PLURAL_COPY_FIRST_NUM_OF_SHEETS; i++) {
        expectedSheet = expectedWorkbook.cloneSheet(INDEX_OF_SHEET5);
    }

    try {
        int startOfTargetSheet = expectedWorkbook.getNumberOfSheets() - PLURAL_COPY_FIRST_NUM_OF_SHEETS;

        for (int i = 0; i < PLURAL_COPY_FIRST_NUM_OF_SHEETS; i++) {
            // ?
            ReportsTestUtil.checkSheet(expectedWorkbook.getSheetAt(startOfTargetSheet + i),
                    workbook.getSheetAt(i), false);
        }
    } catch (ReportsCheckException e) {
        fail(e.getCheckMessagesToString());
    } finally {
        // ?????????????
        String tmpDirPath = System.getProperty("user.dir") + "/work/test/"; // System.getProperty( "java.io.tmpdir");
        File file = new File(tmpDirPath);
        if (!file.exists()) {
            file.mkdirs();
        }

        try {
            String filepath = null;
            if (version.equals("2007")) {
                filepath = tmpDirPath + "ImageParamParserTest5.xlsx";
            } else {
                filepath = tmpDirPath + "ImageParamParserTest5.xls";
            }
            PoiUtil.writeBook(workbook, filepath);
            log.info("????????" + filepath);

        } catch (IOException e) {
            fail(e.toString());
        }

    }

    // ----------------------------------------------------------------------
    // []  / ?? / (2)?
    // ----------------------------------------------------------------------

    workbook = getWorkbook();

    Sheet sheet = null;
    int totalNumOfCopies = PLURAL_COPY_FIRST_NUM_OF_SHEETS + PLURAL_COPY_SECOND_NUM_OF_SHEETS;
    for (int i = 1; i <= totalNumOfCopies; i++) {

        if (i <= PLURAL_COPY_FIRST_NUM_OF_SHEETS) {
            sheet = workbook.cloneSheet(INDEX_OF_SHEET5);
        } else {
            sheet = workbook.cloneSheet(INDEX_OF_SHEET6);
        }

        parser = new ImageParamParser();

        reportsParserInfo = new ReportsParserInfo();
        reportsParserInfo.setParamInfo(createPluralTestData(ImageParamParser.DEFAULT_TAG));

        try {
            parseSheet(parser, sheet, reportsParserInfo);
        } catch (ParseException e) {
            fail(e.toString());
        }
    }

    // ???
    delSheetIndexs.clear();
    for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
        if (i < workbook.getNumberOfSheets() - totalNumOfCopies) {
            delSheetIndexs.add(i);
        }
    }
    for (Integer i : delSheetIndexs) {
        workbook.removeSheetAt(i);
    }

    // ???
    expectedWorkbook = getExpectedWorkbook();
    for (int i = 1; i <= totalNumOfCopies; i++) {
        if (i <= PLURAL_COPY_FIRST_NUM_OF_SHEETS) {
            expectedSheet = expectedWorkbook.cloneSheet(INDEX_OF_SHEET5);
        } else {
            expectedSheet = expectedWorkbook.cloneSheet(INDEX_OF_SHEET6);
        }
    }

    try {
        int startOfTargetSheet = expectedWorkbook.getNumberOfSheets() - totalNumOfCopies;

        for (int i = 0; i < totalNumOfCopies; i++) {
            // ?
            ReportsTestUtil.checkSheet(expectedWorkbook.getSheetAt(startOfTargetSheet + i),
                    workbook.getSheetAt(i), false);
        }
    } catch (ReportsCheckException e) {
        fail(e.getCheckMessagesToString());
    } finally {
        // ?????????????
        String tmpDirPath = System.getProperty("user.dir") + "/work/test/"; // System.getProperty( "java.io.tmpdir");
        File file = new File(tmpDirPath);
        if (!file.exists()) {
            file.mkdirs();
        }

        try {
            String filepath = null;
            if (version.equals("2007")) {
                filepath = tmpDirPath + "ImageParamParserTest6.xlsx";
            } else {
                filepath = tmpDirPath + "ImageParamParserTest6.xls";
            }
            PoiUtil.writeBook(workbook, filepath);
            log.info("????????" + filepath);

        } catch (IOException e) {
            fail(e.toString());
        }
    }

}

From source file:org.wso2.carbon.policy.decision.point.merged.MergedEvaluationPoint.java

private Policy policyResolve(List<Policy> policyList)
        throws PolicyEvaluationException, PolicyManagementException {
    Collections.sort(policyList, Collections.reverseOrder());

    // Iterate through all policies
    Map<String, ProfileFeature> featureMap = new HashMap<>();
    for (Policy policy : policyList) {
        List<ProfileFeature> profileFeaturesList = policy.getProfile().getProfileFeaturesList();
        if (profileFeaturesList != null) {
            for (ProfileFeature feature : profileFeaturesList) {
                featureMap.put(feature.getFeatureCode(), feature);
            }/*from w w w . j a v a2 s. c o m*/
        }
    }

    // Get prioritized features list
    List<ProfileFeature> newFeaturesList = new ArrayList<>(featureMap.values());
    Profile profile = new Profile();
    profile.setProfileFeaturesList(newFeaturesList);
    Policy effectivePolicy = new Policy();
    effectivePolicy.setProfile(profile);
    return effectivePolicy;
}