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.avatarproject.core.command.CommandHelp.java

@Override
public void execute(CommandSender sender, List<String> args) {
    if (!isPlayer(sender) || !hasPermission(sender) || !correctLength(sender, args.size(), 0, 1)) {
        return;/*from   ww w  .ja  v  a  2s .co m*/
    }

    Player player = (Player) sender;
    List<String> order = new ArrayList<String>();
    HashMap<String, TextComponent> components = new HashMap<String, TextComponent>();
    for (APCommand command : instances.values()) {
        if (hasPermissionHelp(sender, command.getName())) {
            TextComponent tc = new TextComponent(ChatColor.GRAY + command.getProperUse());
            String tooltip = WordUtils.wrap(ChatColor.GRAY + command.getDescription(), 40,
                    "\n" + ChatColor.GRAY, false);
            tc.setHoverEvent(
                    new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(tooltip).create()));
            tc.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command.getProperUse()));
            order.add(command.getName());
            components.put(command.getName(), tc);
        }
    }
    order.remove(APCommand.instances.get("help").getName());
    Collections.sort(order);
    Collections.reverse(order);
    order.add(APCommand.instances.get("help").getName());
    Collections.reverse(order);

    List<TextComponent> neworder = new ArrayList<TextComponent>();
    for (String s : order) {
        neworder.add(components.get(s));
    }

    if (args.size() == 0 || isNumeric(args.get(0))) {
        int page = 0;
        if (args.size() > 0 && isNumeric(args.get(0))) {
            page = Integer.valueOf(args.get(0)) - 1;
        }
        for (TextComponent tc : getPage(Strings.COMMAND_HELP_TITLE.toString(), page, neworder)) {
            player.spigot().sendMessage(tc);
        }
        return;
    }

    String arg = args.get(0);
    if (instances.keySet().contains(arg.toLowerCase())) {
        instances.get(arg).help(sender, true);
    } else {
        sender.sendMessage("Invalid command!");
    }
}

From source file:com.salesmanager.core.util.CategoryUtil.java

/**
 * returns a tree path for a given category from the lowest level
 * //from   w ww .  j a  va2  s. c  o  m
 * @param req
 * @param categoriesid
 * @return
 */
