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:br.com.ingenieux.mojo.beanstalk.version.RollbackVersionMojo.java

@Override
protected Object executeInternal() throws MojoExecutionException, MojoFailureException {
    // TODO: Deal with withVersionLabels
    DescribeApplicationVersionsRequest describeApplicationVersionsRequest = new DescribeApplicationVersionsRequest()
            .withApplicationName(applicationName);

    DescribeApplicationVersionsResult appVersions = getService()
            .describeApplicationVersions(describeApplicationVersionsRequest);

    DescribeEnvironmentsRequest describeEnvironmentsRequest = new DescribeEnvironmentsRequest()
            .withApplicationName(applicationName).withEnvironmentIds(curEnv.getEnvironmentId())
            .withEnvironmentNames(curEnv.getEnvironmentName()).withIncludeDeleted(false);

    DescribeEnvironmentsResult environments = getService().describeEnvironments(describeEnvironmentsRequest);

    List<ApplicationVersionDescription> appVersionList = new ArrayList<ApplicationVersionDescription>(
            appVersions.getApplicationVersions());

    List<EnvironmentDescription> environmentList = environments.getEnvironments();

    if (environmentList.isEmpty()) {
        throw new MojoFailureException("No environments were found");
    }//from w  w  w  . j  a v a 2  s . com

    EnvironmentDescription d = environmentList.get(0);

    Collections.sort(appVersionList, new Comparator<ApplicationVersionDescription>() {
        @Override
        public int compare(ApplicationVersionDescription o1, ApplicationVersionDescription o2) {
            return new CompareToBuilder().append(o1.getDateUpdated(), o2.getDateUpdated()).toComparison();
        }
    });

    Collections.reverse(appVersionList);

    if (latestVersionInstead) {
        ApplicationVersionDescription latestVersionDescription = appVersionList.get(0);

        return changeToVersion(d, latestVersionDescription);
    }

    ListIterator<ApplicationVersionDescription> versionIterator = appVersionList.listIterator();

    String curVersionLabel = d.getVersionLabel();

    while (versionIterator.hasNext()) {
        ApplicationVersionDescription versionDescription = versionIterator.next();

        String versionLabel = versionDescription.getVersionLabel();

        if (curVersionLabel.equals(versionLabel) && versionIterator.hasNext()) {
            return changeToVersion(d, versionIterator.next());
        }
    }

    throw new MojoFailureException("No previous version was found (current version: " + curVersionLabel);
}

From source file:net.sourceforge.fenixedu.presentationTier.backBeans.person.OrganizationalStructureBackingBean.java

public List<SelectItem> getExecutionYears() throws FenixServiceException {
    final Set<ExecutionYear> executionYears = rootDomainObject.getExecutionYearsSet();

    List<SelectItem> result = new ArrayList<SelectItem>(executionYears.size());
    for (ExecutionYear executionYear : executionYears) {
        if (executionYear.getYear().compareTo("2005/2006") >= 0) {
            result.add(new SelectItem(executionYear.getExternalId(), executionYear.getYear(),
                    executionYear.getState().getStateCode()));
        }/*from   w  w w  .  ja  v  a  2 s .  c  om*/
    }

    Collections.reverse(result);
    if (getChoosenExecutionYearID() == null) {
        for (SelectItem selectExecutionYear : result) {
            if (selectExecutionYear.getDescription().equals(PeriodState.CURRENT_CODE)) {
                setChoosenExecutionYearID((String) selectExecutionYear.getValue());
            }
        }
    }

    return result;
}

From source file:com.haulmont.cuba.gui.ControllerDependencyInjector.java

public void inject() {
    Map<AnnotatedElement, Class> toInject = new HashMap<>();

    @SuppressWarnings("unchecked")
    List<Class> classes = ClassUtils.getAllSuperclasses(frame.getClass());
    classes.add(0, frame.getClass());/*from w w  w  .j  a v  a2s  .  co m*/
    Collections.reverse(classes);

    for (Field field : getAllFields(classes)) {
        Class aClass = injectionAnnotation(field);
        if (aClass != null) {
            toInject.put(field, aClass);
        }
    }
    for (Method method : frame.getClass().getMethods()) {
        Class aClass = injectionAnnotation(method);
        if (aClass != null) {
            toInject.put(method, aClass);
        }
    }

    for (Map.Entry<AnnotatedElement, Class> entry : toInject.entrySet()) {
        doInjection(entry.getKey(), entry.getValue());
    }

    injectEventListeners(frame);
}

From source file:com.cloudera.oryx.rdf.common.rule.NumericDecision.java

