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.epam.cme.facades.converters.populator.AbstractProductBundleTabsPopulator.java

@Override
public void populate(final SOURCEPRODUCT productModel, final TARGETPRODUCT productData)
        throws ConversionException {
    // iterate over all components, which represent the package tabs in the frontend
    final Map<String, BundleTabData> bundleTabsMap = new HashMap<String, BundleTabData>();
    for (final SOURCETEMPLATE sourceComponent : getComponents(productModel)) {
        final SOURCETEMPLATE parentBundleTemplate = (SOURCETEMPLATE) sourceComponent.getParentTemplate();

        final SOURCETEMPLATE targetComponent = getTargetComponent(sourceComponent);

        final BundleTabData bundleTabData;
        if (bundleTabsMap.containsKey(parentBundleTemplate.getId())) {
            bundleTabData = bundleTabsMap.get(parentBundleTemplate.getId());
        } else {//from   w  w w .  j a va 2s  .c  o m
            bundleTabData = new BundleTabData();
            bundleTabsMap.put(parentBundleTemplate.getId(), bundleTabData);
        }

        bundleTabData.setParentBundleTemplate(getBundleTemplateConverter().convert(parentBundleTemplate));
        bundleTabData.setSourceComponent(getBundleTemplateConverter().convert(sourceComponent));
        bundleTabData.setTargetComponent(getBundleTemplateConverter().convert(targetComponent));

        final Map<String, FrequencyTabData> frequencyTabsMap = new HashMap<String, FrequencyTabData>();
        final List<FrequencyTabData> frequencyTabList = bundleTabData.getFrequencyTabs();
        if (CollectionUtils.isNotEmpty(frequencyTabList)) {
            for (final FrequencyTabData frequencyTabData : frequencyTabList) {
                frequencyTabsMap.put(frequencyTabData.getTermOfServiceFrequency().getCode() + ":"
                        + frequencyTabData.getTermOfServiceNumber(), frequencyTabData);
            }
        }

        // iterate over all products per bundle tab
        for (final ProductModel targetProductModel : getProducts(productModel, sourceComponent,
                targetComponent)) {
            if (targetProductModel instanceof SubscriptionProductModel) {
                final SubscriptionProductModel subscriptionProductModel = (SubscriptionProductModel) targetProductModel;

                final TermOfServiceFrequencyData termOfServiceFrequency = getTermOfServiceFrequencyConverter()
                        .convert(subscriptionProductModel.getSubscriptionTerm().getTermOfServiceFrequency());

                final int termOfServiceNumber = subscriptionProductModel.getSubscriptionTerm()
                        .getTermOfServiceNumber() == null ? 0
                                : subscriptionProductModel.getSubscriptionTerm().getTermOfServiceNumber()
                                        .intValue();

                // The list of Plans is split by its terms and conditions number and frequency,
                // which lead to the frequency tabs in the frontend
                FrequencyTabData frequencyTab;
                final String frequencyString = termOfServiceFrequency.getCode() + ":" + termOfServiceNumber;

                if (frequencyTabsMap.containsKey(frequencyString)) {
                    frequencyTab = frequencyTabsMap.get(frequencyString);
                } else {
                    frequencyTab = buildFrequencyTab(termOfServiceFrequency, termOfServiceNumber);
                    frequencyTabsMap.put(frequencyString, frequencyTab);
                }

                // the related product is populated with specific information
                final ProductData subscriptionProductData = getProductConverter()
                        .convert(subscriptionProductModel);

                getSubscriptionProductBasicPopulator().populate(subscriptionProductModel,
                        subscriptionProductData);
                getSubscriptionProductEntitlementPopulator().populate(subscriptionProductModel,
                        subscriptionProductData);

                callPopulators(sourceComponent, targetComponent, productModel, productData,
                        subscriptionProductModel, subscriptionProductData);

                frequencyTab.getProducts().add(subscriptionProductData);
            } else {
                LOG.error("Product '" + targetProductModel.getCode()
                        + "' is not a SubscriptionProduct. Ignoring it.");
            }
        }

        final List<FrequencyTabData> sortedFrequencies = new ArrayList<FrequencyTabData>(
                frequencyTabsMap.values());
        Collections.sort(sortedFrequencies, new FrequencyTabDataComparator());
        Collections.reverse(sortedFrequencies);
        bundleTabData.setFrequencyTabs(sortedFrequencies);

    }
    final List<BundleTabData> bundleTabs = new ArrayList<BundleTabData>(bundleTabsMap.values());

    if (productModel instanceof DeviceModel) {
        productData.setSoldIndividually(BooleanUtils.toBoolean(productModel.getSoldIndividually()));
        productData.setBundleTabs(bundleTabs);
    } else if (productModel instanceof SubscriptionProductModel) {
        productData.setBundleTabs(bundleTabs);
    }

    // populate the information about pre-selected tabs
    changePreselectedFlags(bundleTabs, productModel.getCode());
}

