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.EndOfMonthAnnualScheduleCalculator.java

public ZonedDateTime[] getSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate,
        final boolean fromEnd) {
    Validate.notNull(startDate, "start date");
    Validate.notNull(endDate, "end date");
    final ZonedDateTime[] monthly = EOM_CALCULATOR.getSchedule(startDate, endDate);
    final List<ZonedDateTime> result = new ArrayList<ZonedDateTime>();
    if (fromEnd) {
        for (int i = monthly.length - 1; i >= 0; i -= 12) {
            result.add(monthly[i]);/*from  w ww . j  a  va 2s . co  m*/
        }
        Collections.reverse(result);
        return result.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
    }
    for (int i = 0; i < monthly.length; i += 12) {
        result.add(monthly[i]);
    }
    return result.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
}

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

public ZonedDateTime[] getSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate,
        final boolean fromEnd) {
    Validate.notNull(startDate, "start date");
    Validate.notNull(endDate, "end date");
    final ZonedDateTime[] monthly = EOM_CALCULATOR.getSchedule(startDate, endDate);
    final List<ZonedDateTime> result = new ArrayList<ZonedDateTime>();
    if (fromEnd) {
        for (int i = monthly.length - 1; i >= 0; i -= 3) {
            result.add(monthly[i]);/* w ww . ja v  a2 s.  c om*/
        }
        Collections.reverse(result);
        return result.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
    }
    for (int i = 0; i < monthly.length; i += 3) {
        result.add(monthly[i]);
    }
    return result.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
}

From source file:com.sporeon.baseutil.OrdenacaoUtil.java

/**
* Mtodo responsvel por retorna uma lista de Object ordenada pelo nome do campo informado.
* @author Senio Caires// ww w .  j  a v a 2 s  .co  m
* @param lista - Lista
* @param campo - Campo
* @param tipoOrdenacao - Tipo de ordenao
* @return lista ordenada
*/
public static List ordenarLista(final List lista, final String campo, final TipoOrdenacao tipoOrdenacao) {

    if (lista != null && !lista.isEmpty() && campo != null && !(campo.trim().length() == 0)) {

        BeanComparator ordem = new BeanComparator(campo, new Comparator() {

            @Override
            public int compare(final Object o1, final Object o2) {

                int resultado = 0;
                final int maximoCaracteres = 20;

                if (o1 instanceof Integer) {
                    resultado = ((String) ManipulacaoUtil
                            .adicionarChar('0', maximoCaracteres, o2.toString(), true))
                                    .compareToIgnoreCase((String) ManipulacaoUtil.adicionarChar('0',
                                            maximoCaracteres, o1.toString(), true));
                } else {
                    resultado = ((String) o2.toString()).compareToIgnoreCase((String) o1.toString());
                }

                return resultado;
            }
        });

        Collections.sort(lista, ordem);

        if (TipoOrdenacao.CRESCENTE.equals(tipoOrdenacao)) {
            Collections.reverse(lista);
        }
    }

    return lista;
}

From source file:org.kmnet.com.fw.web.mvc.support.CompositeRequestDataValueProcessor.java

/**
 * Constructor<br>//from   www. ja  v  a2s. c o  m
 * <p>
 * Sets and initializes a list of {@link RequestDataValueProcessor}
 * </p>
 * @param processors List of {@link RequestDataValueProcessor}
 */
public CompositeRequestDataValueProcessor(RequestDataValueProcessor... processors) {

    this.processors = Collections.unmodifiableList(Arrays.asList(processors));
    List<RequestDataValueProcessor> reverse = Arrays.asList(processors);
    Collections.reverse(reverse);
    this.reversedProcessors = Collections.unmodifiableList(reverse);
    this.processActionInvocationHelper = new ProcessActionInvocationHelper();
}

From source file:whitelabel.cloud.webapp.impl.service.DashboardService.java

public Dashboard load() {

    Dashboard dashboard = new Dashboard();

    WsEndUserClient wsClient = UserUtil.getWsEndUserClient();

    AppCredit credit = wsClient.getAvailableCredit();
    dashboard.setCredit(credit);//from  ww  w  . j  ava2s  .co m

    AppVirtualDatacenter vdc = loadDatacenter();

    List<AppServerDetails> servers = null;
    List<AppLog> logs = null;

    if (vdc != null) {
        servers = vdc.getServers();
    }

    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DAY_OF_YEAR, -7);

    List<AppLog> tmp = wsClient.getLogs(null, cal.getTime(), null);
    if (tmp != null) {
        Collections.reverse(tmp);
        logs = tmp;
    }

    if (servers == null) {
        servers = new ArrayList<AppServerDetails>();
    }
    if (logs == null) {
        logs = new ArrayList<AppLog>();
    }

    dashboard.setLogs(logs);
    dashboard.setServers(servers);
    return dashboard;
}

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

