Example usage for java.util List sort

List of usage examples for java.util List sort

Introduction

In this page you can find the example usage for java.util List sort.

Prototype

@SuppressWarnings({ "unchecked", "rawtypes" })
default void sort(Comparator<? super E> c) 

Source Link

Document

Sorts this list according to the order induced by the specified Comparator .

Usage

From source file:controllers.ConfigurationApplication.java

public static Result updatePuppetConfiguration() {
    String callBackUrl = GoogleComputeEngineAuthImpl.getCallBackURL(request());
    try {/*w  w  w. j  a va  2s  . co  m*/
        String result = GoogleAuthenticationService.authenticate(callBackUrl, null);
        if (result != null) {
            return redirect(result);
        }

        ClusterEditionForm clusterEdition = new ClusterEditionForm();
        Form<ClusterEditionForm> formData = Form.form(ClusterEditionForm.class).fill(clusterEdition);
        Map<String, Boolean> fileNames = new TreeMap<>(Comparator.<String>naturalOrder());
        List<String> fileList = ConfigurationService.listPuppetFiles(PuppetConfiguration.PUPPET_FILE);
        fileList.sort(Comparator.<String>naturalOrder());
        fileNames.put("mongodb-base.pp", false);
        fileNames.put("mongodb-conf.pp", false);
        fileNames.put("mongodb-shard.pp", false);
        return ok(views.html.cluster_edition.render(formData, fileNames, fileList));
    } catch (GoogleComputeEngineException e) {
        return ok(views.html.error.render(e.getMessage()));
    } catch (PuppetConfigurationException e) {
        return ok(views.html.error.render(e.getMessage()));
    }
}

From source file:org.openstreetmap.josm.gui.preferences.imagery.CacheContentsPanel.java

public static String[][] getCacheStats(CacheAccess<String, BufferedImageCacheEntry> cache) {
    Set<String> keySet = cache.getCacheControl().getKeySet();
    Map<String, int[]> temp = new ConcurrentHashMap<>(); // use int[] as a Object reference to int, gives better performance
    for (String key : keySet) {
        String[] keyParts = key.split(":", 2);
        if (keyParts.length == 2) {
            int[] counter = temp.get(keyParts[0]);
            if (counter == null) {
                temp.put(keyParts[0], new int[] { 1 });
            } else {
                counter[0]++;/*w  w  w.ja va2s  .c om*/
            }
        } else {
            Logging.warn("Could not parse the key: {0}. No colon found", key);
        }
    }

    List<Pair<String, Integer>> sortedStats = new ArrayList<>();
    for (Entry<String, int[]> e : temp.entrySet()) {
        sortedStats.add(new Pair<>(e.getKey(), e.getValue()[0]));
    }
    sortedStats.sort(Comparator.comparing(o -> o.b, Comparator.reverseOrder()));
    String[][] ret = new String[sortedStats.size()][3];
    int index = 0;
    for (Pair<String, Integer> e : sortedStats) {
        ret[index] = new String[] { e.a, e.b.toString(), tr("Clear") };
        index++;
    }
    return ret;
}

From source file:controllers.ConfigurationApplication.java