public static List getCategoryPath(String lang, int merchantId, long categoryid) {

    List returnlist = new ArrayList();

    try {

        CatalogService service = (CatalogService) ServiceFactory.getService(ServiceFactory.CatalogService);

        Map cat = service.getCategoriesByLang(merchantId, lang);

        if (cat == null || categoryid == 0) {
            return returnlist;
        }

        boolean atroot = false;
        long curcateg = categoryid;
        // while root category not reached
        while (!atroot) {
            Category categ = (Category) cat.get(curcateg);
            long parentcategid = categ.getParentId();
            returnlist.add(categ);
            curcateg = parentcategid;
            if (parentcategid == 0)
                atroot = true;
        }

        Collections.reverse(returnlist);

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

    return returnlist;

}

From source file:com.chintans.venturebox.server.VentureServer.java

@Override
public List<PackageInfo> createPackageInfoList(JSONObject response) throws Exception {
    mError = null;/*from  w w w  . j  av  a2s .  com*/
    List<PackageInfo> list = new ArrayList<PackageInfo>();
    mError = response.optString("error");
    if (mError == null || mError.isEmpty()) {
        JSONArray updates = response.getJSONArray("updates");
        for (int i = updates.length() - 1; i >= 0; i--) {
            JSONObject file = updates.getJSONObject(i);
            String filename = file.optString("name");
            String stripped = filename.replace(".zip", "");
            String[] parts = stripped.split("-");
            boolean isNew = parts[parts.length - 1].matches("[-+]?\\d*\\.?\\d+");
            if (!isNew) {
                continue;
            }
            Version version = new Version(filename);
            if (Version.compare(mVersion, version) < 0) {
                list.add(new UpdatePackage(mDevice, filename, version, file.getString("size"),
                        file.getString("url"), file.getString("md5"), false));
            }
        }
    }
    Collections.sort(list, new Comparator<PackageInfo>() {

        @Override
        public int compare(Updater.PackageInfo lhs, Updater.PackageInfo rhs) {
            return Version.compare(lhs.getVersion(), rhs.getVersion());
        }

    });
    Collections.reverse(list);
    return list;
}

From source file:com.epam.cme.storefront.breadcrumb.impl.ProductBreadcrumbBuilder.java

public List<Breadcrumb> getBreadcrumbs(final ProductModel productModel) throws IllegalArgumentException {
    final List<Breadcrumb> breadcrumbs = new ArrayList<Breadcrumb>();

    final Collection<CategoryModel> categoryModels = new ArrayList<CategoryModel>();
    final Breadcrumb last;

    final ProductModel baseProductModel = getBaseProduct(productModel);
    last = getProductBreadcrumb(baseProductModel);
    categoryModels.addAll(baseProductModel.getSupercategories());
    last.setLinkClass(LAST_LINK_CLASS);/* w  w  w .  j  a v  a 2 s  . c o m*/

    breadcrumbs.add(last);

    while (!categoryModels.isEmpty()) {
        CategoryModel toDisplay = null;
        for (final CategoryModel categoryModel : categoryModels) {
            if (!(categoryModel instanceof ClassificationClassModel)) {
                if (toDisplay == null) {
                    toDisplay = categoryModel;
                }
                if (getBrowseHistory().findEntryMatchUrlEndsWith(categoryModel.getCode()) != null) {
                    break;
                }
            }
        }
        categoryModels.clear();
        if (toDisplay != null) {
            breadcrumbs.add(getCategoryBreadcrumb(getCategoryConverter().convert(toDisplay)));
            categoryModels.addAll(toDisplay.getSupercategories());
        }
    }
    Collections.reverse(breadcrumbs);
    return breadcrumbs;
}

From source file:com.uber.hoodie.cli.commands.SavepointsCommand.java

@CliCommand(value = "savepoints show", help = "Show the savepoints")
public String showSavepoints() throws IOException {
    HoodieActiveTimeline activeTimeline = HoodieCLI.tableMetadata.getActiveTimeline();
    HoodieTimeline timeline = activeTimeline.getSavePointTimeline().filterCompletedInstants();
    List<HoodieInstant> commits = timeline.getInstants().collect(Collectors.toList());
    String[][] rows = new String[commits.size()][];
    Collections.reverse(commits);
    for (int i = 0; i < commits.size(); i++) {
        HoodieInstant commit = commits.get(i);
        rows[i] = new String[] { commit.getTimestamp() };
    }//from  ww  w.j  a va 2 s .c o m
    return HoodiePrintHelper.print(new String[] { "SavepointTime" }, rows);
}

From source file:fr.jetoile.hadoopunit.HadoopBootstrap.java

public void stopAll() {
    if (manualComponentsToStop.isEmpty()) {
        internalStop(componentsToStop);//from   w  w  w. ja v a2  s . c o  m
    } else {
        manualComponentsToStop = Lists.newArrayList(this.manualComponentsToStart);
        Collections.reverse(manualComponentsToStop);
        internalStop(manualComponentsToStop);
    }
}

From source file:TimeUtil.java

public static String friendly(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.friendly(unitAmount)));
    }//  w  w  w. j a  v  a2s .  c om

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

From source file:com.eurelis.opencms.admin.fileinformation.CmsFileInformationDeleteAndPublishThread.java

/**
 * @see java.lang.Runnable#run()//  w  ww.j a v a 2 s. c  om
 */