From source file:net.sourceforge.ganttproject.client.RssFeedChecker.java

private Runnable createRssReadCommand() {
    return new Runnable() {
        @Override/*from   w  w w .  java2s . com*/
        public void run() {
            GPLogger.log("Starting RSS check...");
            HttpClient httpClient = new DefaultHttpClient();
            String url = RSS_URL;
            try {
                for (int i = 0; i < MAX_ATTEMPTS; i++) {
                    HttpGet getRssUrl = new HttpGet(url);
                    getRssUrl.addHeader("User-Agent", "GanttProject " + GPVersion.CURRENT);
                    HttpResponse result = httpClient.execute(getRssUrl);

                    switch (result.getStatusLine().getStatusCode()) {
                    case HttpStatus.SC_OK:
                        processResponse(result.getEntity().getContent());
                        return;
                    }
                }
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                httpClient.getConnectionManager().shutdown();
                GPLogger.log("RSS check finished");
            }
        }

        private void processResponse(InputStream responseStream) {
            RssFeed feed = parser.parse(responseStream, myLastCheckOption.getValue());
            List<NotificationItem> items = new ArrayList<NotificationItem>();
            for (RssFeed.Item item : feed.getItems()) {
                items.add(new NotificationItem(item.title, item.body,
                        NotificationManager.DEFAULT_HYPERLINK_LISTENER));
            }
            Collections.reverse(items);
            if (!items.isEmpty()) {
                getNotificationManager().addNotifications(NotificationChannel.RSS, items);
            }
            markLastCheck();
        }
    };
}

From source file:com.taobao.itest.listener.TransactionalListener.java

/**
 * Run all {@link BeforeTransaction @BeforeTransaction methods} for the
 * specified {@link TestContext test context}. If one of the methods fails,
 * however, the caught exception will be rethrown in a wrapped
 * {@link RuntimeException}, and the remaining methods will
 * <strong>not</strong> be given a chance to execute.
 * /*from  ww  w .j a v  a  2 s  . c  o  m*/
 * @param testContext
 *            the current test context
 */
protected void runBeforeTransactionMethods(TestContext testContext) throws Exception {
    try {
        List<Method> methods = getAnnotatedMethods(testContext.getTestClass(), BeforeTransaction.class);
        Collections.reverse(methods);
        for (Method method : methods) {
            if (logger.isDebugEnabled()) {
                logger.debug("Executing @BeforeTransaction method [" + method + "] for test context ["
                        + testContext + "]");
            }
            method.invoke(testContext.getTestInstance());
        }
    } catch (InvocationTargetException ex) {
        logger.error("Exception encountered while executing @BeforeTransaction methods for test context ["
                + testContext + "]", ex.getTargetException());
        rethrowException(ex.getTargetException());
    }
}

From source file:de.hybris.platform.ytelcoacceleratorfacades.converters.populator.AbstractProductBundleTabsPopulator.java