public static Result updatePuppetConfigurationPost() {
    String callBackUrl = GoogleComputeEngineAuthImpl.getCallBackURL(request());
    try {/*from   ww w.  j a va 2  s . c  o m*/
        String result = GoogleAuthenticationService.authenticate(callBackUrl, null);
        if (result != null) {
            return redirect(result);
        }

        Form<ClusterEditionForm> formData = new BugWorkaroundForm<>(ClusterEditionForm.class).bindFromRequest();
        ClusterEditionForm clusterForm = formData.get();

        if (formData.hasErrors()) {
            flash("error", "Please correct errors above.");
        } else {
            try {
                File f = File.createTempFile(clusterForm.getFileName(), "tmp");
                FileUtils.writeFile(f, clusterForm.getFileContent());
                ConfigurationService.uploadPuppetFile(PuppetConfiguration.PUPPET_MANIFEST,
                        clusterForm.getFileName(), f);
                flash("success", "Configuration file updated.");
            } catch (IOException e) {
                flash("error", e.getMessage());
            } catch (FileLockException e) {
                flash("error", e.getMessage());
            }
        }

        Map<String, Boolean> fileNames = new TreeMap<>(Comparator.<String>naturalOrder());
        List<String> fileList = ConfigurationService.listPuppetFiles(PuppetConfiguration.PUPPET_FILE);
        fileList.sort(Comparator.<String>naturalOrder());
        fileNames.put("mongodb-base.pp",
                (clusterForm.getFileName() != null && clusterForm.getFileName().equals("mongodb-base.pp")));
        fileNames.put("mongodb-conf.pp",
                (clusterForm.getFileName() != null && clusterForm.getFileName().equals("mongodb-conf.pp")));
        fileNames.put("mongodb-shard.pp",
                (clusterForm.getFileName() != null && clusterForm.getFileName().equals("mongodb-shard.pp")));

        return ok(views.html.cluster_edition.render(formData, fileNames, fileList));
    } catch (GoogleComputeEngineException e) {
        return ok(views.html.error.render(e.getMessage()));
    } catch (PuppetConfigurationException e) {
        return ok(views.html.error.render(e.getMessage()));
    }
}

From source file:org.ensor.fftmusings.rnn.GravesLSTMCharModellingExample.java

private static int sampleFromDistribution2(double[] distribution, Random rng) {

    List<Dist> list = new ArrayList<>();
    for (int i = 0; i < distribution.length; i++) {
        Dist d = new Dist();
        d.prob = distribution[i];// w  w  w  .  j  ava 2  s  .co  m
        d.charIndex = i;
        list.add(d);
    }
    list.sort(comparator);
    int idx = Math.abs(rng.nextInt()) % 3;
    return list.get(idx).charIndex;
}

From source file:io.druid.data.input.impl.PrefetchableTextFilesFirehoseFactoryTest.java

private static void assertResult(List<Row> rows) {
    Assert.assertEquals(1000, rows.size());
    rows.sort((r1, r2) -> {
        int c = r1.getTimestamp().compareTo(r2.getTimestamp());
        if (c != 0) {
            return c;
        }/*from   w w  w  . ja  v  a2 s  . c o  m*/
        c = Integer.valueOf(r1.getDimension("a").get(0))
                .compareTo(Integer.valueOf(r2.getDimension("a").get(0)));
        if (c != 0) {
            return c;
        }

        return Integer.valueOf(r1.getDimension("b").get(0))
                .compareTo(Integer.valueOf(r2.getDimension("b").get(0)));
    });

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 100; j++) {
            final Row row = rows.get(i * 100 + j);
            Assert.assertEquals(new DateTime(20171220 + i), row.getTimestamp());
            Assert.assertEquals(String.valueOf(i), row.getDimension("a").get(0));
            Assert.assertEquals(String.valueOf(j), row.getDimension("b").get(0));
        }
    }
}

From source file:com.taobao.android.builder.tools.bundleinfo.BundleGraphExecutor.java

private static List<BundleItem> getOrderList(Set<BundleItem> sets) {
    List<BundleItem> list = new ArrayList<>(sets);
    list.sort((o1, o2) -> o1.bundleInfo.getPkgName().compareTo(o2.bundleInfo.getPkgName()));
    return list;//from ww w . ja  v  a 2 s.co  m
}

From source file:org.apache.lens.cube.parse.TestCubeSegmentationRewriter.java

private static void compareUnionQuery(CubeQueryContext cubeql, String begin, String end, List<String> queries)
        throws LensException {
    final String actualLower = cubeql.toHQL().toLowerCase();
    queries.sort(Comparator.comparing(s -> actualLower.indexOf(extractTableName(s))));
    String expected = queries.stream().collect(Collectors.joining(" UNION ALL ", begin, end));
    compareQueries(actualLower, expected);
}