static List<Decision> numericDecisionsFromExamples(int featureNumber, Iterable<Example> examples,
        int suggestedMaxSplitCandidates) {
    Multiset<Float> sortedFeatureValueCounts = TreeMultiset.create();
    StorelessUnivariateStatistic mean = new Mean();
    int numExamples = 0;
    for (Example example : examples) {
        NumericFeature feature = (NumericFeature) example.getFeature(featureNumber);
        if (feature == null) {
            continue;
        }//w  w w  .  j  a  v a 2s .  c  om
        numExamples++;
        float value = feature.getValue();
        sortedFeatureValueCounts.add(value, 1);
        mean.increment(value);
    }

    // Make decisions from split points that divide up input into roughly equal amounts of examples
    List<Decision> decisions = Lists.newArrayListWithExpectedSize(suggestedMaxSplitCandidates);
    int approxExamplesPerSplit = FastMath.max(1, numExamples / suggestedMaxSplitCandidates);
    int examplesInSplit = 0;
    float lastValue = Float.NaN;
    // This will iterate in order of value by nature of TreeMap
    for (Multiset.Entry<Float> entry : sortedFeatureValueCounts.entrySet()) {
        float value = entry.getElement();
        if (examplesInSplit >= approxExamplesPerSplit) {
            decisions.add(
                    new NumericDecision(featureNumber, (value + lastValue) / 2.0f, (float) mean.getResult()));
            examplesInSplit = 0;
        }
        examplesInSplit += entry.getCount();
        lastValue = value;
    }

    // The vital condition here is that if decision n decides an example is positive, then all subsequent
    // decisions in the list will also find it positive. So we need to order from highest threshold to lowest
    Collections.reverse(decisions);
    return decisions;
}

From source file:com.acc.storefront.controllers.misc.MiniCartController.java

@RequestMapping(value = "/cart/rollover/" + COMPONENT_UID_PATH_VARIABLE_PATTERN, method = RequestMethod.GET)
public String rolloverMiniCartPopup(@PathVariable final String componentUid, final Model model)
        throws CMSItemNotFoundException {
    final CartData cartData = cartFacade.getSessionCart();
    model.addAttribute("cartData", cartData);

    final MiniCartComponentModel component = (MiniCartComponentModel) cmsComponentService
            .getSimpleCMSComponent(componentUid);

    final List entries = cartData.getEntries();
    if (entries != null) {
        Collections.reverse(entries);
        model.addAttribute("entries", entries);

        model.addAttribute("numberItemsInCart", Integer.valueOf(entries.size()));
        if (entries.size() < component.getShownProductCount()) {
            model.addAttribute("numberShowing", Integer.valueOf(entries.size()));
        } else {/*from   w  w  w  . j a  va2s. co m*/
            model.addAttribute("numberShowing", Integer.valueOf(component.getShownProductCount()));
        }
    }
    model.addAttribute("lightboxBannerComponent", component.getLightboxBannerComponent());

    return ControllerConstants.Views.Fragments.Cart.CartPopup;
}

From source file:com.jnj.b2b.storefront.controllers.misc.MiniCartController.java

@RequestMapping(value = "/cart/rollover/" + COMPONENT_UID_PATH_VARIABLE_PATTERN, method = { RequestMethod.GET,
        RequestMethod.POST })/*from w  w w. j  a  va2 s.  c  o  m*/
public String rolloverMiniCartPopup(@PathVariable final String componentUid, final Model model)
        throws CMSItemNotFoundException {
    final CartData cartData = cartFacade.getSessionCart();

    model.addAttribute("cartData", cartData);

    final MiniCartComponentModel component = (MiniCartComponentModel) cmsComponentService
            .getSimpleCMSComponent(componentUid);

    final List entries = cartData.getEntries();
    if (entries != null) {
        Collections.reverse(entries);
        model.addAttribute("entries", entries);

        model.addAttribute("numberItemsInCart", Integer.valueOf(entries.size()));
        if (entries.size() < component.getShownProductCount()) {
            model.addAttribute("numberShowing", Integer.valueOf(entries.size()));
        } else {
            model.addAttribute("numberShowing", Integer.valueOf(component.getShownProductCount()));
        }
    }
    model.addAttribute("lightboxBannerComponent", component.getLightboxBannerComponent());

    return ControllerConstants.Views.Fragments.Cart.CartPopup;
}

From source file:org.orcid.api.t2.server.delegator.T2OrcidApiServiceDelegatorTest.java

@AfterClass
public static void removeDBUnitData() throws Exception {
    Collections.reverse(DATA_FILES);
    removeDBUnitData(DATA_FILES);
}

From source file:org.openmrs.module.webservices.rest.web.v1_0.search.openmrs1_8.EncounterSearchHandler1_8.java

