Example usage for java.util Collections reverse

List of usage examples for java.util Collections reverse

Introduction

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

Prototype

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void reverse(List<?> list) 

Source Link

Document

Reverses the order of the elements in the specified list.

This method runs in linear time.

Usage

From source file:edu.illinois.cs.cogcomp.CleanMojo.java

public void execute() throws MojoExecutionException {
    dFlag = FileUtils.getPlatformIndependentFilePath(dFlag);
    gspFlag = FileUtils.getPlatformIndependentFilePath(gspFlag);
    sourcepathFlag = FileUtils.getPlatformIndependentFilePath(sourcepathFlag);

    classpath.add(dFlag);/* www. j  av  a 2  s. co  m*/
    classpath.add(gspFlag);

    String newpath = StringUtils.join(classpath, File.pathSeparator);

    // We need to reverse the order we do the cleaning since there might be dependencies across
    // files
    List<String> fileList = Arrays.asList(lbjavaInputFileList);
    Collections.reverse(fileList);
    for (String lbjInputFile : fileList) {
        if (StringUtils.isEmpty(lbjInputFile)) {
            // making the optional-compile-step parameter happy.
            continue;
        }

        getLog().info("Calling Java edu.illinois.cs.cogcomp.lbjava.Main with the -x flag (for cleaning)...");

        lbjInputFile = FileUtils.getPlatformIndependentFilePath(lbjInputFile);

        try {
            // The -x flag makes all the difference.
            String[] args = new String[] { "java", "-cp", newpath, "edu.illinois.cs.cogcomp.lbjava.Main", "-x",
                    "-d", dFlag, "-gsp", gspFlag, "-sourcepath", sourcepathFlag, lbjInputFile };

            ProcessBuilder pr = new ProcessBuilder(args);
            pr.inheritIO();
            Process p = pr.start();
            p.waitFor();

        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("Yeah, an error.");
        }
    }

}

From source file:com.opengamma.analytics.financial.schedule.AnnualScheduleCalculator.java

@Override
public ZonedDateTime[] getSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate,
        final boolean fromEnd, final boolean generateRecursive) {
    Validate.notNull(startDate, "start date");
    Validate.notNull(endDate, "end date");
    Validate.isTrue(startDate.isBefore(endDate) || startDate.equals(endDate));
    if (startDate.equals(endDate)) {
        return new ZonedDateTime[] { startDate };
    }//from ww  w.  j av a 2s  .  c  om
    final List<ZonedDateTime> dates = new ArrayList<ZonedDateTime>();
    if (fromEnd) {
        ZonedDateTime date = endDate;
        int i = 1;
        while (!date.isBefore(startDate)) {
            dates.add(date);
            date = generateRecursive ? date.minus(Period.ofYears(1)) : endDate.minus(Period.ofYears(i++));
        }
        Collections.reverse(dates);
        return dates.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
    }
    ZonedDateTime date = startDate;
    int i = 1;
    while (!date.isAfter(endDate)) {
        dates.add(date);
        date = generateRecursive ? date.plus(Period.ofYears(1)) : startDate.plus(Period.ofYears(i++));
    }
    return dates.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
}

From source file:com.bah.applefox.main.plugins.pageranking.utilities.PRtoFile.java

private static HashMap<String, Double> createMap(String[] args)
        throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
    HashMap<String, Double> ret = new HashMap<String, Double>();
    String readTable = args[13] + "Old";

    Scanner scan = AccumuloUtils.connectRead(readTable);

    Iterator<Entry<Key, Value>> itr = scan.iterator();

    while (itr.hasNext()) {
        Entry<Key, Value> temp = itr.next();
        try {/*from   w ww .  j  a va2 s . co  m*/
            Double val = (Double) IngestUtils.deserialize(temp.getValue().get());
            ret.put(temp.getKey().getRow().toString(), val);
            System.out.println("Adding to Map: " + temp.getKey().getRow().toString() + " with rank: " + val);
        } catch (IOException e) {
            if (e.getMessage() != null) {
                log.error(e.getMessage());
            } else {
                log.error(e.getStackTrace());
            }
        } catch (ClassNotFoundException e) {
            if (e.getMessage() != null) {
                log.error(e.getMessage());
            } else {
                log.error(e.getStackTrace());
            }
        }
    }

    Double max = 0.0;

    Collection<Double> values = ret.values();

    ArrayList<Double> tempValues = new ArrayList<Double>();
    tempValues.addAll(values);
    Collections.sort(tempValues);
    Collections.reverse(tempValues);

    max = tempValues.get(0);

    ret.put("[[MAX_PR]]", max);

    return ret;
}