public ZonedDateTime[] getSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate,
        final boolean fromEnd) {
    Validate.notNull(startDate, "start date");
    Validate.notNull(endDate, "end date");
    final ZonedDateTime[] monthly = EOM_CALCULATOR.getSchedule(startDate, endDate);
    final List<ZonedDateTime> result = new ArrayList<ZonedDateTime>();
    if (fromEnd) {
        for (int i = monthly.length - 1; i >= 0; i -= 6) {
            result.add(monthly[i]);/*from ww  w.j a va  2  s  . c  om*/
        }
        Collections.reverse(result);
        return result.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
    }
    for (int i = 0; i < monthly.length; i += 6) {
        result.add(monthly[i]);
    }
    return result.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
}

From source file:com.eyeq.pivot4j.util.MemberSelection.java

/**
 * @param member//from   w w  w .j av a  2s  .co m
 */
public void addMember(Member member) {
    List<Member> ancestors;

    TreeNode<Member> parent = this;

    Member wrappedMember = OlapUtils.wrapRaggedIfNecessary(member, cube);

    if (wrappedMember instanceof RaggedMemberWrapper) {
        RaggedMemberWrapper raggedMember = (RaggedMemberWrapper) wrappedMember;

        Member topMember = raggedMember.getTopMember();

        ancestors = new ArrayList<Member>(topMember.getAncestorMembers());
        ancestors.add(0, topMember);
    } else {
        ancestors = new ArrayList<Member>(wrappedMember.getAncestorMembers());
    }

    Collections.reverse(ancestors);

    for (Member ancestor : ancestors) {
        TreeNode<Member> node = findChild(ancestor);

        if (node == null) {
            node = new SelectionNode(ancestor, false);
            parent.addChild(node);
        }

        parent = node;
    }

    TreeNode<Member> node = findChild(wrappedMember);

    if (node == null) {
        node = new SelectionNode(wrappedMember, true);
        parent.addChild(node);
    } else {
        ((SelectionNode) node).setSelected(true);
    }

    if (!isSelected(wrappedMember)) {
        selection.add(wrappedMember);
    }
}

From source file:com.hula.lang.commands.data.Sort.java

@Override
public void execute(RuntimeConnector connector) {
    List list = (List) getVariableValue("default", connector);
    String propertyName = getVariableValueAsString("property", connector);
    String sortType = getVariableValueAsString("type", connector);
    String order = getVariableValueAsString("order", connector);

    Collections.sort(list, new HulaComparator(sortType, propertyName));

    if (order != null && order.equals("desc")) {
        Collections.reverse(list);
    }//from  w ww.j a  v a 2s . co  m
}

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

public ZonedDateTime[] getSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate,
        final boolean fromEnd) {
    Validate.notNull(startDate, "start date");
    Validate.notNull(endDate, "end date");
    Validate.isTrue(startDate.isBefore(endDate) || startDate.equals(endDate));
    final List<ZonedDateTime> dates = new ArrayList<ZonedDateTime>();
    if (fromEnd) {
        ZonedDateTime date = endDate;
        while (!date.isBefore(startDate)) {
            dates.add(date);//  w ww. j  a  va 2  s . c om
            date = date.minusDays(7);
        }
        Collections.reverse(dates);
        return dates.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
    }
    ZonedDateTime date = startDate;
    while (!date.isAfter(endDate)) {
        dates.add(date);
        date = date.plusDays(7);
    }
    return dates.toArray(EMPTY_ZONED_DATE_TIME_ARRAY);
}

From source file:com.adaptris.core.management.ManagementComponentFactory.java

private static List<Object> reverseOrder(List<Object> list, boolean reverseOrder) {
    List<Object> newList = new ArrayList<>(list);
    if (reverseOrder) {
        Collections.reverse(newList);
    }//from w ww . j  a v a  2 s .c  o m
    return newList;
}