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.opengamma.analytics.financial.schedule.QuarterlyScheduleCalculator.java

@Override
public ZonedDateTime[] getSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate,
        final boolean fromEnd, final boolean generateRecursive) {
    Validate.notNull(startDate, "start date");
    Validate.notNull(endDate, "end date");
    Validate.isTrue(startDate.isBefore(endDate) || startDate.equals(endDate));
    if (startDate.equals(endDate)) {
        return new ZonedDateTime[] { startDate };
    }//from ww w .j ava 2 s  .c  o  m
    final List<ZonedDateTime> dates = new ArrayList<ZonedDateTime>();
    if (fromEnd) {
        ZonedDateTime date = endDate;
        int i = 3;
        while (!date.isBefore(startDate)) {
            dates.add(date);
            date = generateRecursive ? date.minus(Period.ofMonths(3)) : endDate.minus(Period.ofMonths(i));
            i += 3;
        }
        Collections.reverse(dates);
        return dates.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
    }
    ZonedDateTime date = startDate;
    int i = 3;
    while (!date.isAfter(endDate)) {
        dates.add(date);
        date = generateRecursive ? date.plus(Period.ofMonths(3)) : startDate.plus(Period.ofMonths(i));
        i += 3;
    }
    return dates.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
}

From source file:com.opengamma.analytics.financial.schedule.SemiAnnualScheduleCalculator.java

@Override
public ZonedDateTime[] getSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate,
        final boolean fromEnd, final boolean generateRecursive) {
    Validate.notNull(startDate, "start date");
    Validate.notNull(endDate, "end date");
    Validate.isTrue(startDate.isBefore(endDate) || startDate.equals(endDate));
    if (startDate.equals(endDate)) {
        return new ZonedDateTime[] { startDate };
    }//  w  w w .  j a v  a 2s.  co m
    final List<ZonedDateTime> dates = new ArrayList<ZonedDateTime>();
    if (fromEnd) {
        ZonedDateTime date = endDate;
        int i = 6;
        while (!date.isBefore(startDate)) {
            dates.add(date);
            date = generateRecursive ? date.minus(Period.ofMonths(6)) : endDate.minus(Period.ofMonths(i));
            i += 6;
        }
        Collections.reverse(dates);
        return dates.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
    }
    ZonedDateTime date = startDate;
    int i = 6;
    while (!date.isAfter(endDate)) {
        dates.add(date);
        date = generateRecursive ? date.plus(Period.ofMonths(6)) : startDate.plus(Period.ofMonths(i));
        i += 6;
    }
    return dates.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
}

From source file:com.perficient.aem.weretail.datalayer.DefaultPageDataElement.java

@Override
public void updateDataLayer(DataLayer dataLayer) {
    EventInfo event = new EventInfo();
    event.setEventAction("pageLoad");
    event.setEventName("Page Load");
    dataLayer.getEvents().add(event);//from w  w  w .j a  v a2s . co  m

    Page page = dataLayer.getPage();

    PageInfo pageInfo = new PageInfo();
    if (dataLayer.getConfig().getSetAuthor() == true) {
        pageInfo.setAuthor(dataLayer.getAEMPage().getLastModifiedBy());
    }

    List<String> breadcrumbs = new ArrayList<String>();
    com.day.cq.wcm.api.Page currentPage = dataLayer.getAEMPage();
    while (currentPage != null && currentPage.getDepth() > dataLayer.getConfig().getSiteRootLevel()) {
        breadcrumbs.add(currentPage.getTitle());
        currentPage = currentPage.getParent();
    }

    Collections.reverse(breadcrumbs);
    pageInfo.setBreadcrumbs(breadcrumbs.toArray(new String[breadcrumbs.size()]));

    currentPage = dataLayer.getAEMPage();
    ValueMap properties = currentPage.getContentResource().getValueMap();
    String path = DataLayerUtil.getSiteSubpath(currentPage, dataLayer.getConfig());

    pageInfo.setDestinationUrl(DataLayerUtil.getSiteUrl(currentPage, dataLayer.getConfig()));
    if (currentPage.getOnTime() != null) {
        pageInfo.setEffectiveDate(currentPage.getOnTime().getTime());
    } else if (properties.containsKey(JcrConstants.JCR_CREATED)) {
        pageInfo.setEffectiveDate(properties.get(JcrConstants.JCR_CREATED, Date.class));
    }
    if (currentPage.getOffTime() != null) {
        pageInfo.setExpiryDate(currentPage.getOffTime().getTime());
    }
    if (properties.containsKey(JcrConstants.JCR_CREATED)) {
        pageInfo.setIssueDate(properties.get(JcrConstants.JCR_CREATED, Date.class));
    }
    pageInfo.setLanguage(currentPage.getLanguage(false).toString());
    pageInfo.setPageId(path);
    pageInfo.setPageName(currentPage.getTitle());
    if (StringUtils.isNotEmpty(dataLayer.getConfig().getPublisher())) {
        pageInfo.setPublisher(dataLayer.getConfig().getPublisher());
    }
    pageInfo.setSysEnv(dataLayer.getConfig().getEnvironment());

    page.setPageInfo(pageInfo);

    String templateName = StringUtils
            .substringAfterLast(properties.get(NameConstants.NN_TEMPLATE, String.class), "/");
    List<String> tags = new ArrayList<String>();

    Category category = new Category();
    category.setPrimaryCategory(templateName);
    for (int i = 0; i < currentPage.getTags().length; i++) {
        category.put("tag" + i, currentPage.getTags()[i].getTitle());
        tags.add(currentPage.getTags()[i].getTitle());
    }
    page.setCategory(category);

    Map<String, Object> attributes = new HashMap<String, Object>();
    attributes.put("tags", tags.toArray(new String[tags.size()]));
    attributes.put("template", templateName);
    page.setAttributes(attributes);

}