From source file:com.opengamma.analytics.financial.schedule.MonthlyScheduleCalculator.java

@Override
public ZonedDateTime[] getSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate,
        final boolean fromEnd, final boolean generateRecursive) {
    Validate.notNull(startDate, "start date");
    Validate.notNull(endDate, "end date");
    Validate.isTrue(startDate.isBefore(endDate) || startDate.equals(endDate));
    if (startDate.equals(endDate)) {
        return new ZonedDateTime[] { startDate };
    }/*from  w  w  w . j a  v  a 2 s .c  o m*/
    final List<ZonedDateTime> dates = new ArrayList<ZonedDateTime>();
    if (fromEnd) {
        ZonedDateTime date = endDate;
        int i = 1;
        while (!date.isBefore(startDate)) {
            dates.add(date);
            date = generateRecursive ? date.minus(Period.ofMonths(1)) : endDate.minus(Period.ofMonths(i++));
        }
        Collections.reverse(dates);
        return dates.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
    }
    ZonedDateTime date = startDate;
    int i = 1;
    while (!date.isAfter(endDate)) {
        dates.add(date);
        date = generateRecursive ? date.plus(Period.ofMonths(1)) : startDate.plus(Period.ofMonths(i++));
    }
    return dates.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
}

From source file:net.landora.video.addons.AddonManager.java

private void stopAddons() {
    if (addons == null) {
        throw new IllegalStateException("Addons not running.");
    }//from  w ww.  j av a  2s.  c  o  m
    if (!started) {
        return;
    }

    List<Addon> addonsReversed = new ArrayList<Addon>(addons.values());
    Collections.reverse(addonsReversed);

    for (Addon addon : addonsReversed) {
        addon.stop();
    }

    started = false;
}

From source file:de.tudarmstadt.tk.statistics.helper.Helpers.java

/**
 * Remove models with the worst performance measures from the sample data if
 * the no. of models exceeds a certain threshold. If a baseline evaluation
 * is performed, the baseline model is retained. If the number of models
 * does not exceed the specified threshold, nothing happens.
 * /*from w  w w .j a v  a  2  s  . co m*/
 * @param sampleData
 *            An object of type {@link StatisticalEvaluationData}
 * @param selectBestN
 *            Maximum number of models
 * @param selectByMeasure
 *            Measure by which to select the models
 * @return the truncated SampleData object
 */
public static SampleData truncateData(SampleData sampleData, int selectBestN, String selectByMeasure) {

    int nModels = sampleData.getModelMetadata().size();

    // Only select a subset of the data if there're more models than the
    // specified maximum
    if (nModels > selectBestN && nModels > 1) {

        // Get sample averages
        ArrayList<Double> sampleAverages = sampleData.getSamplesAverage().get(selectByMeasure);
        if (sampleAverages == null) {
            sampleAverages = sampleData.getSamplesAverage().get("Averaged " + selectByMeasure);
        }

        if (sampleAverages == null) {
            logger.log(Level.ERROR, "Measure for model selection not available in sample data! No selection.");
            return sampleData;
        }

        // Sort them
        ArrayList<Pair<Integer, Double>> sortedAvgs = new ArrayList<Pair<Integer, Double>>();
        for (int i = 0; i < sampleAverages.size(); i++) {
            sortedAvgs.add(Pair.of(i, sampleAverages.get(i)));
        }

        Collections.sort(sortedAvgs, new PairValueComparator());

        ArrayList<Integer> obsolete = new ArrayList<Integer>();
        for (int i = 0; i < sortedAvgs.size() - selectBestN; i++) {
            int toBeRemoved = sortedAvgs.get(i).getKey();
            // If this is a baseline evaluation, do not remove the baseline
            // model
            if (sampleData.isBaselineEvaluation() && toBeRemoved == 0) {
                continue;
            }
            obsolete.add(toBeRemoved);
        }

        Collections.sort(obsolete);
        Collections.reverse(obsolete);

        // Remove obsolete samples
        Iterator<String> itm = sampleData.getSamplesAverage().keySet().iterator();
        while (itm.hasNext()) {
            String measure = itm.next();
            for (int i = 0; i < obsolete.size(); i++) {
                sampleData.getSamplesAverage().get(measure).remove((int) obsolete.get(i));
                sampleData.getSamples().get(measure).remove((int) obsolete.get(i));
            }
        }
        // Remove obsolete model metadata
        for (int i = 0; i < obsolete.size(); i++) {
            sampleData.getModelMetadata().remove((int) obsolete.get(i));
        }

    }

    return sampleData;
}

