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:org.egov.council.service.CouncilReportService.java

public byte[] generatePDFForMom(final CouncilMeeting councilMeeting) {
    if (councilMeeting != null) {
        final Map<String, Object> momDetails = new HashMap<>();
        final List<MeetingMOM> meetingMomList = councilMeeting.getMeetingMOMs();
        meetingMomList.sort((final MeetingMOM f1, final MeetingMOM f2) -> Long.valueOf(f1.getItemNumber())
                .compareTo(Long.valueOf(f2.getItemNumber())));
        momDetails.put("meetingMOMList", meetingMomList);
        ReportRequest reportInput = new ReportRequest(MEETINGMOM, momDetails,
                buildReportParameters(councilMeeting));
        reportInput.setReportFormat(ReportFormat.RTF);
        reportInput.setPrintDialogOnOpenReport(false);
        return createReport(reportInput).getReportOutputData();
    }// w  w  w  .j  a v  a 2 s.co  m
    return new byte[0];
}

From source file:cc.redpen.formatter.JSONBySentenceFormatter.java

/**
 * Render as a JSON object a list of errors for a given document
 *
 * @param document the document that has the errors
 * @param errors   a list of errors//  w  w  w. j  ava  2 s . c  om
 * @return a JSON object representing the errors
 */
protected JSONObject asJSON(Document document, List<ValidationError> errors) {
    List<ValidationError> sortedErrors = new ArrayList<>(errors);
    sortedErrors.sort(BY_SENTENCE_COMPARATOR);

    JSONObject jsonErrors = new JSONObject();
    try {
        if (document.getFileName().isPresent()) {
            jsonErrors.put("document", document.getFileName().get());
        }
        JSONArray documentErrors = new JSONArray();
        jsonErrors.put("errors", documentErrors);

        JSONArray sentenceErrors = new JSONArray();
        ValidationError lastError = null;
        for (ValidationError error : sortedErrors) {
            if (BY_SENTENCE_COMPARATOR.compare(lastError, error) != 0) {
                JSONObject sentenceError = new JSONObject();
                sentenceError.put("sentence", error.getSentence().getContent());
                Sentence sentence = error.getSentence();
                //NOTE: last position is optional
                LineOffset lastPosition = sentence.getOffset(sentence.getContent().length() - 1)
                        .orElse(new LineOffset(sentence.getLineNumber(),
                                sentence.getStartPositionOffset() + sentence.getContent().length()));
                sentenceError.put("position", asJSON(sentence.getLineNumber(),
                        sentence.getStartPositionOffset(), lastPosition.lineNum, lastPosition.offset));
                sentenceErrors = new JSONArray();
                sentenceError.put("errors", sentenceErrors);

                documentErrors.put(sentenceError);
                lastError = error;
            }
            sentenceErrors.put(asJSON(error));
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
    return jsonErrors;
}

From source file:com.navercorp.pinpoint.web.service.AgentEventServiceImpl.java

@Override
public List<AgentEvent> getAgentEvents(String agentId, Range range, int... excludeEventTypeCodes) {
    if (agentId == null) {
        throw new NullPointerException("agentId must not be null");
    }/*from   w w  w.  j a v  a  2s .c  o  m*/
    Set<AgentEventType> excludeEventTypes = EnumSet.noneOf(AgentEventType.class);
    for (int excludeEventTypeCode : excludeEventTypeCodes) {
        AgentEventType excludeEventType = AgentEventType.getTypeByCode(excludeEventTypeCode);
        if (excludeEventType != null) {
            excludeEventTypes.add(excludeEventType);
        }
    }
    List<AgentEventBo> agentEventBos = this.agentEventDao.getAgentEvents(agentId, range, excludeEventTypes);
    List<AgentEvent> agentEvents = createAgentEvents(agentEventBos);
    agentEvents.sort(AgentEvent.EVENT_TIMESTAMP_ASC_COMPARATOR);
    return agentEvents;
}

From source file:pl.p.lodz.ftims.server.logic.ChallengeService.java

@Override
public List<Challenge> getChallenges(Coordinates coords) {
    List<Challenge> challenges = IteratorUtils.toList(challengesDAO.findAll().iterator());
    challenges.sort((Challenge o1, Challenge o2) -> {
        double distance1 = new Coordinates(o1.getLocation()).computeDistance(coords);
        double distance2 = new Coordinates(o2.getLocation()).computeDistance(coords);
        return (int) (distance2 - distance1);
    });//from w ww . j  a v a 2 s.c om
    return challenges;
}

From source file:com.thinkbiganalytics.auth.jaas.config.JaasAuthConfig.java

@Bean(name = "jaasConfiguration")
public javax.security.auth.login.Configuration jaasConfiguration(
        Optional<List<LoginConfiguration>> loginModuleEntries) {
    // Generally the entries will be null only in situations like unit/integration tests.
    if (loginModuleEntries.isPresent()) {
        List<LoginConfiguration> sorted = new ArrayList<>(loginModuleEntries.get());
        sorted.sort(new AnnotationAwareOrderComparator());

        Map<String, AppConfigurationEntry[]> merged = sorted.stream()
                .map(c -> c.getAllApplicationEntries().entrySet()).flatMap(s -> s.stream())
                .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue(), ArrayUtils::addAll));
        return new InMemoryConfiguration(merged);
    } else {//from  w ww .  j  a v a 2s .c om
        return new InMemoryConfiguration(Collections.emptyMap());
    }
}

From source file:org.openlmis.referencedata.web.BaseController.java

