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:ldap.SearchUtility.java

/**
 * This sets the ordered types that//  www. j  av  a2 s  . com
 * give names to the semantic structure of the directory that is being searched
 * (e.g. define the structure as country, company, division, section etc.
 *
 * @param types definitions of the 'meaning' of each level of the directory tree - NOTE these
 *              are in LEAST SIGNIFICANT ORDER FIRST! (Opposite of normal directory numbering)
 *              e.g.:  types[0] = name;
 *              types[1] = section
 *              types[2] = division;
 *              types[3] = group;
 *              types[4] = area
 */
public void setStructure(List<String> types) {
    structureTypes = new ArrayList<String>(types);
    // set the order of structureTypes to match normal DN order (makes parsing LdapNames easier)
    Collections.reverse(structureTypes);
}

From source file:br.com.hslife.orcamento.service.ItemDespensaService.java

@Override
public void desfazerRegistroCompraConsumo(ItemDespensa entity) {
    if (entity.getMovimentacao() != null && entity.getMovimentacao().size() > 0) {
        Collections.reverse(entity.getMovimentacao());
    } else {//from   w  w w.  j a  v a  2  s  . co m
        throw new BusinessException("Impossvel desfazer! Item de despensa sem movimentao!");
    }
    MovimentoItemDespensa movimentoItemDespensa = entity.getMovimentacao().get(0);
    if (movimentoItemDespensa.getOperacaoDespensa().equals(OperacaoDespensa.COMPRA)
            && (entity.getQuantidadeAtual() - movimentoItemDespensa.getQuantidade()) < 0) {
        throw new BusinessException(
                "Impossvel desfazer! Quantidade informada ultrapassa estoque disponvel!");
    }
    entity.getMovimentacao().remove(movimentoItemDespensa);
    entity.setQuantidadeAtual(0);
    for (MovimentoItemDespensa mid : entity.getMovimentacao()) {
        if (mid.getOperacaoDespensa().equals(OperacaoDespensa.COMPRA)) {
            entity.setQuantidadeAtual(entity.getQuantidadeAtual() + mid.getQuantidade());
        } else {
            entity.setQuantidadeAtual(entity.getQuantidadeAtual() - mid.getQuantidade());
        }
    }
    getRepository().update(entity);
}

From source file:com.denkbares.semanticcore.utils.ResultTableModel.java

@NotNull
@Override/*from   www. jav  a  2s . c o m*/
public Iterator<TableRow> iterator() {
    if (comparators.isEmpty()) {
        return rows.iterator();
    } else {
        ArrayList<TableRow> tableRows = new ArrayList<>(rows);
        Collections.reverse(comparators);
        for (Comparator<TableRow> comparator : comparators) {
            tableRows.sort(comparator);
        }
        return tableRows.iterator();
    }
}

From source file:net.sourceforge.processdash.ui.web.psp.TimeLogPhaseWaterfallChart.java

