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:TimeUtil.java

public static String unfriendly(long amount, Unit unitOfAmount, boolean includeCentiseconds) {
    long nanos = Nanosecond.convertFrom(amount, unitOfAmount);
    List<Unit> units = Arrays.asList(Unit.values());
    Collections.reverse(units);
    StringBuilder sb = new StringBuilder();
    for (Unit unit : units) {
        if ((!includeCentiseconds) && unit.equals(Centisecond))
            continue;

        long unitAmount = unit.convertFrom(nanos, Nanosecond);
        nanos -= Nanosecond.convertFrom(unitAmount, unit);
        if (unitAmount > 0)
            sb.append(String.format("%s ", unit.toString(unitAmount)));
    }//  w  w w . j a  v a  2  s  .  c  om

    return sb.toString().trim();
}

From source file:org.dhara.portal.web.controllers.ExperimentController.java

public ArrayList<ExperimentHelper> reverseList(List<ExperimentHelper> list) {

    if (list == null || list.isEmpty()) {
        return null;
    }//  www. j  ava2s. c  o  m

    ArrayList<ExperimentHelper> reversedlist = new ArrayList<ExperimentHelper>(list);

    Collections.reverse(reversedlist);
    return reversedlist;
}

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

public List<Breadcrumb> getBreadcrumbs(final String categoryCode, final String searchText,
        final boolean emptyBreadcrumbs) throws IllegalArgumentException {
    final List<Breadcrumb> breadcrumbs = new ArrayList<>();

    if (categoryCode == null) {
        final Breadcrumb breadcrumb = new Breadcrumb("/search?text=" + getEncodedUrl(searchText),
                StringEscapeUtils.escapeHtml(searchText), (emptyBreadcrumbs ? LAST_LINK_CLASS : ""));
        breadcrumbs.add(breadcrumb);//from w  w  w  .  java2 s  .  co  m
    } else {
        // Create category hierarchy path for breadcrumb
        final List<Breadcrumb> categoryBreadcrumbs = new ArrayList<>();
        final Collection<CategoryModel> categoryModels = new ArrayList<>();
        final CategoryModel lastCategoryModel = getCommerceCategoryService().getCategoryForCode(categoryCode);
        categoryModels.addAll(lastCategoryModel.getSupercategories());
        categoryBreadcrumbs
                .add(getCategoryBreadcrumb(lastCategoryModel, (!emptyBreadcrumbs ? LAST_LINK_CLASS : "")));

        while (!categoryModels.isEmpty()) {
            final CategoryModel categoryModel = categoryModels.iterator().next();

            if (!(categoryModel instanceof ClassificationClassModel)) {
                if (categoryModel != null) {
                    categoryBreadcrumbs.add(getCategoryBreadcrumb(categoryModel));
                    categoryModels.clear();
                    categoryModels.addAll(categoryModel.getSupercategories());
                }
            } else {
                categoryModels.remove(categoryModel);
            }
        }
        Collections.reverse(categoryBreadcrumbs);
        breadcrumbs.addAll(categoryBreadcrumbs);
    }
    return breadcrumbs;
}

From source file:com.intellij.lang.jsgraphql.endpoint.doc.psi.JSGraphQLEndpointDocPsiUtil.java

/**
 * Gets the PSI comment that starts the documentation for the specified element, or <code>null</code> if no documentation is available
 *//*from   w  w  w  .j  a v a2  s.co  m*/
public static PsiComment getDocumentationStartElement(PsiElement element) {
    final PsiComment comment = PsiTreeUtil.getPrevSiblingOfType(element, PsiComment.class);
    if (isDocumentationComment(comment)) {
        final List<PsiComment> siblings = Lists.newArrayList(comment);
        getDocumentationCommentSiblings(comment, siblings, PsiElement::getPrevSibling);
        Collections.reverse(siblings);
        return siblings.get(0);
    }
    return null;
}

From source file:org.wikimedia.analytics.refinery.core.IpUtil.java

