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:com.db2eshop.gui.dialog.ErrorDialog.java

/**
 * <p>showError.</p>/* w  w w. jav  a  2  s  .c  o  m*/
 *
 * @param message a {@link java.lang.String} object.
 * @param throwable a {@link java.lang.Throwable} object.
 */
public void showError(String message, Throwable throwable) {
    log.error(message, throwable);

    embeddedContentPane.removeAll();
    embeddedContentPane.setLayout(new MigLayout("fill"));

    ErrorTile tile = new ErrorTile(message, throwable, scrollPane);
    errors.add(tile);

    Collections.reverse(errors);
    for (ErrorTile errorTile : errors) {
        embeddedContentPane.add(errorTile, "north");
        embeddedContentPane.updateUI();
    }
    Collections.reverse(errors);

    scrollPane.updateUI();
    scrollPane.revalidate();
    if (!this.isVisible()) {
        this.setVisible(true);
    }
}

From source file:org.training.storefront.breadcrumb.impl.ProductBreadcrumbBuilder.java

public List<Breadcrumb> getBreadcrumbs(final ProductModel productModel) throws IllegalArgumentException {
    final List<Breadcrumb> breadcrumbs = new ArrayList<>();

    final Collection<CategoryModel> categoryModels = new ArrayList<>();
    final Breadcrumb last;

    final ProductModel baseProductModel = getBaseProduct(productModel);
    last = getProductBreadcrumb(baseProductModel);
    categoryModels.addAll(baseProductModel.getSupercategories());
    last.setLinkClass(LAST_LINK_CLASS);//from w  ww .j  av  a  2s. co m

    breadcrumbs.add(last);

    while (!categoryModels.isEmpty()) {
        CategoryModel toDisplay = null;
        for (final CategoryModel categoryModel : categoryModels) {
            if (!(categoryModel instanceof ClassificationClassModel)) {
                if (toDisplay == null) {
                    toDisplay = categoryModel;
                }
                if (getBrowseHistory().findEntryMatchUrlEndsWith(categoryModel.getCode()) != null) {
                    break;
                }
            }
        }
        categoryModels.clear();
        if (toDisplay != null) {
            breadcrumbs.add(getCategoryBreadcrumb(toDisplay));
            categoryModels.addAll(toDisplay.getSupercategories());
        }
    }
    Collections.reverse(breadcrumbs);
    return breadcrumbs;
}

From source file:com.stratuscom.harvester.codebase.ClassServerCodebaseContext.java