private List<String> getPhaseList(ProcessUtil process) {
    List phases = process.getProcessListPlain("Phase_List");
    phases = process.filterPhaseList(phases);
    Collections.reverse(phases);
    return phases;
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.commons.tutorship.ViewStudentsByTutorDispatchAction.java

private List<StudentsByTutorBean> getTutorshipsByEntryYear(List<Tutorship> tutorships) {
    Map<ExecutionYear, StudentsByTutorBean> tutorshipsMapByEntryYear = new HashMap<ExecutionYear, StudentsByTutorBean>();

    for (final Tutorship tutorship : tutorships) {
        ExecutionYear entryYear = ExecutionYear
                .getExecutionYearByDate(tutorship.getStudentCurricularPlan().getRegistration().getStartDate());
        if (!tutorship.getStudentCurricularPlan().getRegistration().isCanceled()) {
            if (tutorshipsMapByEntryYear.containsKey(entryYear)) {
                StudentsByTutorBean studentsByTutorBean = tutorshipsMapByEntryYear.get(entryYear);
                studentsByTutorBean.getStudentsList().add(new TutorshipBean(tutorship));
                Collections.sort(studentsByTutorBean.getStudentsList(),
                        TutorshipBean.TUTORSHIP_COMPARATOR_BY_STUDENT_NUMBER);
            } else {
                List<Tutorship> studentsByEntryYearList = new ArrayList<Tutorship>();
                studentsByEntryYearList.add(tutorship);
                StudentsByTutorBean studentsByTutorBean = new StudentsByTutorBean(tutorship.getTeacher(),
                        entryYear, studentsByEntryYearList);
                tutorshipsMapByEntryYear.put(entryYear, studentsByTutorBean);
            }/*from   ww w. j a  v a  2 s  . com*/
        }
    }

    List<StudentsByTutorBean> tutorshipsByEntryYear = new ArrayList<StudentsByTutorBean>(
            tutorshipsMapByEntryYear.values());
    Collections.sort(tutorshipsByEntryYear, new BeanComparator("studentsEntryYear"));
    Collections.reverse(tutorshipsByEntryYear);

    return tutorshipsByEntryYear;
}

From source file:com.salesmanager.central.merchantstore.StoreFrontPortletsAction.java

public String display() {

    try {//from   w ww  .  j  a va2 s . co  m

        super.setPageTitle("label.storefront.portletsconfig");

        // get portlets
        ReferenceService rservice = (ReferenceService) ServiceFactory
                .getService(ServiceFactory.ReferenceService);
        portlets = rservice.getCoreModules(CatalogConstants.STORE_FRONT_PORTLETS_CODE, "XX");
        Collections.reverse((List) portlets);

        // get selection
        ConfigurationRequest request = new ConfigurationRequest(super.getContext().getMerchantid(), true,
                ConfigurationConstants.STORE_PORTLETS_);
        MerchantService mservice = (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService);
        ConfigurationResponse vo = mservice.getConfiguration(request);

        if (vo != null) {
            List configurations = vo.getMerchantConfigurationList();

            if (configurations != null && configurations.size() > 0) {

                Iterator i = configurations.iterator();

                while (i.hasNext()) {

                    MerchantConfiguration conf = (MerchantConfiguration) i.next();

                    if (conf.getConfigurationKey().equals(ConfigurationConstants.STORE_PORTLETS_)) {
                        mc = conf;
                        Collection portletsList = MerchantConfigurationUtil
                                .getConfigurationList(mc.getConfigurationValue(), ";");
                        if (portletsList != null && portletsList.size() > 0) {
                            Map returnMap = new HashMap();
                            Iterator ii = portletsList.iterator();
                            while (ii.hasNext()) {
                                String p = (String) ii.next();
                                returnMap.put(p, p);
                            }
                            selectedPortlets = returnMap;
                        }
                        continue;
                    }

                    if (conf.getConfigurationModule() != null) {
                        this.configuredPortlets.put(conf.getConfigurationModule(),
                                conf.getConfigurationModule());
                    }
                }

            }
        }

        // get custom portlets
        customPortlets = rservice.getDynamicLabels(super.getContext().getMerchantid(),
                LabelConstants.STORE_FRONT_CUSTOM_PORTLETS, super.getLocale());

    } catch (Exception e) {
        log.error(e);
        super.setTechnicalMessage();
    }

    return SUCCESS;

}

From source file:com.github.fauu.natrank.service.MatchServiceImpl.java

@Override
public List<Integer> getTeamFormByName(String name) throws DataAccessException {
    Team team = teamRepository.findByName(name);
    Page<Match> matchPage = matchRepository.findByTeam1OrTeam2(team, team,
            new PageRequest(0, 5, Sort.Direction.DESC, "id"));

    List<Integer> form = new LinkedList<>();

    for (Match match : matchPage.getContent()) {
        int formEntryValue = 0;

        if (match.getWinnerTeam() == null) {
            formEntryValue = 0;/* w  w w .  j  ava  2  s.  c  o  m*/
        } else if (match.getWinnerTeam() == team) {
            formEntryValue = 1;
        } else if (match.getWinnerTeam() != team) {
            formEntryValue = -1;
        }

        form.add(formEntryValue);
    }

    Collections.reverse(form);

    return form;
}

From source file:io.fabric8.maven.core.util.kubernetes.KubernetesClientUtil.java

public static void deleteEntities(KubernetesClient kubernetes, String namespace, Set<HasMetadata> entities,
        String s2iBuildNameSuffix, Logger log) {
    List<HasMetadata> list = new ArrayList<>(entities);

    // For OpenShift cluster, also delete s2i buildconfig
    OpenShiftClient openshiftClient = OpenshiftHelper.asOpenShiftClient(kubernetes);
    if (openshiftClient != null) {
        for (HasMetadata entity : list) {
            if ("ImageStream".equals(KubernetesHelper.getKind(entity))) {
                ImageName imageName = new ImageName(entity.getMetadata().getName());
                String buildName = getS2IBuildName(imageName, s2iBuildNameSuffix);
                log.info("Deleting resource BuildConfig " + namespace + "/" + buildName);
                openshiftClient.buildConfigs().inNamespace(namespace).withName(buildName).delete();
            }//from www  .j a  v  a  2  s.com
        }
    }

    // lets delete in reverse order
    Collections.reverse(list);

    for (HasMetadata entity : list) {
        log.info("Deleting resource " + KubernetesHelper.getKind(entity) + " " + namespace + "/"
                + KubernetesHelper.getName(entity));
        kubernetes.resource(entity).inNamespace(namespace).cascading(true).delete();
    }
}

From source file:es.uniovi.imovil.fcrtrainer.highscores.HighscoreManager.java

private static ArrayList<Highscore> trim(ArrayList<Highscore> highscores, int maxNumberHighscores) {
    ArrayList<Highscore> trimmedHighscores = new ArrayList<Highscore>();
    SparseIntArray highscoresPerExercise = new SparseIntArray();

    Collections.sort(highscores);
    Collections.reverse(highscores);

    for (int i = 0; i < highscores.size(); i++) {
        int exercise = highscores.get(i).getExercise();
        if (highscoresPerExercise.get(exercise) != 0) {
            int numHighscores = highscoresPerExercise.get(exercise);
            if (numHighscores < maxNumberHighscores) {
                highscoresPerExercise.put(exercise, numHighscores + 1);
                trimmedHighscores.add(highscores.get(i));
            }//from  www  .ja  v a 2 s.c  o m
        } else {
            highscoresPerExercise.put(exercise, 1);
            trimmedHighscores.add(highscores.get(i));
        }
    }

    return trimmedHighscores;
}

From source file:com.netflix.spinnaker.orca.pipeline.util.ArtifactResolver.java

public @Nonnull List<Artifact> getAllArtifacts(@Nonnull Execution execution) {
    // Get all artifacts emitted by the execution's stages; we'll sort the stages topologically,
    // then reverse the result so that artifacts from later stages will appear
    // earlier in the results.
    List<Artifact> emittedArtifacts = Stage.topologicalSort(execution.getStages())
            .filter(s -> s.getOutputs().containsKey("artifacts"))
            .flatMap(s -> (Stream<Artifact>) ((List) s.getOutputs().get("artifacts")).stream()
                    .map(a -> a instanceof Map ? objectMapper.convertValue(a, Artifact.class) : a))
            .collect(Collectors.toList());
    Collections.reverse(emittedArtifacts);

    // Get all artifacts in the parent pipeline's trigger; these artifacts go at the end of the list,
    // after any that were emitted by the pipeline
    List<Artifact> triggerArtifacts = objectMapper.convertValue(execution.getTrigger().getArtifacts(),
            new TypeReference<List<Artifact>>() {
            });/*from w  ww  .j  a v  a  2 s.  co  m*/

    emittedArtifacts.addAll(triggerArtifacts);

    return emittedArtifacts;
}