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:com.github.radium226.github.maven.MetaDataDownloader.java

@Override
public InputStream download(GHRepository repository, Optional<GHTag> tag, String fileName)
        throws TransferFailedException, ResourceDoesNotExistException {
    List<GHRelease> releases = null;
    try {/*from ww w .  ja  v  a 2  s  .  co m*/
        releases = repository.listReleases().asList();
        releases.sort((GHRelease oneRelease, GHRelease otherRelease) -> {
            return -oneRelease.getPublished_at().compareTo(otherRelease.getPublished_at());
        });
    } catch (IOException e) {
        throw new TransferFailedException("Glup", e);
    }

    StringBuilder metaData = new StringBuilder("<metadata>").append("\n");
    GHRelease lastRelease = releases.get(0);
    metaData.append("   <groupId>").append(extractGroupID(lastRelease)).append("</groupId>").append("\n");
    metaData.append("   <artifactId>").append(extractArtifactID(lastRelease)).append("</artifactId>")
            .append("\n");
    metaData.append("   <version>").append(extractVersion(lastRelease)).append("</version>").append("\n");
    metaData.append("   <versioning>").append("\n");
    metaData.append("       <versions>").append("\n");
    for (GHRelease release : releases) {
        metaData.append("           <version>").append(extractVersion(release)).append("</version>")
                .append("\n");
    }
    metaData.append("       </versions>").append("\n");
    metaData.append("   </versioning>").append("\n");
    metaData.append("</metadata>").append("\n");

    LOGGER.debug("metaData = {}", metaData.toString());

    InputStream inputStream = new ByteArrayInputStream(metaData.toString().getBytes(Charsets.UTF_8));
    return inputStream;
}

From source file:de.mgd.simplesoundboard.dao.FileSystemSoundResourceDao.java

@Override
public List<SoundResource> findExistingSoundResources(final String category) {
    List<File> files = findFilesInStorageDirectoryIfAny(this::isMediaFile, category);
    if (files.isEmpty()) {
        return Collections.emptyList();
    }/* ww w  .  ja v  a2  s .co  m*/
    files.sort(NameFileComparator.NAME_INSENSITIVE_COMPARATOR);

    return files.stream().map(f -> soundResourceService.createSoundResourceFromFile(f))
            .collect(Collectors.toList());
}

From source file:com.hazelcast.qasonar.listpullrequests.ListPullRequests.java

public void run() throws IOException {
    print("Connecting to GitHub...");
    GitHub github = GitHub.connect();/*from  www .  j  a  v  a 2  s .  c om*/
    GHRepository repo = github.getRepository(gitHubRepository);

    print("Searching milestone \"%s\"...", milestoneTitle);
    GHMilestone milestone = getMilestone(milestoneTitle, repo);
    if (milestone == null) {
        printRed("Could not find milestone \"%s\"!", milestoneTitle);
        return;
    }

    print("Searching merged PRs for milestone \"%s\"...", milestoneTitle);
    List<Integer> pullRequests = getPullRequests(repo, milestone, calendar);

    print("Sorting %d PRs...", pullRequests.size());
    pullRequests.sort(Integer::compareTo);
    String pullRequestString = pullRequests.stream().map(String::valueOf).collect(Collectors.joining(","));

    String command = (pullRequests.size() > 0)
            ? format("qa-sonar%s%s%s --pullRequests %s --outputFile %s%n", optionalParameters,
                    outputGithubRepository, outputDefaultModule, pullRequestString, outputFile)
            : format("No PRs have been found for milestone %s in this repository!", milestone);

    if (scriptFile != null && pullRequests.size() > 0) {
        File file = new File(scriptFile);
        String script = readFileToString(file);
        writeStringToFile(file, format("%s%s%n", script, command));
    }

    printTimeTracks();
    printGreen("Done!\n");
    print(command);
}

From source file:de.hs.mannheim.modUro.reader.BoxAndWhiskersPlotDiagram.java

/**
 * Create a Tikz snippet that will render a Box and Whisker diagram
 * in Tikz./*from www.j av a  2 s  .c o  m*/
 * @return
 */
public String exportToTikz() {
    Map<String, StatisticValues> stats = bwpModel.getStatisticValues();
    List<String> sortedModels = new ArrayList<>(stats.keySet());
    //sortedModels.sort(String::compareTo);
    sortedModels.sort((s1, s2) -> s2.compareTo(s1));
    String ytickslabels = "yticklabels={"
            + sortedModels.stream().map(Object::toString).collect(Collectors.joining(", ")) + "}";
    List<String> yticksl = new ArrayList<>();
    for (int i = 2; i <= sortedModels.size() + 1; i++) {
        yticksl.add(i + "");
    }
    String ytick = "ytick={" + yticksl.stream().map(Object::toString).collect(Collectors.joining(", ")) + "}";
    String enn = "enn"; // ok.map(m = > m._1.toString + " = " + m._2.toString).mkString(", ")
    String s = "% " + enn + "\n";
    s = s + "\\begin{tikzpicture}\n" + " \\begin{axis}[\n" + " " + ytick + ",\n" + " " + ytickslabels + ",\n "
            + " height=.5*\\textheight,\n" + " xmin=0, xmax=1.0, width=.9*\\textwidth,\n"
            + " xtick={0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1},\n" + " xticklabels={0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1}\n"
            + " ]\n";

    int pos = 2;
    for (String m : sortedModels) {
        s = s + " \\addplot+[boxplot prepared={draw position=" + pos + ",\n" + "  lower whisker="
                + stats.get(m).getMin() + ", lower quartile=" + stats.get(m).getFirstPercentile() + ",\n"
                + "  median=" + stats.get(m).getSecondPercentile() + ", upper quartile="
                + stats.get(m).getLastPercentile() + ",\n" + "  upper whisker=" + stats.get(m).getMax() + ",\n"
                + "  every box/.style={draw=black},\n" + "  every whisker/.style={black},\n"
                + "  every median/.style={black}}]\n" + " coordinates {};\n";
        pos++;
    }
    s = s + " \\end{axis}\n" + "\\end{tikzpicture}\n";
    return s;
}