@Override
public PageableResult search(RequestContext context) throws ResponseException {
    String patientUuid = context.getRequest().getParameter("patient");
    String encounterTypeUuid = context.getRequest().getParameter("encounterType");

    String dateFrom = context.getRequest().getParameter(DATE_FROM);
    String dateTo = context.getRequest().getParameter(DATE_TO);

    Date fromDate = dateFrom != null ? (Date) ConversionUtil.convert(dateFrom, Date.class) : null;
    Date toDate = dateTo != null ? (Date) ConversionUtil.convert(dateTo, Date.class) : null;

    Patient patient = ((PatientResource1_8) Context.getService(RestService.class)
            .getResourceBySupportedClass(Patient.class)).getByUniqueId(patientUuid);
    EncounterType encounterType = ((EncounterTypeResource1_8) Context.getService(RestService.class)
            .getResourceBySupportedClass(EncounterType.class)).getByUniqueId(encounterTypeUuid);
    if (patient != null && encounterType != null) {
        List<Encounter> encounters = Context.getEncounterService().getEncounters(patient, null, fromDate,
                toDate, null, Arrays.asList(encounterType), null, false);
        String order = context.getRequest().getParameter("order");
        if ("desc".equals(order)) {
            Collections.reverse(encounters);
        }/*  w ww.  j ava2  s  .  c om*/
        return new NeedsPaging<Encounter>(encounters, context);
    }
    return new EmptySearchResult();
}

From source file:se.uu.it.cs.recsys.ruleminer.datastructure.builder.FPTreeHeaderTableBuilder.java

/**
 *
 * @param idAndCount item id and count//from   w  ww  .  j  a v  a  2 s .c  o m
 * @param threshold, min support
 * @return non-null HeaderTableItem if the input contains id meets threshold
 * requirement; otherwise null.
 */
public static List<HeaderTableItem> build(Map<Integer, Integer> idAndCount, Integer threshold) {

    List<HeaderTableItem> instance = new ArrayList<>();

    Map<Integer, Integer> filteredIdAndCount = Util.filter(idAndCount, threshold);

    if (filteredIdAndCount.isEmpty()) {
        LOGGER.debug("Empty map after filtering. Empty list will be returned. Source: {}", idAndCount);
        return instance;
    }

    List<Integer> countList = new ArrayList<>(filteredIdAndCount.values());
    Collections.sort(countList);
    Collections.reverse(countList);// now the count is in DESC order

    for (int i = 1; i <= filteredIdAndCount.size(); i++) {
        instance.add(new HeaderTableItem()); // in order to call list.set(idx,elem)
    }

    Map<Integer, Set<Integer>> forIdsHavingSameCount = new HashMap<>();//different ids may have same count

    filteredIdAndCount.entrySet().forEach((entry) -> {
        Integer courseId = entry.getKey();
        Integer count = entry.getValue();

        Integer countFrequence = Collections.frequency(countList, count);

        if (countFrequence == 1) {
            Integer countIdx = countList.indexOf(count);
            instance.set(countIdx, new HeaderTableItem(new Item(courseId, count)));
        } else {
            // different ids have same count

            if (!forIdsHavingSameCount.containsKey(count)) {
                forIdsHavingSameCount.put(count, Util.findDuplicatesIndexes(countList, count));
            }

            Iterator<Integer> itr = forIdsHavingSameCount.get(count).iterator();
            Integer idx = itr.next();
            itr.remove();

            instance.set(idx, new HeaderTableItem(new Item(courseId, count)));
        }

    });

    //        LOGGER.debug("Final built header table: {}",
    //                instance.stream()
    //                .map(headerItem -> headerItem.getItem()).collect(Collectors.toList()));

    return instance;
}

From source file:com.epam.cme.storefront.controllers.misc.TelcoMiniCartController.java

@RequestMapping(value = "/cart/rollover/" + COMPONENT_UID_PATH_VARIABLE_PATTERN, method = RequestMethod.GET)
public String rolloverMiniCartPopup(@PathVariable final String componentUid, final Model model)
        throws CMSItemNotFoundException {
    final CartData cartData = cartFacade.getMiniCart();
    model.addAttribute("cartData", cartData);
    final Integer allEntriesCount = cartData.getAllEntriesCount();
    final MiniCartComponentModel component = (MiniCartComponentModel) cmsComponentService
            .getSimpleCMSComponent(componentUid);

    final List entries = cartData.getEntries();
    if (entries != null) {
        Collections.reverse(entries);
        model.addAttribute("entries", entries);
        model.addAttribute("numberItemsInCart",
                allEntriesCount == null ? Integer.valueOf(entries.size()) : allEntriesCount);

        if (entries.size() < component.getShownProductCount()) {
            model.addAttribute("numberShowing", Integer.valueOf(entries.size()));
        } else {//from w  w  w.j  a  v a  2 s.co  m
            model.addAttribute("numberShowing", Integer.valueOf(component.getShownProductCount()));
        }
    }
    model.addAttribute("lightboxBannerComponent", component.getLightboxBannerComponent());

    return ControllerConstants.Views.Fragments.Cart.CartPopup;
}