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:com.bytelightning.opensource.pokerface.ScriptHelperImpl.java
/** * {@inheritDoc}/*w ww. j a v a 2 s . co m*/ */ @Override public String[] getAcceptableLocales() { ArrayList<String> retVal = new ArrayList<String>(); Header[] hdrs = request.getHeaders("Accept-Language"); if ((hdrs != null) && (hdrs.length > 0)) { // Store the accumulated languages that have been requested in a local collection, sorted by the quality value (so we can add Locales in descending order). // The values will be ArrayLists containing the corresponding Locales to be added TreeMap<Double, ArrayList<Locale>> locales = new TreeMap<Double, ArrayList<Locale>>(); for (Header hdr : hdrs) parseLocalesHeader(hdr.getValue(), locales); // Process the quality values in highest->lowest order (due to negating the Double value when creating the key) for (ArrayList<Locale> list : locales.values()) for (Locale locale : list) retVal.add(locale.toLanguageTag()); Collections.reverse(retVal); } retVal.add(Locale.getDefault().toLanguageTag()); return retVal.toArray(new String[retVal.size()]); }
From source file:com.github.braully.graph.DatabaseFacade.java
public synchronized static List<RecordResultGraph> getAllResults(String database) { List<RecordResultGraph> results = new ArrayList(); ObjectMapper mapper = new ObjectMapper(); try {/*from w w w. j a v a 2s . c o m*/ List<Map> tmp = mapper.readValue(new File(database), List.class); if (tmp != null) { try { Iterator<Map> iterator = tmp.iterator(); while (iterator.hasNext()) { RecordResultGraph t = new RecordResultGraph(iterator.next()); results.add(t); } } catch (ClassCastException e) { e.printStackTrace(); } } Collections.reverse(results); } catch (Exception e) { e.printStackTrace(); } return results; }
From source file:py.una.pol.karaku.test.cucumber.TransactionalTestCucumberExecutionListener.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 w w w. ja va 2 s . c om*/ * @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()); ReflectionUtils.rethrowException(ex.getTargetException()); } }
From source file:com.hellblazer.process.impl.AbstractManagedProcess.java
@Override public String getStdErrTail(int numLines) throws IOException { if (!getStdErrFile().exists()) { throw new IllegalThreadStateException("Process has not been started or has already exited"); }//from ww w . java 2 s . co m List<String> lines = new ArrayList<>(); try (ReversedLinesFileReader reader = new ReversedLinesFileReader(getStdErrFile())) { int linesRead = 0; String line; while (((line = reader.readLine()) != null) && (linesRead++ < numLines)) { lines.add(line); } } Collections.reverse(lines); StringBuilder builder = new StringBuilder(); for (String line : lines) { builder.append(line); builder.append('\n'); } return builder.toString(); }
From source file:com.powers.wsexplorer.gui.GUIUtil.java
public static Listener createTextSortListener(final Table table, final Map<String, String> map, final boolean sortOnValues) { Listener sortListener = new Listener() { public void handleEvent(Event e) { final int direction = table.getSortDirection(); Collator collator = Collator.getInstance(Locale.getDefault()); TableColumn column = (TableColumn) e.widget; Set<String> keys = null; List<String> l = new LinkedList<String>(); Iterator<String> itr = null; if (sortOnValues) { TreeMap<String, String> tm = new TreeMap<String, String>( new MapValueComparator(map, direction == SWT.DOWN)); tm.putAll(map);/* w ww. j a v a2 s .c o m*/ if (direction == SWT.DOWN) { table.setSortDirection(SWT.UP); } else { table.setSortDirection(SWT.DOWN); } itr = tm.keySet().iterator(); } else { keys = map.keySet(); l.addAll(keys); Collections.sort(l, collator); if (direction == SWT.DOWN) { Collections.reverse(l); table.setSortDirection(SWT.UP); } else { table.setSortDirection(SWT.DOWN); } itr = l.iterator(); } // remove all table data table.removeAll(); String key = null; String value = null; while (itr.hasNext()) { key = itr.next(); if (StringUtils.isNotBlank(key)) { TableItem ti = new TableItem(table, SWT.BORDER); ti.setText(0, key); value = map.get(key); if (StringUtils.isNotBlank(value)) { ti.setText(1, value); } } } table.setSortColumn(column); } }; return sortListener; }
From source file:net.oddsoftware.android.feedscribe.data.FeedManager.java
public ArrayList<ShortFeedItem> getShortItems(int feedTypes) { ArrayList<ShortFeedItem> result = new ArrayList<ShortFeedItem>(); ArrayList<Feed> feeds = mDB.getFeeds(feedTypes); for (Feed feed : feeds) { ArrayList<ShortFeedItem> items = mDB.getShortFeedItems(feed.mId, null, false); result.addAll(items);//from ww w.j a va 2 s . c om } Collections.sort(result); Collections.reverse(result); return result; }
From source file:module.workingCapital.presentationTier.action.WorkingCapitalAction.java
private ActionForward showList(final HttpServletRequest request, final WorkingCapitalContext workingCapitalContext, final SortedSet<WorkingCapitalProcess> unitProcesses) { if (unitProcesses.size() == 1) { final WorkingCapitalProcess workingCapitalProcess = unitProcesses.first(); return ProcessManagement.forwardToProcess(workingCapitalProcess); } else {//from ww w . j av a 2 s .c o m final List<WorkingCapitalProcess> list = new ArrayList<WorkingCapitalProcess>(unitProcesses); final String sortByArg = request.getParameter("sortBy"); if (sortByArg != null && !sortByArg.isEmpty()) { final int i = sortByArg.indexOf('='); if (i > 0) { final BeanComparator comparator = new BeanComparator(sortByArg.substring(0, i)); Collections.sort(list, comparator); final char c = sortByArg.charAt(i + 1); if (c == 'd' || c == 'D') { Collections.reverse(list); } } } request.setAttribute("unitProcesses", list); return frontPage(request, workingCapitalContext); } }
From source file:fr.mcc.ginco.services.ThesaurusServiceImpl.java
@Override public List<Language> getThesaurusLanguages(String thesaurusId) { Thesaurus th = thesaurusDAO.getById(thesaurusId); if (th == null) { throw new BusinessException("Invalid thesaurusId : " + thesaurusId, "invalid-thesaurus-id"); }// w w w .ja v a2 s.c o m Set<Language> languages = th.getLang(); List<Language> orderedLangs = new ArrayList<Language>(); orderedLangs.addAll(languages); Collections.sort(orderedLangs, new LanguageComparator(defaultLang)); Collections.reverse(orderedLangs); return orderedLangs; }
From source file:io.wcm.caconfig.extensions.contextpath.impl.AbsoluteParentContextPathStrategy.java
@Override public @NotNull Iterator<ContextResource> findContextResources(@NotNull Resource resource) { if (!isValidConfig()) { return Collections.emptyIterator(); }//from w w w. j av a 2 s. com ResourceResolver resourceResolver = resource.getResourceResolver(); PageManager pageManager = resourceResolver.adaptTo(PageManager.class); List<ContextResource> contextResources = new ArrayList<>(); int maxLevel = Path.getAbsoluteLevel(resource.getPath(), resourceResolver); for (int level = 0; level <= maxLevel; level++) { if (levels.contains(level) || (unlimited && level >= unlimitedLevelStart)) { String contextPath = Path.getAbsoluteParent(resource.getPath(), level, resourceResolver); if (StringUtils.isNotEmpty(contextPath)) { Resource contextResource = resource.getResourceResolver().getResource(contextPath); if (contextResource != null) { // first check if resource is blacklisted if (isResourceBelongingToBlacklistedTemplates(contextResource, pageManager)) { log.trace( "Resource '{}' is belonging to a page derived from a blacklisted template, skipping level {}", contextPath, level); break; } for (String configPathPattern : configPathPatterns) { String configRef = deriveConfigRef(contextPath, configPathPattern, resourceResolver); if (configRef != null) { contextResources .add(new ContextResource(contextResource, configRef, serviceRanking)); } } } } } } Collections.reverse(contextResources); return contextResources.iterator(); }
From source file:JTop.java
/** * Get the thread list with CPU consumption and the ThreadInfo for each thread * sorted by the CPU time./*from w w w.ja va 2s.com*/ */ private List<Map.Entry<Long, ThreadInfo>> getThreadList() { // Get all threads and their ThreadInfo objects // with no stack trace long[] tids = tmbean.getAllThreadIds(); ThreadInfo[] tinfos = tmbean.getThreadInfo(tids); // build a map with key = CPU time and value = ThreadInfo SortedMap<Long, ThreadInfo> map = new TreeMap<Long, ThreadInfo>(); for (int i = 0; i < tids.length; i++) { long cpuTime = tmbean.getThreadCpuTime(tids[i]); // filter out threads that have been terminated if (cpuTime != -1 && tinfos[i] != null) { map.put(new Long(cpuTime), tinfos[i]); } } // build the thread list and sort it with CPU time // in decreasing order Set<Map.Entry<Long, ThreadInfo>> set = map.entrySet(); List<Map.Entry<Long, ThreadInfo>> list = new ArrayList<Map.Entry<Long, ThreadInfo>>(set); Collections.reverse(list); return list; }