/**
 * Gets the client IP given the source IP and X-Forwarded-For header value
 * @param ip   the remote IP address of the requests
 * @param xff  Comma-separated list of ip addresses in X-Forwarded-For header
 * @return String Client IP address (trimmed, if required, but no
 * canonicalization) and {@code null} otherwise.
 *//*from  w w  w .  ja  v a2  s  . c om*/
public String getClientIp(final String ip, final String xff) {
    String ret = null;

    String sanitizedIp = sanitizeIp(ip);

    if (sanitizedIp != null) {
        // The original ip is good
        ret = sanitizedIp;

        if (isTrustedProxy(ret) && xff != null) {
            // ip was a proxy, and xff is not null.
            // Trying to detect user's ip by backtracking on xff.
            String[] xffIps = xff.split(",");

            // As proxies append (not prepend) ips to xff, we need to
            // traverse xff from right to left. We do so by reversing
            // xffIps and then iterating normally over it.
            Collections.reverse(Arrays.asList(xffIps));
            for (String xffIp : xffIps) {
                sanitizedIp = sanitizeIp(xffIp);
                if (sanitizedIp == null) {
                    // The current xffIp is not a proper IP. Hence bailing
                    // out and moving forward with last known good IP
                    // in ret.
                    break;
                }
                // The ip got sanitized, so we mark it as best possible
                // return value for now.
                ret = sanitizedIp;
                if (!isTrustedProxy(ret)) {
                    // ret is not a trusted proxy, so we have to stop
                    // iterating further to avoid using spoofed entries.
                    break;
                }
            }
        }
    }
    return ret;
}

From source file:com.pedra.storefront.breadcrumb.impl.SearchBreadcrumbBuilder.java

public List<Breadcrumb> getBreadcrumbs(final String categoryCode, final String searchText,
        final boolean emptyBreadcrumbs) throws IllegalArgumentException {
    final List<Breadcrumb> breadcrumbs = new ArrayList<Breadcrumb>();

    if (categoryCode == null) {
        final Breadcrumb breadcrumb = new Breadcrumb("/search?text=" + getEncodedUrl(searchText),
                StringEscapeUtils.escapeHtml(searchText), (emptyBreadcrumbs ? LAST_LINK_CLASS : ""));
        breadcrumbs.add(breadcrumb);/*from   www.  ja va2  s  .  co m*/
    } else {
        // Create category hierarchy path for breadcrumb
        final List<Breadcrumb> categoryBreadcrumbs = new ArrayList<Breadcrumb>();
        final Collection<CategoryModel> categoryModels = new ArrayList<CategoryModel>();
        final CategoryModel lastCategoryModel = getCommerceCategoryService().getCategoryForCode(categoryCode);
        categoryModels.addAll(lastCategoryModel.getSupercategories());
        categoryBreadcrumbs
                .add(getCategoryBreadcrumb(lastCategoryModel, (!emptyBreadcrumbs ? LAST_LINK_CLASS : "")));

        while (!categoryModels.isEmpty()) {
            final CategoryModel categoryModel = categoryModels.iterator().next();

            if (!(categoryModel instanceof ClassificationClassModel)) {
                if (categoryModel != null) {
                    categoryBreadcrumbs.add(getCategoryBreadcrumb(categoryModel));
                    categoryModels.clear();
                    categoryModels.addAll(categoryModel.getSupercategories());
                }
            } else {
                categoryModels.remove(categoryModel);
            }
        }
        Collections.reverse(categoryBreadcrumbs);
        breadcrumbs.addAll(categoryBreadcrumbs);
    }
    return breadcrumbs;
}

From source file:de.knowwe.rdf2go.utils.ResultTableModel.java

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

From source file:it.unibas.spicy.persistence.xml.operators.TransformFilePaths.java

private String mergePathLists(List<String> basePathSteps, List<String> filePathSteps) {
    Collections.reverse(basePathSteps);
    Collections.reverse(filePathSteps);
    List<String> result = new ArrayList<String>(basePathSteps);
    int i = 0;/*  w w  w .  ja  va2  s . c  o  m*/
    while (i < filePathSteps.size() && filePathSteps.get(i).equals("..")) {
        result.remove(result.size() - 1);
        i++;
    }
    for (int j = i; j < filePathSteps.size(); j++) {
        result.add(filePathSteps.get(j));
    }
    StringBuilder resultPath = new StringBuilder();
    for (int k = 0; k < result.size(); k++) {
        resultPath.append(result.get(k));
        if (k != result.size() - 1) {
            resultPath.append(File.separator);
        }
    }
    String resultString = resultPath.toString();
    if (!resultString.startsWith("/")) {
        resultString = "/" + resultString;
    }
    return resultString;
}