@Override
public void run() {

    I_CmsReport report = getReport();
    try {
        if (LOG.isDebugEnabled()) {
            LOG.debug(Messages.get().getBundle().key(Messages.LOG_DELETE_THREAD_STARTED_0));
        }
        m_resourceNames = CmsModuleManager.topologicalSort(m_resourceNames, null);
        Collections.reverse(m_resourceNames);

        String currentSiteRoot = getCms().getRequestContext().getSiteRoot();
        getCms().getRequestContext().setSiteRoot("/");

        report.println(Messages.get().container(Messages.RPT_DELETE_FILEINFORMATION_BEGIN_0),
                I_CmsReport.FORMAT_HEADLINE);

        Iterator<String> j = m_resourceNames.iterator();
        while (j.hasNext()) {
            String resourceName = j.next();

            resourceName = resourceName.replace('\\', '/');

            // now delete the module
            //OpenCms.getModuleManager().deleteModule(getCms(), moduleName, m_replaceMode, report);

            // now delete the resource
            CmsResource resource = null;
            try {
                resource = getCms().readResource(resourceName, CmsResourceFilter.ALL);
            } catch (CmsVfsResourceNotFoundException e) {
                // ignore
            }
            CmsLock lock = getCms().getLock(resourceName);
            if (lock.isUnlocked()) {
                // lock the resource
                getCms().lockResource(resourceName);
            } else if (lock.isLockableBy(getCms().getRequestContext().getCurrentUser())) {
                // steal the resource
                getCms().changeLock(resourceName);
            }
            if (!resource.getState().isDeleted()) {
                // delete the resource
                getCms().deleteResource(resourceName, CmsResource.DELETE_PRESERVE_SIBLINGS);
            }
            report.print(Messages.get().container(Messages.RPT_DELETE_0), I_CmsReport.FORMAT_NOTE);
            report.println(org.opencms.report.Messages.get()
                    .container(org.opencms.report.Messages.RPT_ARGUMENT_1, resourceName));
            if (!resource.getState().isNew()) {
                // unlock the resource (so it gets deleted with next publish)
                getCms().unlockResource(resourceName);
            }

        }

        report.println(Messages.get().container(Messages.RPT_DELETE_FILEINFORMATION_END_0),
                I_CmsReport.FORMAT_HEADLINE);

        report.println(Messages.get().container(Messages.RPT_PUBLISH_FILEINFORMATION_BEGIN_0),
                I_CmsReport.FORMAT_HEADLINE);

        j = m_resourceNames.iterator();
        while (j.hasNext()) {
            String resourceName = j.next();

            resourceName = resourceName.replace('\\', '/');

            if (getCms().existsResource(resourceName)) {
                // now delete the resource
                CmsResource resource = null;
                try {
                    resource = getCms().readResource(resourceName, CmsResourceFilter.ALL);
                } catch (CmsVfsResourceNotFoundException e) {
                    // ignore
                }
                CmsLock lock = getCms().getLock(resourceName);
                if (lock.isUnlocked()) {
                    // lock the resource
                    getCms().lockResource(resourceName);
                } else if (lock.isLockableBy(getCms().getRequestContext().getCurrentUser())) {
                    // steal the resource
                    getCms().changeLock(resourceName);
                }
                // publish the resource
                OpenCms.getPublishManager().publishResource(getCms(), resourceName);

                report.print(Messages.get().container(Messages.RPT_PUBLISH_0), I_CmsReport.FORMAT_NOTE);
                report.println(org.opencms.report.Messages.get()
                        .container(org.opencms.report.Messages.RPT_ARGUMENT_1, resourceName));
            }

        }

        report.println(Messages.get().container(Messages.RPT_DELETE_FILEINFORMATION_END_0),
                I_CmsReport.FORMAT_HEADLINE);

        getCms().getRequestContext().setSiteRoot(currentSiteRoot);

        if (LOG.isDebugEnabled()) {
            LOG.debug(Messages.get().getBundle().key(Messages.LOG_DELETE_THREAD_FINISHED_0));
        }
    } catch (Throwable e) {
        report.println(e);
        LOG.error(Messages.get().getBundle().key(Messages.LOG_FILEINFORMATION_DELETE_FAILED_1, m_resourceNames),
                e);
    }
}

From source file:net.geoprism.context.ServerInitializer.java