@Override
public void populate(final SOURCEPRODUCT productModel, final TARGETPRODUCT productData)
        throws ConversionException {
    // iterate over all components, which represent the package tabs in the frontend
    final Map<String, BundleTabData> bundleTabsMap = new HashMap<String, BundleTabData>();
    for (final SOURCETEMPLATE sourceComponent : getComponents(productModel)) {
        final SOURCETEMPLATE parentBundleTemplate = (SOURCETEMPLATE) sourceComponent.getParentTemplate();

        final SOURCETEMPLATE targetComponent = getTargetComponent(sourceComponent);

        final BundleTabData bundleTabData;
        if (bundleTabsMap.containsKey(parentBundleTemplate.getId())) {
            bundleTabData = bundleTabsMap.get(parentBundleTemplate.getId());
        } else {//from  ww w  .  ja va2s  .co  m
            bundleTabData = new BundleTabData();
            bundleTabsMap.put(parentBundleTemplate.getId(), bundleTabData);
        }

        bundleTabData.setParentBundleTemplate(getBundleTemplateConverter().convert(parentBundleTemplate));
        bundleTabData.setSourceComponent(getBundleTemplateConverter().convert(sourceComponent));
        bundleTabData.setTargetComponent(getBundleTemplateConverter().convert(targetComponent));

        final Map<String, FrequencyTabData> frequencyTabsMap = new HashMap<String, FrequencyTabData>();
        final List<FrequencyTabData> frequencyTabList = bundleTabData.getFrequencyTabs();
        if (CollectionUtils.isNotEmpty(frequencyTabList)) {
            for (final FrequencyTabData frequencyTabData : frequencyTabList) {
                frequencyTabsMap.put(frequencyTabData.getTermOfServiceFrequency().getCode() + ":"
                        + frequencyTabData.getTermOfServiceNumber(), frequencyTabData);
            }
        }

        // iterate over all products per bundle tab
        for (final ProductModel targetProductModel : getProducts(productModel, sourceComponent,
                targetComponent)) {
            if (targetProductModel instanceof SubscriptionProductModel) {
                final SubscriptionProductModel subscriptionProductModel = (SubscriptionProductModel) targetProductModel;

                final TermOfServiceFrequencyData termOfServiceFrequency = getTermOfServiceFrequencyConverter()
                        .convert(subscriptionProductModel.getSubscriptionTerm().getTermOfServiceFrequency());

                final int termOfServiceNumber = subscriptionProductModel.getSubscriptionTerm()
                        .getTermOfServiceNumber() == null ? 0
                                : subscriptionProductModel.getSubscriptionTerm().getTermOfServiceNumber()
                                        .intValue();

                // The list of Plans is split by its terms and conditions number and frequency, which lead to the frequency tabs in the frontend
                FrequencyTabData frequencyTab;
                final String frequencyString = termOfServiceFrequency.getCode() + ":" + termOfServiceNumber;

                if (frequencyTabsMap.containsKey(frequencyString)) {
                    frequencyTab = frequencyTabsMap.get(frequencyString);
                } else {
                    frequencyTab = buildFrequencyTab(termOfServiceFrequency, termOfServiceNumber);
                    frequencyTabsMap.put(frequencyString, frequencyTab);
                }

                // the related product is populated with specific information
                final ProductData subscriptionProductData = getProductConverter()
                        .convert(subscriptionProductModel);

                getSubscriptionProductBasicPopulator().populate(subscriptionProductModel,
                        subscriptionProductData);
                getSubscriptionProductEntitlementPopulator().populate(subscriptionProductModel,
                        subscriptionProductData);

                callPopulators(sourceComponent, targetComponent, productModel, productData,
                        subscriptionProductModel, subscriptionProductData);

                frequencyTab.getProducts().add(subscriptionProductData);
            } else {
                LOG.error("Product '" + targetProductModel.getCode()
                        + "' is not a SubscriptionProduct. Ignoring it.");
            }
        }

        final List<FrequencyTabData> sortedFrequencies = new ArrayList<FrequencyTabData>(
                frequencyTabsMap.values());
        Collections.sort(sortedFrequencies, new FrequencyTabDataComparator());
        Collections.reverse(sortedFrequencies);
        bundleTabData.setFrequencyTabs(sortedFrequencies);

    }
    final List<BundleTabData> bundleTabs = new ArrayList<BundleTabData>(bundleTabsMap.values());

    if (productModel instanceof DeviceModel) {
        productData.setSoldIndividually(BooleanUtils.toBoolean(productModel.getSoldIndividually()));
        productData.setBundleTabs(bundleTabs);
    } else if (productModel instanceof SubscriptionProductModel) {
        productData.setBundleTabs(bundleTabs);
    }

    // populate the information about pre-selected tabs
    changePreselectedFlags(bundleTabs, productModel.getCode());
}

From source file:com.stratelia.webactiv.yellowpages.control.YellowpagesSessionController.java

public TopicDetail getTopic(String id) {
    TopicDetail topic = getKSCEJB().goTo(getNodePK(id), getUserId());
    List<NodeDetail> thePath = (List<NodeDetail>) getNodeBm().getAnotherPath(getNodePK(id));
    Collections.reverse(thePath);
    topic.setPath(thePath);//from   www.  j  av  a2  s. c  o m
    return topic;
}

From source file:userInterface.cdcRole.DecisionChartJPanel.java

