List of usage examples for java.util Collections reverse
@SuppressWarnings({ "rawtypes", "unchecked" }) public static void reverse(List<?> list)
This method runs in linear time.
From source file:io.haze.core.Application.java
/** * Start this {@link Application}.//from www . java2s . co m */ private void start() { isRunning = true; for (ServiceFactory factory : factories) { factory.createServices(this); } if (services.size() > 0) { // build list of nodes for (Node node : getServices(Node.class)) { nodes.add(node); } // reverse the service order, so they can be started descendingly Collections.reverse(services); // start services logger.info("Starting services:"); for (Service service : services) { service.initialize(); service.start(); logger.info(String.format(" * %s", service.getName())); } // put the service order back Collections.reverse(services); } // register shutdown hook final Application app = this; Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { if (app.isRunning()) { app.stop(); return; } // forcefully exit System.exit(1); } }); }
From source file:edu.cornell.mannlib.vitro.webapp.startup.StartupManager.java
/** * Notify the listeners that the context is being destroyed, in the reverse * order from how they were notified at initialization. */// w ww. ja v a2s . c om @Override public void contextDestroyed(ServletContextEvent sce) { List<ServletContextListener> destroyList = new ArrayList<ServletContextListener>(initializeList); Collections.reverse(destroyList); for (ServletContextListener listener : destroyList) { try { log.debug("Destroying '" + listener.getClass().getName() + "'"); listener.contextDestroyed(sce); } catch (Exception e) { log.error("Unexpected exception from contextDestroyed() on '" + listener.getClass().getName() + "'", e); } catch (Throwable t) { log.fatal("Unexpected error from contextDestroyed() on '" + listener.getClass().getName() + "'", t); throw t; } } log.info("Called 'contextDestroyed' on all listeners."); }
From source file:com.weibo.api.motan.protocol.support.ProtocolFilterDecorator.java
/** * <pre>//from ww w .j av a 2 s. c om * ?? * 1?filter * 2?filter??filtersfilter? * 3?????filter?accessLog??accesslog * </pre> * * @param url * @param key * @return */ private List<Filter> getFilters(URL url, String key) { // load default filters List<Filter> filters = new ArrayList<Filter>(); List<Filter> defaultFilters = ExtensionLoader.getExtensionLoader(Filter.class).getExtensions(key); if (defaultFilters != null && defaultFilters.size() > 0) { filters.addAll(defaultFilters); } // add filters via "filter" config String filterStr = url.getParameter(URLParamType.filter.getName()); if (StringUtils.isNotBlank(filterStr)) { String[] filterNames = MotanConstants.COMMA_SPLIT_PATTERN.split(filterStr); for (String fn : filterNames) { addIfAbsent(filters, fn); } } // add filter via other configs, like accessLog and so on boolean accessLog = url.getBooleanParameter(URLParamType.accessLog.getName(), URLParamType.accessLog.getBooleanValue()); if (accessLog) { addIfAbsent(filters, AccessLogFilter.class.getAnnotation(SpiMeta.class).name()); } // sort the filters Collections.sort(filters, new ActivationComparator<Filter>()); Collections.reverse(filters); return filters; }
From source file:gate.util.reporting.DocTimeReporter.java
/** * Sorts LinkedHashMap by its values(natural descending order). keeps the * duplicates as it is.//from www . j a va 2 s . co m * * @param passedMap * An Object of type LinkedHashMap to be sorted by its values. * @return An Object containing the sorted LinkedHashMap. */ private LinkedHashMap<?, ?> sortHashMapByValues(LinkedHashMap<String, String> passedMap) { List<String> mapKeys = new ArrayList<String>(passedMap.keySet()); List<String> mapValues = new ArrayList<String>(passedMap.values()); Collections.sort(mapValues, new ValueComparator()); Collections.sort(mapKeys); // Reversing the collection to sort the values in descending order Collections.reverse(mapValues); LinkedHashMap<String, String> sortedMap = new LinkedHashMap<String, String>(); Iterator<String> valueIt = mapValues.iterator(); while (valueIt.hasNext()) { String val = valueIt.next(); Iterator<String> keyIt = mapKeys.iterator(); while (keyIt.hasNext()) { String key = keyIt.next(); String comp1 = passedMap.get(key).toString(); String comp2 = val.toString(); if (comp1.equals(comp2)) { passedMap.remove(key); mapKeys.remove(key); sortedMap.put(key, val); break; } } } return sortedMap; }
From source file:NimbleTree.java
/** * Find all the paths from root to leaves. Used by NGramEDAReproductionOperation. * @return list of list of TreeNode, each list starting at the root and ending at a leaf. *///from w w w. j a v a 2 s. c o m public ArrayList<ArrayList<TreeNode<E>>> getRootToLeafPaths() { ArrayList<TreeNode<E>> leafNodes = new ArrayList<TreeNode<E>>(); // traverse the tree and find the leaf nodes for (TreeNode<E> node : depthFirstTraversal(getRoot())) { if (node.size() == 0) { leafNodes.add(node); } } ArrayList<ArrayList<TreeNode<E>>> paths = new ArrayList<ArrayList<TreeNode<E>>>(); for (TreeNode<E> leaf : leafNodes) { ArrayList<TreeNode<E>> path = new ArrayList<TreeNode<E>>(); TreeNode<E> current = leaf; while (current != getRoot()) { path.add(current); current = current.getParent(); } // add the root path.add(current); Collections.reverse(path); paths.add(path); } return paths; }
From source file:com.bigdata.dastor.thrift.server.DastorThriftServer.java
private List<ColumnOrSuperColumn> thriftifySuperColumns(Collection<IColumn> columns, boolean reverseOrder) { ArrayList<ColumnOrSuperColumn> thriftSuperColumns = new ArrayList<ColumnOrSuperColumn>(columns.size()); for (IColumn column : columns) { List<Column> subcolumns = thriftifySubColumns(column.getSubColumns()); if (subcolumns.isEmpty()) { continue; }/* www. j a va 2 s.co m*/ SuperColumn superColumn = new SuperColumn(column.name(), subcolumns); thriftSuperColumns.add(createColumnOrSuperColumn_SuperColumn(superColumn)); } if (reverseOrder) Collections.reverse(thriftSuperColumns); return thriftSuperColumns; }
From source file:com.google.gwt.emultest.java.util.TreeMapTest.java
private static <E> Collection<E> reverseCollection(Collection<E> c) { List<E> reversedCollection = new ArrayList<E>(c); Collections.reverse(reversedCollection); return reversedCollection; }
From source file:com.epam.cme.storefront.util.PageTitleResolver.java
protected List<CategoryModel> getCategoryPath(final CategoryModel category) { final Collection<List<CategoryModel>> paths = getCommerceCategoryService().getPathsForCategory(category); // Return first - there will always be at least 1 final List<CategoryModel> cat2ret = paths.iterator().next(); Collections.reverse(cat2ret); return cat2ret; }
From source file:com.silverpeas.look.SilverpeasLook.java
public String getCSSOfSpaceLook(String spaceId) { List<SpaceInst> path = organizationController.getSpacePath(spaceId); Collections.reverse(path); String cssURL = null;//from w w w .j a v a 2s.c o m for (SpaceInst space : path) { if (StringUtil.isDefined(space.getLook())) { cssURL = GraphicElementFactory.getCSSOfLook(space.getLook()); } if (StringUtil.isDefined(cssURL)) { break; } } return cssURL; }
From source file:annis.sqlgen.GraphWithClauseGenerator.java
private String generatePathName(URI uri) { StringBuilder sb = new StringBuilder(); List<String> path = CommonHelper.getCorpusPath(uri); Collections.reverse(path); sb.append("{"); sb.append(StringUtils.join(path, ", ")); sb.append("}"); return sqlString(sb.toString()); }