@Request
public static void destroy() {
    ServerContextListenerDocumentBuilder builder = new ServerContextListenerDocumentBuilder();
    List<ServerContextListenerInfo> infos = builder.read();

    Collections.reverse(infos);

    for (ServerContextListenerInfo info : infos) {
        try {//from   w  w w  . j  ava2s. com

            Class<?> clazz = LoaderDecorator.load(info.getClassName());
            Object newInstance = clazz.newInstance();

            try {
                ServerContextListener listener = (ServerContextListener) newInstance;
                listener.shutdown();
            } catch (ClassCastException e) {
                log.error("ClassCastException in ServerInitializer.shutdown", e);

                Class<? extends Object> class1 = newInstance.getClass();
                ClassLoader loader1 = class1.getClassLoader();

                log.debug("New instance class : " + class1.hashCode());
                log.debug("New instance class loader: " + loader1.hashCode());

                Class<? extends Object> class2 = ServerContextListener.class;
                ClassLoader loader2 = class2.getClassLoader();

                log.debug("Interface class : " + class2.hashCode());
                log.debug("New instance class loader: " + loader2.hashCode());

                clazz.getMethod("shutdown").invoke(newInstance);
            }

            log.debug("COMLPETE: " + info.getClassName() + ".shutdown();");
        } catch (Exception e) {
            log.error(e);

            throw new ProgrammingErrorException(
                    "Unable to shutdown the server context listener [" + info.getClassName() + "]", e);
        }
    }
}

From source file:com.eurelis.opencms.admin.fileinformation.CmsFileInformationDeleteThread.java

/**
 * @see java.lang.Runnable#run()/*from   w w  w .j  a va2s  .c  o  m*/
 */
@Override
public void run() {

    I_CmsReport report = getReport();
    try {
        if (LOG.isDebugEnabled()) {
            LOG.debug(Messages.get().getBundle().key(Messages.LOG_DELETE_THREAD_STARTED_0));
        }
        /*if (!m_replaceMode) {
        OpenCms.getModuleManager().checkModuleSelectionList(m_resourceNames, null, true);
        }*/
        m_resourceNames = CmsModuleManager.topologicalSort(m_resourceNames, null);
        Collections.reverse(m_resourceNames);

        String currentSiteRoot = getCms().getRequestContext().getSiteRoot();
        getCms().getRequestContext().setSiteRoot("/");

        report.println(Messages.get().container(Messages.RPT_DELETE_FILEINFORMATION_BEGIN_0),
                I_CmsReport.FORMAT_HEADLINE);

        Iterator<String> j = m_resourceNames.iterator();
        while (j.hasNext()) {
            String resourceName = j.next();

            resourceName = resourceName.replace('\\', '/');

            // now delete the module
            //OpenCms.getModuleManager().deleteModule(getCms(), moduleName, m_replaceMode, report);

            // now delete the resource
            CmsResource resource = null;
            try {
                resource = getCms().readResource(resourceName, CmsResourceFilter.ALL);
            } catch (CmsVfsResourceNotFoundException e) {
                // ignore
            }
            CmsLock lock = getCms().getLock(resourceName);
            if (lock.isUnlocked()) {
                // lock the resource
                getCms().lockResource(resourceName);
            } else if (lock.isLockableBy(getCms().getRequestContext().getCurrentUser())) {
                // steal the resource
                getCms().changeLock(resourceName);
            }
            if (!resource.getState().isDeleted()) {
                // delete the resource
                getCms().deleteResource(resourceName, CmsResource.DELETE_PRESERVE_SIBLINGS);
            }
            report.print(Messages.get().container(Messages.RPT_DELETE_0), I_CmsReport.FORMAT_NOTE);
            report.println(org.opencms.report.Messages.get()
                    .container(org.opencms.report.Messages.RPT_ARGUMENT_1, resourceName));
            if (!resource.getState().isNew()) {
                // unlock the resource (so it gets deleted with next publish)
                getCms().unlockResource(resourceName);
            }

        }

        report.println(Messages.get().container(Messages.RPT_DELETE_FILEINFORMATION_END_0),
                I_CmsReport.FORMAT_HEADLINE);

        getCms().getRequestContext().setSiteRoot(currentSiteRoot);

        if (LOG.isDebugEnabled()) {
            LOG.debug(Messages.get().getBundle().key(Messages.LOG_DELETE_THREAD_FINISHED_0));
        }
    } catch (Throwable e) {
        report.println(e);
        LOG.error(Messages.get().getBundle().key(Messages.LOG_FILEINFORMATION_DELETE_FAILED_1, m_resourceNames),
                e);
    }
}