From source file:uk.ac.ebi.ep.data.repositories.EnzymePortalEcNumbersRepositoryImpl.java

@Transactional(readOnly = true)
@Override/*  ww w  .  j  av  a  2 s  .c  o  m*/
public List<EcNumber> findEnzymeFamiliesByTaxId(Long taxId) {

    EntityGraph eGraph = entityManager.getEntityGraph("EcNumberEntityGraph");
    eGraph.addAttributeNodes("uniprotAccession");

    JPAQuery query = new JPAQuery(entityManager);
    query.setHint("javax.persistence.fetchgraph", eGraph);

    List<EcNumber> result = query.from($).where($.uniprotAccession.taxId.eq(taxId))
            .list(Projections.constructor(EcNumber.class, $.ecFamily)).stream().distinct()
            .collect(Collectors.toList());

    result.sort(SORT_BY_EC);
    return result;
}

From source file:org.apache.samza.system.hdfs.partitioner.DirectoryPartitioner.java

private List<List<FileMetadata>> generatePartitionGroups(List<FileMetadata> filteredFiles) {
    Map<String, List<FileMetadata>> map = new HashMap<>();
    for (FileMetadata fileMetadata : filteredFiles) {
        String groupId = extractGroupIdentifier(fileMetadata.getPath());
        map.putIfAbsent(groupId, new ArrayList<>());
        map.get(groupId).add(fileMetadata);
    }//from w  ww . java 2  s  . co m
    List<List<FileMetadata>> ret = new ArrayList<>();
    // sort the map to guarantee consistent ordering
    List<String> sortedKeys = new ArrayList<>(map.keySet());
    sortedKeys.sort(Comparator.<String>naturalOrder());
    sortedKeys.stream().forEach(key -> ret.add(map.get(key)));
    return ret;
}

From source file:org.pgptool.gui.ui.keyslist.KeysListPm.java

public void init(KeysListHost host) {
    Preconditions.checkArgument(host != null);
    this.host = host;

    List<Key> initialKeys = keyRingService.readKeys();
    initialKeys.sort(keySorterByNameAsc);
    tableModelProp = new ModelTableProperty<>(this, initialKeys, "keys", new KeysTableModel());
    hasData = new ModelProperty<>(this, new ValueAdapterHolderImpl<>(!initialKeys.isEmpty()), "hasData");
    tableModelProp.getModelPropertyAccessor().addPropertyChangeListener(onSelectionChangedHandler);
    onSelectionChangedHandler.propertyChange(null);

    actionExportAllPublicKeys.setEnabled(hasData.getValue());

    eventBus.register(this);
}

From source file:org.pgptool.gui.ui.keyslist.KeysListPm.java

@Subscribe
public void onRowChangedEvent(EntityChangedEvent<?> event) {
    if (!event.isTypeOf(Key.class)) {
        return;/* w  ww. j a  v  a  2 s . c o  m*/
    }

    List<Key> newKeysList = keyRingService.readKeys();
    newKeysList.sort(keySorterByNameAsc);
    tableModelProp.getList().clear();
    tableModelProp.getList().addAll(newKeysList);
    hasData.setValueByOwner(!newKeysList.isEmpty());
    actionExportAllPublicKeys.setEnabled(hasData.getValue());

    // NOTE: Selection is not nicely maintained. Each update will clear the
    // current selection if any
}

From source file:org.cbioportal.service.impl.GenesetCorrelationServiceImpl.java

private void sortResult(List<GenesetCorrelation> result) {

    result.sort((GenesetCorrelation o1, GenesetCorrelation o2) -> {
        //descending order, also check for NaN
        if (o1.getCorrelationValue().isNaN())
            return 1;
        if (o2.getCorrelationValue().isNaN())
            return -1;

        if (o1.getCorrelationValue() < o2.getCorrelationValue())
            return 1;
        if (o1.getCorrelationValue() > o2.getCorrelationValue())
            return -1;

        return 0;
    });//from w  w w.ja  v  a2 s  .  c  om
}

From source file:com.acmutv.ontoqa.tool.io.IOManagerTest.java

/**
 * Tests directory listing./*from w  ww. ja  va2  s .c  o  m*/
 */
@Test
public void test_listAllFiles() throws IOException {
    String directory = IOManagerTest.class.getResource("/tool/io/").getPath();
    List<Path> actual = IOManager.allFiles(directory);
    actual.sort(Comparator.naturalOrder());

    List<Path> expected = new ArrayList<>();
    expected.add(
            FileSystems.getDefault().getPath(IOManagerTest.class.getResource("/tool/io/sample").getPath()));
    expected.add(
            FileSystems.getDefault().getPath(IOManagerTest.class.getResource("/tool/io/sample.txt").getPath()));
    expected.sort(Comparator.naturalOrder());

    Assert.assertEquals(expected, actual);
}