From source file:delfos.dataset.basic.rating.RatingsDatasetAdapter.java

public static <RatingType extends Rating> int hashCode(RatingsDataset<RatingType> ratingsDataset) {
    HashCodeBuilder hashCodeBuilder = new HashCodeBuilder(37, 11);

    List<Integer> usersSorted = ratingsDataset.allUsers().stream().collect(Collectors.toList());
    usersSorted.sort((i1, i2) -> Integer.compare(i1, i2));

    List<Integer> itemsSorted = ratingsDataset.allRatedItems().stream().collect(Collectors.toList());
    itemsSorted.sort((i1, i2) -> Integer.compare(i1, i2));

    for (int idUser : usersSorted) {
        hashCodeBuilder.append(idUser);//  ww  w.j  a  va 2  s  . c om
        try {
            Map<Integer, RatingType> userRatingsRated = ratingsDataset.getUserRatingsRated(idUser);

            List<Integer> thisUserItemsSorted = userRatingsRated.keySet().stream()
                    .sorted((i1, i2) -> Integer.compare(i1, i2)).collect(Collectors.toList());
            for (Integer idItem : thisUserItemsSorted) {
                RatingType rating = userRatingsRated.get(idItem);
                double ratingValue = rating.getRatingValue().doubleValue();
                hashCodeBuilder.append(idItem);
                hashCodeBuilder.append(ratingValue);
            }
        } catch (UserNotFound ex) {
            ERROR_CODES.USER_NOT_FOUND.exit(ex);
        }
    }

    return hashCodeBuilder.hashCode();
}

From source file:io.druid.data.input.impl.prefetch.PrefetchableTextFilesFirehoseFactoryTest.java

private static void assertResult(List<Row> rows) {
    Assert.assertEquals(10000, rows.size());
    rows.sort((r1, r2) -> {
        int c = r1.getTimestamp().compareTo(r2.getTimestamp());
        if (c != 0) {
            return c;
        }/* w ww .  j a v  a  2  s .c  o m*/
        c = Integer.valueOf(r1.getDimension("a").get(0))
                .compareTo(Integer.valueOf(r2.getDimension("a").get(0)));
        if (c != 0) {
            return c;
        }

        return Integer.valueOf(r1.getDimension("b").get(0))
                .compareTo(Integer.valueOf(r2.getDimension("b").get(0)));
    });

    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            final Row row = rows.get(i * 100 + j);
            Assert.assertEquals(DateTimes.utc(20171220 + i), row.getTimestamp());
            Assert.assertEquals(i, Integer.valueOf(row.getDimension("a").get(0)).intValue());
            Assert.assertEquals(j, Integer.valueOf(row.getDimension("b").get(0)).intValue());
        }
    }
}

From source file:org.structr.feed.entity.DataFeed.java

static void cleanUp(final DataFeed thisFeed) {

    final Integer maxItemsToRetain = thisFeed.getMaxItems();
    final Long maxItemAge = thisFeed.getMaxAge();

    int i = 0;// w  w  w .  j  a v  a 2  s.  co m

    // Don't do anything if maxItems and maxAge are not set
    if (maxItemsToRetain != null || maxItemAge != null) {

        final List<FeedItem> feedItems = Iterables.toList(thisFeed.getItems());
        final PropertyKey<Date> dateKey = StructrApp.key(FeedItem.class, "pubDate");

        // Sort by publication date, youngest items first
        feedItems.sort(new GraphObjectComparator(dateKey, GraphObjectComparator.DESCENDING));

        for (final FeedItem item : feedItems) {

            i++;

            final Date itemDate = item.getProperty(dateKey);

            if ((maxItemsToRetain != null && i > maxItemsToRetain)
                    || (maxItemAge != null && itemDate.before(new Date(new Date().getTime() - maxItemAge)))) {

                try {
                    StructrApp.getInstance().delete(item);

                } catch (FrameworkException ex) {
                    logger.error("Error while deleting old/surplus feed item " + item, ex);
                }
            }
        }

    }

}