private PieDataset createDataset() {
    System.out.println("2");
    ArrayList<stateQty> temp = new ArrayList<>();
    //temp = supplier.getProductCatalog().getProductCatalog();
    //temp = supplier.getProductCatalog().getProductCatalog();
    stateQty sq = null;//from w w  w .j ava  2s .com
    Boolean flag = true;

    for (Network n1 : n.getStateList()) {
        for (Enterprise e1 : n1.getEnterpriseDirectory().getEnterpriseList()) {
            if (e1 instanceof PhdEnterprise) {
                int total = 0;
                for (Organization o3 : e1.getOrganizationDirectory().getOrganizationList()) {
                    if (o3 instanceof HospitalOrganization) {
                        HospitalOrganization ho1 = (HospitalOrganization) o3;
                        total += ho1.getTotalVaccine();
                    }
                }
                for (Organization o4 : e1.getOrganizationDirectory().getOrganizationList()) {
                    if (o4 instanceof HospitalOrganization) {
                        for (Organization o5 : o4.getOrganizationDirectory().getOrganizationList()) {
                            if (o5 instanceof ClinicOrganization) {
                                ClinicOrganization co1 = (ClinicOrganization) o5;
                                total += co1.getTotalVaccine();
                            }
                        }
                    }
                }
                sq = new stateQty();
                sq.setE(e1);
                sq.setQ(total);
                temp.add(sq);
            }
        }
    }

    Collections.sort(temp, new Comparator<stateQty>() {
        public int compare(stateQty one, stateQty other) {
            if (one.getQ() < other.getQ()) {
                return -1;
            }
            if (one.getQ() > other.getQ()) {
                return 1;
            }

            return 0;
        }
    });
    Collections.reverse(temp);
    System.out.println(temp.size());
    DefaultPieDataset defaultpiedataset = new DefaultPieDataset();
    //defaultpiedataset.setValue("Java", 10);
    int i = 1;
    for (stateQty p : temp) {
        if (i == 6) {
            break;
        } else {
            defaultpiedataset.setValue(p.getE().getName() + "(" + p.getQ() + ")", p.getQ());
            i++;
        }
    }

    return defaultpiedataset;
}

From source file:eu.markov.jenkins.plugin.mvnmeta.MavenMetadataParameterDefinition.java

private MavenMetadataVersions getArtifactMetadata() {
    InputStream input = null;//from  ww  w  .  j av  a 2  s  .  co m
    try {
        URL url = new URL(getArtifactUrlForPath("maven-metadata.xml"));

        LOGGER.finest("Requesting metadata from URL: " + url.toExternalForm());

        URLConnection conn = url.openConnection();

        if (StringUtils.isNotBlank(url.getUserInfo())) {
            LOGGER.finest("Using implicit UserInfo");
            String encodedAuth = new String(Base64.encodeBase64(url.getUserInfo().getBytes(UTF8)), UTF8);
            conn.addRequestProperty("Authorization", "Basic " + encodedAuth);
        }

        if (StringUtils.isNotBlank(this.username) && StringUtils.isNotBlank(this.password)) {
            LOGGER.finest("Using explicit UserInfo");
            String userpassword = username + ":" + password;
            String encodedAuthorization = new String(Base64.encodeBase64(userpassword.getBytes(UTF8)), UTF8);
            conn.addRequestProperty("Authorization", "Basic " + encodedAuthorization);
        }

        input = conn.getInputStream();
        JAXBContext context = JAXBContext.newInstance(MavenMetadataVersions.class);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        MavenMetadataVersions metadata = (MavenMetadataVersions) unmarshaller.unmarshal(input);

        if (sortOrder == SortOrder.DESC) {
            Collections.reverse(metadata.versioning.versions);
        }
        metadata.versioning.versions = filterVersions(metadata.versioning.versions);

        return metadata;
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "Could not parse maven-metadata.xml", e);
        MavenMetadataVersions result = new MavenMetadataVersions();
        result.versioning.versions.add("<" + e.getClass().getName() + ": " + e.getMessage() + ">");
        return result;
    } finally {
        try {
            if (input != null)
                input.close();
        } catch (IOException e) {
            // ignore
        }
    }
}

From source file:com.silverpeas.silvercrawler.control.SilverCrawlerSessionController.java

public void setCurrentPathFromResult(String path) {
    File pathFile = FileUtils.getFile(path);
    if (pathFile.getPath().startsWith(rootPath.getPath())) {
        pathFile = FileUtils.getFile(pathFile.getPath().substring(rootPath.getPath().length()));
    }//from www .  j  a  va  2 s. co  m
    currentPath = FileUtils.getFile(rootPath, pathFile.getPath());
    // mise  jour de la collection des chemins
    paths.clear();
    // dcomposer le chemin pour crer le path
    SilverTrace.debug("silverCrawler", "SilverCrawlerSessionController.getDestination()",
            "root.MSG_GEN_PARAM_VALUE", "separator = " + File.separator + " path = " + pathFile.getPath());

    while (pathFile != null && pathFile.getName().length() > 0) {
        paths.add(pathFile.getName());
        pathFile = pathFile.getParentFile();
    }
    Collections.reverse(paths);
}