private List<Change> getChangesByType(Class type, UUID id, String author, String changedPropertyName,
        Pageable page) {/*from  w  w w .  ja  v a2  s.  c o  m*/
    QueryBuilder queryBuilder;

    if (id != null) {
        queryBuilder = QueryBuilder.byInstanceId(id, type);
    } else {
        queryBuilder = QueryBuilder.byClass(type);
    }

    int skip = Pagination.getPageNumber(page);
    int limit = Pagination.getPageSize(page);

    queryBuilder = queryBuilder.withNewObjectChanges(true).skip(skip).limit(limit);

    if (StringUtils.isNotBlank(author)) {
        queryBuilder = queryBuilder.byAuthor(author);
    }
    if (StringUtils.isNotBlank(changedPropertyName)) {
        queryBuilder = queryBuilder.andProperty(changedPropertyName);
    }

    /* Depending on the business' preference, we can either use findSnapshots() or findChanges().
       Whereas the former returns the entire state of the object as it was at each commit, the later
       returns only the property and values which changed. */
    //List<Change> changes = javers.findSnapshots(queryBuilder.build());
    List<Change> changes = javers.findChanges(queryBuilder.build());

    changes.sort((o1, o2) -> -1 * o1.getCommitMetadata().get().getCommitDate()
            .compareTo(o2.getCommitMetadata().get().getCommitDate()));
    return changes;
}

From source file:org.jboss.prod.jardif.JarDif.java

private void compare(Path maven, Path gradle) {
    System.out.println("===============================================");
    System.out.println(maven + " vs " + gradle);
    System.out.println("===============================================");
    Path gradleDir = new File(workDir, "gradle-" + gradle.getFileName().toString()).toPath();
    Path mvnDir = new File(workDir, "maven-" + maven.getFileName().toString()).toPath();
    ZipUtils.unzip(maven, mvnDir);// w ww  . ja  v a2  s  .  c  o  m
    ZipUtils.unzip(gradle, gradleDir);

    List<String> mvnContents = OSUtils.runCommandIn("find . -type f", mvnDir);
    mvnContents.sort(Comparator.comparingInt(String::hashCode));
    List<String> gradleContents = OSUtils.runCommandIn("find . -type f", gradleDir);
    gradleContents.sort(Comparator.comparingInt(String::hashCode));

    Iterator<String> mvnFiles = mvnContents.stream().iterator();
    Iterator<String> gradleFiles = gradleContents.stream().iterator();

    if (!mvnFiles.hasNext() || !gradleFiles.hasNext()) {
        throw new IllegalStateException("One of the jars: " + maven + ", " + gradle + " is empty! Exitting");
    }
    String mvnFile = mvnFiles.next();
    String gradleFile = gradleFiles.next();

    while (mvnFiles.hasNext() && gradleFiles.hasNext()) {
        if (mvnFile.equals(gradleFile)) {
            compareFiles(new File(mvnDir.toFile(), mvnFile), new File(gradleDir.toFile(), gradleFile));
            mvnFile = mvnFiles.next();
            gradleFile = gradleFiles.next();
        } else if (mvnFile.hashCode() < gradleFile.hashCode()) {
            System.out.println("+" + mvnFile);
            mvnFile = mvnFiles.next();
        } else {
            System.out.println("-" + gradleFile);
            gradleFile = gradleFiles.next();
        }
    }

    mvnFiles.forEachRemaining(e -> System.out.println("+" + e));
    gradleFiles.forEachRemaining(e -> System.out.println("-" + e));
    System.out.println();
    System.out.println();
}

From source file:pl.hycom.pip.messanger.controller.GreetingController.java

private void sortByLocale(List<com.github.messenger4j.profile.Greeting> greetings) {
    greetings.sort((g1, g2) -> StringUtils.compare(g1.getLocale(), g2.getLocale()));
}

From source file:org.silverpeas.core.index.indexing.model.RepositoryIndexer.java

/**
 * Recursive function which covers directories. For each file, the file is indexed.
 *//*from  w w  w .  j a  v  a2 s. co  m*/
private void processFileList(Path dir, LocalDate creationDate, String creatorId, String action) {
    if (count % 10000 == 0) {
        SilverLogger.getLogger(this).debug("# of indexed documents = {0}", count);
    }

    File[] dirs = dir.toFile().listFiles(DirectorySPFilter.getInstance());
    File[] files = dir.toFile().listFiles(FileSPFilter.getInstance());

    List<File> dirList = Arrays.asList(dirs != null ? dirs : new File[0]);
    dirList.sort(FilenameComparator.comparator);

    List<File> fileList = Arrays.asList(files != null ? files : new File[0]);
    fileList.sort(FilenameComparator.comparator);

    for (File currentFile : fileList) {
        indexFile(currentFile, creationDate, creatorId, action);
    }
    for (File currentDir : dirList) {
        final Path currentDirectoryPath = currentDir.toPath();
        indexDirectory(currentDirectoryPath, creationDate, creatorId, action);
        // recursive call to get the current object
        processFileList(currentDirectoryPath, creationDate, creatorId, action);
    }
}

From source file:io.stallion.secrets.SecretsVault.java

public List<String> getSecretNames() {
    List<String> secretNames = new ArrayList<String>(secrets.keySet());
    secretNames.sort(new Comparator<String>() {
        @Override//from  w w w  .j a  v  a2s .c  o  m
        public int compare(String o1, String o2) {
            return o1.compareTo(o2);
        }
    });
    return secretNames;
}