From source file:cherry.foundation.navi.NavigatorImpl.java

@Override
public List<Node> navigate(String name) {
    List<Node> list = new ArrayList<>();
    boolean flag = true;
    for (NaviNode nd = nodeMap.get(name); nd != null; nd = nd.getParent()) {
        Node node = new Node();
        node.setName(nd.getName());/*  w  w w  . j  av  a  2  s  .c o m*/
        node.setUri(nd.getUri());
        node.setLast(flag);
        list.add(node);
        flag = false;
    }
    Collections.reverse(list);
    return list;
}

From source file:com.mac.holdempoker.app.impl.SimplePlayOrder.java

private void orderPlayers(List<Player> players) {
    Map<Card, Player> initDealOrder = new TreeMap(this);
    Deck d = new SimpleDeck();
    d.buildDeck();/*from   w w  w . j  a v  a  2  s . c om*/
    d.shuffleDeck();
    players.stream().forEach((p) -> {
        initDealOrder.put(d.drawNextCard(), p);
    });

    List<Player> plyrs = new ArrayList(initDealOrder.values());
    orderedPlayers = new ArrayList(plyrs.size());
    orderedPlayers.add(plyrs.remove(plyrs.size() - 1));
    Collections.reverse(plyrs);

    for (Player p : plyrs) {
        orderedPlayers.add(0, p);
    }
    isFirstOrder = false;
}

From source file:ClassTree.java

/**
 * Constructs an ordered list starting at the highest (most general) class
 * in the tree and moving down the tree, ensuring no generalization comes
 * after one of its specializations.//from  w ww.ja va  2 s .c  om
 * @return a list ordered as above
 */
public List getOrderedList() {
    List list = new ArrayList();
    list.add(getBottom());

    buildList(getBottom(), list);

    Collections.sort(list);

    // Refactor list into a list of classes from a list of ClassTreeNodes
    for (int i = 0; i < list.size(); i++) {
        ClassTreeNode node = (ClassTreeNode) list.get(i);
        list.set(i, node.getObjectClass());
    }

    // Reverse the list so that the top class in the hierarchy comes first
    Collections.reverse(list);

    return list;
}

From source file:com.betel.flowers.web.bean.StockVentasBean.java

@PostConstruct
public void init() {
    this.nuevo = new StockVenta();
    this.nuevo.setUsername("usertest");
    this.selected = new StockVenta();
    this.stockVentas = new ArrayList<>();
    this.gerated = Boolean.TRUE;
    this.detalle = new DetalleCajaStock();
    this.barcodeList = new ArrayList<>();
    this.message = "";
    this.stockVentasG = this.stockVentaService.obtenerListFlag(1);
    if (this.stockVentasG == null) {
        this.stockVentasG = new ArrayList<>();
    } else {//from  ww  w  . j av a 2  s  . c o m
        Collections.reverse(this.stockVentasG);
        this.loadBarcodeList();
    }
}

From source file:eu.morfeoproject.fast.catalogue.planner.ScreenPlanner.java

protected List<Plan> reverse(List<Plan> planList) {
    for (Plan plan : planList) {
        Collections.reverse(plan.getUriList());
    }//from w w  w  .java 2s.com
    return planList;
}

From source file:com.sap.prd.mobile.ios.mios.FileUtils.java

private static List<String> split(File dir) {

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

    do {/* w w w  .j ava 2  s .c o m*/

        result.add(dir.getName());
        dir = dir.getParentFile();

    } while (dir != null);

    Collections.reverse(result);

    return result;

}

From source file:funnycats.RankingController.java

private Map sortByRating(Map<?, ?> unsortedMap) {
    List list = new LinkedList(unsortedMap.entrySet());

    // sort list based on comparator
    Collections.sort(list, new Comparator() {
        public int compare(Object o1, Object o2) {
            return ((Comparable) ((Map.Entry) (o1)).getValue()).compareTo(((Map.Entry) (o2)).getValue());
        }/*from w  ww  .  j a v  a 2s . c o m*/
    });
    Collections.reverse(list);

    // put sorted list into map again
    Map sortedMap = new LinkedHashMap();
    for (Iterator it = list.iterator(); it.hasNext();) {
        Map.Entry entry = (Map.Entry) it.next();
        sortedMap.put(entry.getKey(), entry.getValue());
    }
    return sortedMap;
}