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.brown.utils.TestCollectionUtil.java

/**
 * testSortByValues/*from w w w.j  ava  2s .c o  m*/
 */
public void testSortByValues() {
    Map<String, Integer> map = new HashMap<String, Integer>();
    map.put("b", 2000);
    map.put("a", 1000);
    map.put("c", 4000);
    map.put("d", 3000);

    Map<String, Integer> sorted = CollectionUtil.sortByValues(map);
    assertNotNull(sorted);
    assertEquals(map.size(), sorted.size());
    assert (map.keySet().containsAll(sorted.keySet()));
    assert (map.values().containsAll(sorted.values()));

    List<String> list = new ArrayList<String>(sorted.keySet());
    assertEquals("a", list.get(0));
    Collections.reverse(list);
    assertEquals("c", list.get(0));
}

From source file:com.agiletec.plugins.jpwebmail.apsadmin.webmail.folder.WebmailAction.java

protected void orderMessages(List<Message> messages) {
    //TODO PER ORA ORDINA PER DATA DISCENDENTE... POI STRUTTURARE OPZIONI
    BeanComparator comparator = new BeanComparator("receivedDate");
    Collections.sort(messages, comparator);
    Collections.reverse(messages);
}

From source file:com.yahoo.bard.webservice.config.ConfigurationGraph.java

/**
 * Take a configuration and if it is a valid module, load it into the moduleConfigurations map and load it's
 * dependency moduleDependencies./* w  w  w .j a v  a2s .c  o  m*/
 *
 * @param configuration  A configuration which may be a module
 * @param configName  The resource name for that configuration
 * @param nameValidator  A function which throws exceptions on module names which are not valid.
 */
@SuppressWarnings("unchecked")
private void addVertex(Configuration configuration, String configName, Consumer<String> nameValidator) {
    if (!configuration.containsKey(MODULE_NAME_KEY)) {
        // This may be the result of another library using one of our configuration names
        LOG.warn(MODULE_NAME_MISSING.logFormat(configName));
        return;
    }
    String moduleName = configuration.getString(MODULE_NAME_KEY);
    nameValidator.accept(moduleName);

    LOG.debug(MODULE_FOUND_MESSAGE.logFormat(moduleName, configName));
    if (moduleConfigurations.containsKey(moduleName)) {
        LOG.error(MODULE_NAME_DUPLICATION.format(configName, moduleName));
        throw new SystemConfigException(MODULE_NAME_DUPLICATION.format(configName, moduleName));
    }
    moduleConfigurations.put(moduleName, configuration);

    List<String> dependencies = new ArrayList<>(
            configuration.getList(DEPENDENT_MODULE_KEY, Collections.<String>emptyList()));
    // later dependencies have higher precedence.  Store moduleDependencies in precedence order descending
    Collections.reverse(dependencies);
    moduleDependencies.put(moduleName, dependencies);
}

From source file:backtype.storm.utils.VersionedStore.java

/**
 * Sorted from most recent to oldest//w  w  w.j  a  v  a  2  s.  c  om
 */