From source file:edu.umn.msi.tropix.storage.core.monitor.StorageMonitorClosureImpl.java

private void registerFile(final File newFile) {
    final String newId = UUID.randomUUID().toString(); // It is perhaps inappropriate to pick id here

    final File rootDirectory = findMatchingDirectory(newFile);
    if (newFile.equals(rootDirectory)) {
        return;//from   w  w  w. java2s. c  o m
    }

    final List<String> extractPathList = Lists.newArrayList();
    File parent = newFile.getParentFile();
    while (!rootDirectory.equals(parent)) {
        extractPathList.add(parent.getName());
        parent = parent.getParentFile();
    }
    Collections.reverse(extractPathList);

    final String rootFolderName = monitorConfig.getSharedFolderName(rootDirectory);
    final VirtualFolder rootSharedFolder = folderService.getOrCreateRootVirtualFolderWithName(getIdentity(),
            rootFolderName);
    final VirtualFolder child = folderService.getOrCreateVirtualPath(getIdentity(), rootSharedFolder.getId(),
            Iterables.toArray(extractPathList, String.class));

    final TropixFile tropixFile = new TropixFile();
    tropixFile.setFileId(newId);
    tropixFile.setCommitted(true);
    tropixFile.setName(newFile.getName());
    // TODO: FIX THIS
    // tropixFile.setFileSize(newFile.length());

    tropixFile.setStorageServiceUrl(storageServiceUrl);

    persistentFileMapperService.registerMapping(newId, FilenameUtils.normalize(newFile.getAbsolutePath()));
    final TropixFile returnedFile = tropixObjectService.createFile(getIdentity(), child.getId(), tropixFile,
            null);
    fileService.recordLength(newId, newFile.length());
    tropixObjectService.addToSharedFolder(getIdentity(), returnedFile.getId(), child.getId(), false);
}

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

public List<Breadcrumb> getBreadcrumbs(final String categoryCode, final String searchText,
        final boolean emptyBreadcrumbs) throws IllegalArgumentException {
    final List<Breadcrumb> breadcrumbs = new ArrayList<Breadcrumb>();

    if (categoryCode == null) {
        final Breadcrumb breadcrumb = new Breadcrumb("/search?text=" + getEncodedUrl(searchText),
                StringEscapeUtils.escapeHtml(searchText), (emptyBreadcrumbs ? LAST_LINK_CLASS : ""));
        breadcrumbs.add(breadcrumb);//from   www . j  av a  2 s  .co m
    } else {
        // Create category hierarchy path for breadcrumb
        final List<Breadcrumb> categoryBreadcrumbs = new ArrayList<Breadcrumb>();
        final Collection<CategoryModel> categoryModels = new ArrayList<CategoryModel>();
        final CategoryModel lastCategoryModel = getCommerceCategoryService().getCategoryForCode(categoryCode);
        categoryModels.addAll(lastCategoryModel.getSupercategories());
        categoryBreadcrumbs
                .add(getCategoryBreadcrumb(lastCategoryModel, (!emptyBreadcrumbs ? LAST_LINK_CLASS : "")));

        while (!categoryModels.isEmpty()) {
            final CategoryModel categoryModel = categoryModels.iterator().next();
            if (!(categoryModel instanceof ClassificationClassModel)) {
                if (categoryModel != null) {
                    categoryBreadcrumbs.add(getCategoryBreadcrumb(categoryModel));
                    categoryModels.clear();
                    categoryModels.addAll(categoryModel.getSupercategories());
                }
            } else {
                categoryModels.remove(categoryModel);
            }
        }
        Collections.reverse(categoryBreadcrumbs);
        breadcrumbs.addAll(categoryBreadcrumbs);
    }

    return breadcrumbs;
}