@Override
public URL[] getCodebaseAnnotation() {
    try {//from   w  ww . j  av a 2s. c  om
        if (codebaseAnnotation == null) {
            /*
            codebase is derived from the list of file objects.
            */
            codebaseAnnotation = new ArrayList<URL>();
            for (String path : fileEntries.keySet()) {
                codebaseAnnotation.add(
                        new URL(Strings.HTTP_COLON + Strings.SLASH_SLASH + classServer.getHost() + Strings.COLON
                                + classServer.getPort() + Strings.SLASH + appId + Strings.SLASH + path));
            }
        }

        // Just to see if it fixes our download problem, reverse the list.
        // Yep, that fixes it, by totally shutting off the preferred codebase
        // mechanism.
        // TODO:  We really ought to be exporting a wrapper jar with a combined 
        // preferred list.
        Collections.reverse(codebaseAnnotation);
        return codebaseAnnotation.toArray(new URL[0]);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:de.hybris.platform.acceleratorstorefrontcommons.breadcrumb.impl.ProductBreadcrumbBuilder.java

/**
 * Returns a list of breadcrumbs for the given product.
 *
 * @param productCode// w  w  w  .j  a v a 2s . c om
 * @return breadcrumbs for the given product
 */
public List<Breadcrumb> getBreadcrumbs(final String productCode) {
    final ProductModel productModel = getProductService().getProductForCode(productCode);
    final List<Breadcrumb> breadcrumbs = new ArrayList<>();

    final Collection<CategoryModel> categoryModels = new ArrayList<>();
    final Breadcrumb last;

    final ProductModel baseProductModel = getBaseProduct(productModel);
    last = getProductBreadcrumb(baseProductModel);
    categoryModels.addAll(baseProductModel.getSupercategories());
    last.setLinkClass(LAST_LINK_CLASS);

    breadcrumbs.add(last);

    while (!categoryModels.isEmpty()) {
        CategoryModel toDisplay = null;
        toDisplay = processCategoryModels(categoryModels, toDisplay);
        categoryModels.clear();
        if (toDisplay != null) {
            breadcrumbs.add(getCategoryBreadcrumb(toDisplay));
            categoryModels.addAll(toDisplay.getSupercategories());
        }
    }
    Collections.reverse(breadcrumbs);
    return breadcrumbs;
}

From source file:controller.HostelController.java

@ResponseBody
@RequestMapping(value = "/pass.do")
public Map pass(@RequestBody Map name, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    String jname = (String) name.get("name");
    hostelService.pass(jname);//from   www .ja v a2s  . c  o m
    Map<String, Object> result = new HashMap<String, Object>();
    List<Application> applications = hostelService.getApplications();
    Collections.reverse(applications);
    result.put("applications", applications);
    return result;
}

From source file:com.exxonmobile.ace.hybris.storefront.breadcrumb.impl.ProductBreadcrumbBuilder.java

public List<Breadcrumb> getBreadcrumbs(final ProductModel productModel) throws IllegalArgumentException {
    final List<Breadcrumb> breadcrumbs = new ArrayList<Breadcrumb>();

    final Collection<CategoryModel> categoryModels = new ArrayList<CategoryModel>();
    final Breadcrumb last;

    final ProductModel baseProductModel = getBaseProduct(productModel);
    last = getProductBreadcrumb(baseProductModel);
    categoryModels.addAll(baseProductModel.getSupercategories());
    last.setLinkClass(LAST_LINK_CLASS);//w  ww  .  j  a  va 2  s  .com

    breadcrumbs.add(last);

    while (!categoryModels.isEmpty()) {
        CategoryModel toDisplay = null;
        for (final CategoryModel categoryModel : categoryModels) {
            if (!(categoryModel instanceof ClassificationClassModel)) {
                if (toDisplay == null) {
                    toDisplay = categoryModel;
                }
                if (getBrowseHistory().findUrlInHistory(categoryModel.getCode()) != null) {
                    break;
                }
            }
        }
        categoryModels.clear();
        if (toDisplay != null) {
            breadcrumbs.add(getCategoryBreadcrumb(toDisplay));
            categoryModels.addAll(toDisplay.getSupercategories());
        }
    }
    Collections.reverse(breadcrumbs);
    return breadcrumbs;
}

From source file:com.vsct.dt.hesperides.events.EventsAggregate.java

@Override
public List<EventData> getEventsList(final String streamName, final int page, final int size) {

    Callable<List<EventData>> task = () -> {
        List<Event> list = this.eventStore.getEventsList(streamName, page, size);

        List<EventData> events = new ArrayList<>();

        try {//from   ww w .j a va  2  s  .com
            // Converting the data field from String to Object : this is useful for the front-end uses
            for (Event e : list) {
                Object data = MAPPER.readValue(e.getData(), Class.forName(e.getEventType()));
                events.add(new EventData(e.getEventType(), data, e.getTimestamp(), e.getUser()));
            }

            // Sort in inverse order
            Collections.reverse(events);
            return events;
        } catch (IOException | ClassNotFoundException e) {
            LOGGER.debug(" Error while convertingEvent to EventData. Message : {}", e.getMessage());
            return null;
        }
    };

    List<EventData> results = null;
    try {
        results = executor.submit(task).get();
    } catch (InterruptedException | ExecutionException e) {
        LOGGER.debug(" Execution error while getting events list. Message : {}", e.getMessage());
    }

    return results;
}

From source file:org.openmrs.module.rheapocadapter.web.controller.TransactionServiceController.java

@RequestMapping("/module/rheapocadapter/errorQueue.form")
public String showErrorQueue(ModelMap map) {
    EnteredHandler enteredHandler = new EnteredHandler();
    List<ErrorTransaction> errorTransactions = (List<ErrorTransaction>) enteredHandler.getErrorQueue();
    Collections.reverse(errorTransactions);
    map.addAttribute("errorTransactions", errorTransactions);

    return "/module/rheapocadapter/errorQueue";
}

From source file:com.tacitknowledge.util.migration.OrderedMigrationRunnerStrategy.java

public List<MigrationTask> getRollbackCandidates(List<MigrationTask> allMigrationTasks, int[] rollbackLevels,
        PatchInfoStore currentPatchInfoStore) throws MigrationException {
    validateRollbackLevel(rollbackLevels);

    int rollbackLevel = rollbackLevels[0];
    int currentPatchLevel = currentPatchInfoStore.getPatchLevel();

    if (currentPatchLevel < rollbackLevel) {
        throw new MigrationException("The rollback patch level cannot be greater than the current patch level");
    }//from   ww  w  .  j  a  v  a2s. c  om

    PatchRollbackPredicate rollbackPredicate = new PatchRollbackPredicate(currentPatchLevel, rollbackLevel);
    List<MigrationTask> migrationCandidates = new ArrayList<MigrationTask>();
    migrationCandidates.addAll(allMigrationTasks);
    CollectionUtils.filter(migrationCandidates, rollbackPredicate);
    Collections.sort(migrationCandidates);
    // need to reverse the list do we apply the rollbacks in descending
    // order
    Collections.reverse(migrationCandidates);
    return migrationCandidates;

}

From source file:ch.ksfx.util.calc.MovingAverageCalculator.java

public static Double calculateMovingAverageForSecondsBackObservation(List<Observation> prices,
        Integer secondsBackFromNow, boolean askPrice) {
    List<Observation> aps = new ArrayList<Observation>(prices);

    Collections.sort(aps, new ObservationDateComparator());
    Collections.reverse(aps);

    Date referenceDate = DateUtils.addSeconds(aps.get(0).getObservationTime(), (secondsBackFromNow * -1));

    if (prices.get(0).getObservationTime().after(referenceDate)) {
        return null;
    }//from  w  ww .  j a v  a2  s . c o m

    List<Observation> relevantPrices = new ArrayList<Observation>();

    for (Integer iI = 0; iI < aps.size(); iI++) {
        if (aps.get(iI).getObservationTime().after(referenceDate)) {
            relevantPrices.add(aps.get(iI));
        } else {
            break;
        }
    }

    if (askPrice) {
        Double cal = 0.0;

        for (Observation ap : relevantPrices) {
            cal = cal + Double.parseDouble(ap.getScalarValue());
        }

        return cal / relevantPrices.size();
    } else {
        Double cal = 0.0;

        for (Observation ap : relevantPrices) {
            cal = cal + Double.parseDouble(ap.getScalarValue());
        }

        return cal / relevantPrices.size();
    }
}