public List<Long> getAllVersions() throws IOException {
    List<Long> ret = new ArrayList<Long>();
    for (String s : listDir(_root)) {
        if (s.endsWith(FINISHED_VERSION_SUFFIX)) {
            ret.add(validateAndGetVersion(s));
        }
    }
    Collections.sort(ret);
    Collections.reverse(ret);
    return ret;
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.publico.ViewCourseInquiryPublicResults.java

public static ActionForward getCourseResultsActionForward(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response) {
    String executionCourseId = request.getParameter("executionCourseOID");
    if (executionCourseId == null) {
        executionCourseId = request.getParameter("executionCourseID");
    }//w ww  .j av a  2  s .com
    ExecutionCourse executionCourse = FenixFramework.getDomainObject(executionCourseId);
    ExecutionSemester executionPeriod = executionCourse.getExecutionPeriod();

    CurricularCourseInquiryTemplate curricularCourseInquiryTemplate = CurricularCourseInquiryTemplate
            .getTemplateByExecutionPeriod(executionPeriod);
    if (curricularCourseInquiryTemplate == null) {
        request.setAttribute("notAvailableMessage", "message.inquiries.publicResults.notAvailable.m1");
        return mapping.findForward("execution-course-student-inquiries-result-notAvailable");
    }

    DegreeCurricularPlan dcp = FenixFramework.getDomainObject(request.getParameter("degreeCurricularPlanOID"));
    ExecutionDegree executionDegree = dcp
            .getExecutionDegreeByAcademicInterval(executionPeriod.getAcademicInterval());
    List<InquiryResult> results = executionCourse
            .getInquiryResultsByExecutionDegreeAndForTeachers(executionDegree);
    boolean hasNotRelevantData = executionCourse.hasNotRelevantDataFor(executionDegree);

    ResultsInquiryTemplate resultsInquiryTemplate = ResultsInquiryTemplate
            .getTemplateByExecutionPeriod(executionPeriod);
    Collection<InquiryBlock> resultBlocks = resultsInquiryTemplate.getInquiryBlocksSet();

    GroupResultsSummaryBean ucGroupResultsSummaryBean = getGeneralResults(results, resultBlocks,
            GroupResultType.COURSE_RESULTS);
    GroupResultsSummaryBean answersResultsSummaryBean = getGeneralResults(results, resultBlocks,
            GroupResultType.COURSE_ANSWERS);
    GroupResultsSummaryBean nonAnswersResultsSummaryBean = getGeneralResults(results, resultBlocks,
            GroupResultType.COURSE_NON_ANSWERS);
    if (executionCourse.getAvailableForInquiries()) {
        Collections.sort(nonAnswersResultsSummaryBean.getQuestionsResults(),
                new BeanComparator("questionResult.value"));
        Collections.reverse(nonAnswersResultsSummaryBean.getQuestionsResults());
    }

    CurricularCourse curricularCourse = executionCourse.getCurricularCourseFor(dcp);
    Double ects = curricularCourse.getEctsCredits(executionPeriod);
    Double contactLoadEcts = curricularCourse.getContactLoad() / 28;
    Double autonumousWorkEcts = ects - contactLoadEcts;

    GroupResultsSummaryBean workLoadSummaryBean = getGeneralResults(results, resultBlocks,
            GroupResultType.WORKLOAD);
    request.setAttribute("contactLoadEcts", contactLoadEcts);
    request.setAttribute("autonumousWorkEcts", autonumousWorkEcts);
    GroupResultsSummaryBean ucGeneralDataSummaryBean = getGeneralResults(results, resultBlocks,
            GroupResultType.COURSE_GENERAL_DATA);
    GroupResultsSummaryBean ucEvaluationsGroupBean = getGeneralResults(results, resultBlocks,
            GroupResultType.COURSE_EVALUATIONS);
    InquiryQuestion estimatedEvaluationQuestion = getEstimatedEvaluationsQuestion(
            curricularCourseInquiryTemplate.getInquiryBlocksSet());
    QuestionResultsSummaryBean estimatedEvaluationBeanQuestion = new QuestionResultsSummaryBean(
            estimatedEvaluationQuestion, getResultsForQuestion(results, estimatedEvaluationQuestion), null,
            null);

    InquiryQuestion totalAnswersQuestion = getInquiryQuestion(results, InquiryResultType.COURSE_TOTAL_ANSWERS);
    request.setAttribute("totalAnswers", new QuestionResultsSummaryBean(totalAnswersQuestion,
            getResultsForQuestion(results, totalAnswersQuestion).iterator().next()));

    List<TeacherShiftTypeGeneralResultBean> teachersSummaryBeans = getTeachersShiftsResults(executionCourse);
    Collections.sort(teachersSummaryBeans, new BeanComparator("professorship.person.name"));
    Collections.sort(teachersSummaryBeans, new BeanComparator("shiftType"));

    ResultClassification auditResult = getAuditResult(results);
    if (auditResult != null) {
        request.setAttribute("auditResult", auditResult.name());
    }

    request.setAttribute("ucGroupResultsSummaryBean", ucGroupResultsSummaryBean);
    request.setAttribute("answersResultsSummaryBean", answersResultsSummaryBean);
    request.setAttribute("nonAnswersResultsSummaryBean", nonAnswersResultsSummaryBean);
    request.setAttribute("workLoadSummaryBean", workLoadSummaryBean);
    request.setAttribute("ucGeneralDataSummaryBean", ucGeneralDataSummaryBean);
    request.setAttribute("ucEvaluationsGroupBean", ucEvaluationsGroupBean);
    request.setAttribute("estimatedEvaluationBeanQuestion", estimatedEvaluationBeanQuestion);
    request.setAttribute("teachersSummaryBeans", teachersSummaryBeans);

    CurricularCourseInquiryTemplate courseInquiryTemplate = CurricularCourseInquiryTemplate
            .getTemplateByExecutionPeriod(executionPeriod);
    List<BlockResultsSummaryBean> blockResultsSummaryBeans = new ArrayList<BlockResultsSummaryBean>();

    for (InquiryBlock inquiryBlock : courseInquiryTemplate.getInquiryBlocksSet()) {
        blockResultsSummaryBeans.add(new BlockResultsSummaryBean(inquiryBlock, results, null, null));
    }
    Collections.sort(blockResultsSummaryBeans, new BeanComparator("inquiryBlock.blockOrder"));

    request.setAttribute("hasNotRelevantData", hasNotRelevantData);
    request.setAttribute("executionCourse", executionCourse);
    request.setAttribute("executionPeriod", executionPeriod);
    request.setAttribute("executionDegree", executionDegree);
    request.setAttribute("resultsDate", results.iterator().next().getResultDate());
    request.setAttribute("blockResultsSummaryBeans", blockResultsSummaryBeans);

    request.setAttribute("publicContext", true);
    return new ActionForward(null, "/inquiries/showCourseInquiryResult_v3.jsp", false, "/teacher");
}

From source file:gephi.spade.panel.FCSOperations.java

public List<AttributeValuePair> computeTStat() {
    ArrayList<AttributeValuePair> stats = new ArrayList<AttributeValuePair>();
    for (int i = 0; i < fcsInputFile.getNumChannels(); i++) {
        String name = fcsInputFile.getChannelShortName(i);
        if (name.contentEquals("Time") || name.contentEquals("time") || name.contentEquals("cluster")
                || name.contentEquals("density")) {
            continue;
        }//from  www.jav a2  s .c om
        stats.add(new AttributeValuePair(name, tTest(eventsSlctd, eventsInitl, i)));
    }
    Collections.sort(stats);
    Collections.reverse(stats);
    return stats;
}

From source file:fr.landel.utils.assertor.helper.HelperAssertor.java

/**
 * Validates matcher mode and return the steps list reversed
 * /*from   w  w  w .ja  v a2  s.  c  o  m*/
 * @param step
 *            the end step
 * @param matcherMode
 *            if in matcher mode
 * @param <T>
 *            the type of current chcecked object
 * @return the steps list reversed
 * @throws UnsupportedOperationException
 *             if in matcher mode and if steps of type
 *             {@link EnumStep#CREATION}, {@link EnumStep#OBJECT} are found
 *             in the chain
 */
private static <T> List<StepAssertor<?>> validatesAndReverse(final StepAssertor<T> step,
        final boolean matcherMode) {

    final List<StepAssertor<?>> steps = new ArrayList<>();
    steps.add(step);

    final boolean inMatcherMode = matcherMode || EnumStep.PREDICATE_OBJECT.equals(step.getStepType());

    StepAssertor<?> first = null;
    StepAssertor<?> currentStep = step;
    StepAssertor<?> previousStep;

    while ((previousStep = currentStep.getPreviousStep()) != null) {

        if (inMatcherMode) {
            final EnumStep s = previousStep.getStepType();

            if (EnumStep.PREDICATE.equals(s)) {
                first = previousStep;

            } else if (EnumStep.CREATION.equals(s) || EnumStep.OBJECT.equals(s)) {
                throw new UnsupportedOperationException("Creation step cannot be used in Predicate mode");
            }
        }

        steps.add(previousStep);

        currentStep = previousStep;
    }

    if (inMatcherMode && first == null) {
        throw new IllegalArgumentException("StepAssertor chain must contain a matcher step");
    }

    Collections.reverse(steps);

    return steps;
}

From source file:com.haulmont.cuba.gui.app.core.appproperties.AppPropertiesDatasource.java

private List<String> nameParts(AppPropertyEntity entity) {
    List<String> list = new ArrayList<>();
    AppPropertyEntity e = entity;//w w  w.  ja v a 2 s  . c  om
    while (e != null) {
        list.add(e.getName());
        e = e.getParent();
    }
    Collections.reverse(list);
    return list;
}

From source file:com.bellman.bible.service.format.osistohtml.strongs.StrongsHandler.java

/**
 * Convert a Strongs lemma into a url E.g. lemmas "strong:H0430",
 * "strong:H0853 strong:H01254"/* w w w .ja  va 2  s  .c o  m*/
 * 
 * @return a single char to use as a note ref
 */
private List<String> getStrongsAndMorphTags(String strongsLemma, String morphology) {
    // there may occasionally be more than one ref so split them into a list
    // of single refs
    List<String> strongsTags = getStrongsTags(strongsLemma);
    List<String> morphTags = getMorphTags(morphology);

    List<String> mergedStrongsAndMorphTags = new ArrayList<String>();

    // each morph tag should relate to a Strongs tag so they should be same
    // length but can't assume that
    // merge the tags into the merge list
    for (int i = 0; i < Math.max(strongsTags.size(), morphTags.size()); i++) {
        StringBuilder merged = new StringBuilder();
        if (i < strongsTags.size()) {
            merged.append(strongsTags.get(i));
        }
        if (i < morphTags.size()) {
            merged.append(morphTags.get(i));
        }
        mergedStrongsAndMorphTags.add(merged.toString());
    }

    // for some reason the generic tags should come last and the order seems
    // always reversed in other systems
    // the second tag (once reversed) seems to relate to a missing word like
    // eth
    Collections.reverse(mergedStrongsAndMorphTags);
    return mergedStrongsAndMorphTags;
}

From source file:de.larmic.butterfaces.component.showcase.table.TableShowcase.java

public List<DemoPojo> getStringRows() {
    if (demoPojos.isEmpty()) {
        for (int row = 0; row < 10; row++) {
            final int rowNumber = row + 1;
            demoPojos.add(new DemoPojo(rowNumber, String.format("r%sc1", rowNumber),
                    String.format("r%sc2", rowNumber)));
        }//from   w  w w  .j  av  a2s.  co  m
    }

    if (toolBarType == ToolBarType.SERVER_FILTER && StringUtils.isNotEmpty(filterValue)) {
        final List<DemoPojo> filteredDemoPojos = new ArrayList<>();

        for (DemoPojo demoPojo : demoPojos) {
            if (StringUtils.containsIgnoreCase(demoPojo.getA(), filterValue)
                    || StringUtils.containsIgnoreCase(demoPojo.getB(), filterValue)) {
                filteredDemoPojos.add(demoPojo);
            }
        }

        return filteredDemoPojos;
    }

    if (this.shouldReverseRows()) {
        Collections.reverse(demoPojos);
    }

    return demoPojos;
}