From source file:com.boundlessgeo.geoserver.util.RecentObjectCache.java

public <T extends Info> Iterable<Ref> list(Class<T> clazz) {
    List<Ref> list = null;

    EvictingQueue<Ref> q = q(clazz);
    synchronized (q) {
        list = new ArrayList(q);
    }/*from w  w  w.  ja va  2 s .  c om*/

    Collections.reverse(list);
    return new LinkedHashSet<>(list);
}

From source file:eu.prestoprime.p4gui.connection.SearchConnection.java

public static ArrayList<String> searchByDC(P4Service service, String title, String description, String format,
        String identifier) {//from   w w  w  .j  a  v a  2  s. com
    ArrayList<String> records = new ArrayList<String>();
    try {
        String path = service.getURL() + "/search/?" + "title=" + title + "&description=" + description
                + "&format=" + format + "&identifier=" + identifier;
        P4HttpClient client = new P4HttpClient(service.getUserID());
        HttpRequestBase request = new HttpGet(path);
        HttpResponse response = client.executeRequest(request);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            InputStream is = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(is));
            String line = null;
            while ((line = reader.readLine()) != null) {
                records.add(line);
            }
            is.close();
        }
        EntityUtils.consume(entity);
    } catch (Exception e) {
        e.printStackTrace();
    }
    Collections.reverse(records);
    return records;
}

From source file:hudson.scm.listtagsparameter.SimpleSVNDirEntryHandler.java

public List<String> getDirs(boolean reverseByDate, boolean reverseByName) {
    List sortedDirs = null;//ww w. j av a2  s .  com
    if (reverseByDate) {
        sortedDirs = new ArrayList();
        TreeSet<Date> keys = new TreeSet<Date>(dirs.keySet());
        for (Date key : keys) {
            sortedDirs.add(dirs.get(key));
        }
        Collections.reverse(sortedDirs);
    } else if (reverseByName) {
        sortedDirs = new ArrayList(dirs.values());
        Collections.reverse(sortedDirs);
    } else {
        sortedDirs = new ArrayList(dirs.values());
        Collections.sort(sortedDirs);
    }
    return sortedDirs;
}

From source file:com.uber.hoodie.cli.commands.CleansCommand.java

@CliCommand(value = "cleans show", help = "Show the cleans")
public String showCleans() throws IOException {
    HoodieActiveTimeline activeTimeline = HoodieCLI.tableMetadata.getActiveTimeline();
    HoodieTimeline timeline = activeTimeline.getCleanerTimeline().filterCompletedInstants();
    List<HoodieInstant> cleans = timeline.getInstants().collect(Collectors.toList());
    String[][] rows = new String[cleans.size()][];
    Collections.reverse(cleans);
    for (int i = 0; i < cleans.size(); i++) {
        HoodieInstant clean = cleans.get(i);
        HoodieCleanMetadata cleanMetadata = AvroUtils
                .deserializeHoodieCleanMetadata(timeline.getInstantDetails(clean).get());
        rows[i] = new String[] { clean.getTimestamp(), cleanMetadata.getEarliestCommitToRetain(),
                String.valueOf(cleanMetadata.getTotalFilesDeleted()),
                String.valueOf(cleanMetadata.getTimeTakenInMillis()) };
    }/* w w w.ja  v a  2s.  co  m*/
    return HoodiePrintHelper.print(
            new String[] { "CleanTime", "EarliestCommandRetained", "Total Files Deleted", "Total Time Taken" },
            rows);
}