From source file:ispyb.client.common.util.FileUtil.java

private static List<ImageValueInfo> getImageList(List<Image3VO> tmp_imageList, Integer extract_ImageId,
        Integer extract_ImageNumber, Integer nbImagesHorizontal, Integer nbImagesVertical,
        HttpServletRequest request) throws Exception {
    Collections.reverse(tmp_imageList);
    List<ImageValueInfo> imageList = new ArrayList<ImageValueInfo>(tmp_imageList.size());

    int imgNumberHorizontal = 0;
    int imgNumberVertical = 0;

    int nb = tmp_imageList.size();

    for (int i = 0; i < nb; i++) {

        Image3VO imgValue = tmp_imageList.get(i);
        // TODO check if fileExists
        // we add the image only if jpeg are present on disk
        if (isJpgForImage(imgValue, request)) {

            imgNumberHorizontal++;//from w ww .jav  a 2s .c  om

            ImageValueInfo imageValueInfo = new ImageValueInfo(imgValue);
            // --- Populate ImageValueInf0
            Integer currId = imgValue.getImageId();
            Integer prevId = (i > 0) ? (tmp_imageList.get(i - 1)).getImageId() : currId;
            Integer nextId = (i < (tmp_imageList.size() - 1)) ? (tmp_imageList.get(i + 1)).getImageId()
                    : currId;
            Integer imageNumber = new Integer(i + 1);
            boolean first = (i == 0) ? true : false;
            boolean last = (i == tmp_imageList.size() - 1) ? true : false;

            imageValueInfo.setCurrentImageId(currId);
            imageValueInfo.setPreviousImageId(prevId);
            imageValueInfo.setNextImageId(nextId);
            imageValueInfo.setImageNumberInfo(imageNumber);
            imageValueInfo.setFirst(first);
            imageValueInfo.setLast(last);
            imageValueInfo.setSynchrotronCurrent(imgValue.getSynchrotronCurrent());
            imageValueInfo.setFormattedData();
            imageValueInfo.setLastImageHorizontal(false);
            imageValueInfo.setLastImageVertical(false);

            // --- Tag last Horizontal and Vertical Image ---
            if (nbImagesHorizontal != null && imgNumberHorizontal == nbImagesHorizontal
                    && nbImagesHorizontal != 0) {
                imageValueInfo.setLastImageHorizontal(true);
                imgNumberHorizontal = 0;
                imgNumberVertical++;
            }

            if (nbImagesVertical != null && imgNumberVertical == nbImagesVertical && nbImagesVertical != 0) {
                imageValueInfo.setLastImageVertical(true);
                imgNumberVertical = 0;
            }

            imageList.add(imageValueInfo);
        }

    }
    // update the nextId value
    int nbImages = imageList.size();
    for (int i = 0; i < nbImages; i++) {
        Integer id = new Integer(i + 1);
        ImageValueInfo v = imageList.get(i);
        if (i < nbImages - 1) {
            v.setNextImageId(imageList.get(id).getCurrentImageId());
        }
        v.setImageNumberInfo(id);

    }
    // --- Extract specific Image by adding it at position 0
    if (extract_ImageId != null) {
        ImageValueInfo v = getImageValueInfo(extract_ImageId, imageList);
        if (v != null)
            imageList.add(0, v);
    } else {
        if (extract_ImageNumber != null) {
            ImageValueInfo v = getImageValueInfo(extract_ImageNumber, imageList);
            if (v != null)
                imageList.add(0, v);
        }
    }
    return imageList;
}

From source file:org.jasig.portlet.notice.service.jpa.JpaNotificationService.java

private Map<NotificationState, Date> prepareStates(JpaEntry entry, String username) {
    Map<NotificationState, Date> rslt = new HashMap<NotificationState, Date>();
    List<JpaEvent> events = notificationDao.getEvents(entry.getId(), username);
    Collections.reverse(events); // Process in reverse-chronological order
    for (JpaEvent e : events) {
        // NOTE:  We're obligated to filter out states
        // that are "canceled out" by subsequent events
        Set<NotificationState> subsequentHistory = rslt.keySet();
        if (e.getState().isActive(e.getTimestamp(), subsequentHistory)) {
            rslt.put(e.getState(), e.getTimestamp());
        }/*from   ww w  . jav a 2  s.c om*/
    }
    return rslt;
}