List of usage examples for com.google.common.collect Lists reverse
@CheckReturnValue public static <T> List<T> reverse(List<T> list)
From source file:com.android.tools.idea.updater.configure.PlatformComponentsPanel.java
private void updatePlatformItems() { myPlatformDetailsRootNode.removeAllChildren(); myPlatformSummaryRootNode.removeAllChildren(); myStates.clear();/*from w w w . j av a 2 s . com*/ List<AndroidVersion> versions = Lists.newArrayList(myCurrentPackages.keySet()); versions = Lists.reverse(versions); for (AndroidVersion version : versions) { Set<UpdaterTreeNode> versionNodes = Sets.newHashSet(); UpdaterTreeNode marker = new ParentTreeNode(version); myPlatformDetailsRootNode.add(marker); boolean obsolete = false; for (UpdatablePackage info : myCurrentPackages.get(version)) { RepoPackage pkg = info.getRepresentative(); PackageNodeModel model = new PackageNodeModel(info); myStates.add(model); UpdaterTreeNode node = new DetailsTreeNode(model, myModificationListener, myConfigurable); marker.add(node); versionNodes.add(node); if (pkg.obsolete() && pkg.getTypeDetails() instanceof DetailsTypes.PlatformDetailsType) { obsolete = true; } } if (!obsolete) { SummaryTreeNode node = SummaryTreeNode.createNode(version, versionNodes); if (node != null) { myPlatformSummaryRootNode.add(node); } } } refreshModified(); SdkUpdaterConfigPanel.resizeColumnsToFit(myPlatformDetailTable); SdkUpdaterConfigPanel.resizeColumnsToFit(myPlatformSummaryTable); myPlatformDetailTable.updateUI(); myPlatformSummaryTable.updateUI(); TreeUtil.expandAll(myPlatformDetailTable.getTree()); TreeUtil.expandAll(myPlatformSummaryTable.getTree()); }
From source file:org.sonar.java.checks.DeadStoreCheck.java
private void checkElements(CFG.Block block, Set<Symbol> blockOut, Symbol.MethodSymbol methodSymbol) { Set<Symbol> out = new HashSet<>(blockOut); Set<Tree> assignmentLHS = new HashSet<>(); Lists.reverse(block.elements()).forEach(element -> checkElement(methodSymbol, out, assignmentLHS, element)); }
From source file:com.twitter.graphjet.demo.TopTweetsServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int k = 10;/*from w w w . j a v a2s . c o m*/ String p = request.getParameter("k"); if (p != null) { try { k = Integer.parseInt(p); } catch (NumberFormatException e) { // Just eat it, don't need to worry. } } PriorityQueue<NodeValueEntry> queue = new PriorityQueue<>(k); LongIterator iter = tweets.iterator(); while (iter.hasNext()) { long tweet = iter.nextLong(); int cnt = graphType.equals(GraphType.USER_TWEET) ? bigraph.getRightNodeDegree(tweet) : bigraph.getLeftNodeDegree(tweet); if (cnt == 1) continue; if (queue.size() < k) { queue.add(new NodeValueEntry(tweet, cnt)); } else { NodeValueEntry peek = queue.peek(); // Break ties by preferring higher tweetid (i.e., more recent tweet) if (cnt > peek.getValue() || (cnt == peek.getValue() && tweet > peek.getNode())) { queue.poll(); queue.add(new NodeValueEntry(tweet, cnt)); } } } if (queue.size() == 0) { response.getWriter().println("[]\n"); return; } NodeValueEntry e; List<String> entries = new ArrayList<>(queue.size()); while ((e = queue.poll()) != null) { // Note that we explicitly use id_str and treat the tweet id as a String. See: // https://dev.twitter.com/overview/api/twitter-ids-json-and-snowflake entries.add(String.format("{\"id_str\": \"%d\", \"cnt\": %d}", e.getNode(), e.getValue())); } response.setStatus(HttpStatus.OK_200); response.getWriter().println("[\n" + JOINER.join(Lists.reverse(entries)) + "\n]"); }
From source file:com.collective.celos.servlet.JSONWorkflowSlotsServlet.java
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException { String id = req.getParameter(CelosClient.ID_PARAM); try {/* ww w. ja v a 2s . c o m*/ if (id == null) { res.sendError(HttpServletResponse.SC_BAD_REQUEST, CelosClient.ID_PARAM + " parameter missing."); return; } Scheduler scheduler = getOrCreateCachedScheduler(); Workflow wf = scheduler.getWorkflowConfiguration().findWorkflow(new WorkflowID(id)); if (wf == null) { res.sendError(HttpServletResponse.SC_NOT_FOUND, "Workflow not found: " + id); return; } ScheduledTime endTime = getTimeParam(req, CelosClient.END_TIME_PARAM, new ScheduledTime(DateTime.now(DateTimeZone.UTC))); ScheduledTime startTime = getTimeParam(req, CelosClient.START_TIME_PARAM, scheduler.getWorkflowStartTime(wf, endTime)); if (startTime.plusHours(scheduler.getSlidingWindowHours()).getDateTime() .isBefore(endTime.getDateTime())) { res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Time interval between start and end is limited to: " + scheduler.getSlidingWindowHours() + " hours"); return; } try (StateDatabaseConnection connection = getStateDatabase().openConnection()) { List<SlotState> slotStates = scheduler.getSlotStates(wf, startTime, endTime, connection); List<JsonNode> objectNodes = Lists.newArrayList(); for (SlotState state : Lists.reverse(slotStates)) { objectNodes.add(state.toJSONNode()); } ObjectNode node = Util.MAPPER.createObjectNode(); node.put(CelosClient.INFO_NODE, (JsonNode) Util.MAPPER.valueToTree(wf.getWorkflowInfo())); node.put(CelosClient.PAUSE_NODE, connection.isPaused(wf.getID())); node.putArray(CelosClient.SLOTS_NODE).addAll(objectNodes); writer.writeValue(res.getOutputStream(), node); } } catch (Exception e) { throw new ServletException(e); } }
From source file:org.onosproject.cli.app.ApplicationNameCompleter.java
@Override public int complete(String buffer, int cursor, List<String> candidates) { // Delegate string completer StringsCompleter delegate = new StringsCompleter(); // Command name is the second argument. ArgumentCompleter.ArgumentList list = getArgumentList(); String cmd = list.getArguments()[1]; // Grab apps already on the command (to prevent tab-completed duplicates) // FIXME: This does not work. // final Set previousApps; // if (list.getArguments().length > 2) { // previousApps = Sets.newHashSet( // Arrays.copyOfRange(list.getArguments(), 2, list.getArguments().length)); // } else { // previousApps = Collections.emptySet(); // }/* ww w. jav a2 s .co m*/ // Fetch our service and feed it's offerings to the string completer ApplicationService service = get(ApplicationService.class); Iterator<Application> it = service.getApplications().iterator(); SortedSet<String> strings = delegate.getStrings(); while (it.hasNext()) { Application app = it.next(); ApplicationState state = service.getState(app.id()); // if (previousApps.contains(app.id().name())) { // continue; // } if ("uninstall".equals(cmd) || "download".equals(cmd) || ("activate".equals(cmd) && state == INSTALLED) || ("deactivate".equals(cmd) && state == ACTIVE)) { strings.add(app.id().name()); } } // add unique suffix to candidates, if user has something in buffer if (!Strings.isNullOrEmpty(buffer)) { List<String> suffixCandidates = strings.stream() // remove onos common prefix .map(full -> full.replaceFirst("org\\.onosproject\\.", "")) // a.b.c -> [c, b.c, a.b.c] .flatMap(appName -> { List<String> suffixes = new ArrayList<>(); Deque<String> frags = new ArrayDeque<>(); // a.b.c -> [c, b, a] -> [c, b.c, a.b.c] Lists.reverse(asList(appName.split("\\."))).forEach(frag -> { frags.addFirst(frag); suffixes.add(frags.stream().collect(Collectors.joining("."))); }); return suffixes.stream(); }) // convert to occurrence map .collect(Collectors.groupingBy(e -> e, Collectors.counting())).entrySet().stream() // only accept unique suffix .filter(e -> e.getValue() == 1L).map(Entry::getKey).collect(Collectors.toList()); delegate.getStrings().addAll(suffixCandidates); } // Now let the completer do the work for figuring out what to offer. return delegate.complete(buffer, cursor, candidates); }
From source file:io.v.location.LocationService.java
private static String userEmailFromBlessings(Blessings blessings) { for (List<VCertificate> chain : blessings.getCertificateChains()) { for (VCertificate certificate : Lists.reverse(chain)) { if (certificate.getExtension().contains("@")) { return certificate.getExtension(); }//from w w w . ja va 2 s . c o m } } Log.w(TAG, "Could not determine name from blessings '" + blessings + "'"); return ""; }
From source file:org.apache.brooklyn.core.location.geo.MaxMind2HostGeoLookup.java
public HostGeoInfo getHostGeoInfo(InetAddress address) throws MalformedURLException, IOException { if (lookupFailed) return null; DatabaseReader ll = getDatabaseReader(); if (ll == null) return null; InetAddress extAddress = address; if (Networking.isPrivateSubnet(extAddress)) extAddress = InetAddress.getByName(LocalhostExternalIpLoader.getLocalhostIpQuicklyOrDefault()); try {/*from ww w . java 2 s. c o m*/ CityResponse l = ll.city(extAddress); if (l == null) { if (log.isDebugEnabled()) log.debug("Geo info failed to find location for address {}, using {}", extAddress, ll); return null; } StringBuilder name = new StringBuilder(); if (l.getCity() != null && l.getCity().getName() != null) name.append(l.getCity().getName()); if (l.getSubdivisions() != null) { for (Subdivision subd : Lists.reverse(l.getSubdivisions())) { if (name.length() > 0) name.append(", "); // prefer e.g. USA state codes over state names if (!Strings.isBlank(subd.getIsoCode())) name.append(subd.getIsoCode()); else name.append(subd.getName()); } } if (l.getCountry() != null) { if (name.length() == 0) { name.append(l.getCountry().getName()); } else { name.append(" ("); name.append(l.getCountry().getIsoCode()); name.append(")"); } } HostGeoInfo geo = new HostGeoInfo(address.getHostName(), name.toString(), l.getLocation().getLatitude(), l.getLocation().getLongitude()); log.debug("Geo info lookup (MaxMind DB) for " + address + " returned: " + geo); return geo; } catch (Exception e) { if (log.isDebugEnabled()) log.debug("Geo info lookup failed: " + e); throw Throwables.propagate(e); } }
From source file:pgentity.redis.list.RedisList.java
private List<String> range(Range chRange) { try {// w w w .j av a 2 s . c o m sync.lock(); Range orgRange = new Range(chRange.getMin(), chRange.getMax()); List<Command> revCommands = Lists.reverse(commands); for (Command command : revCommands) { command.reverseRange(orgRange); } List<String> cacheList; if (orgRange.getLength() > 0) { cacheList = DBContext.Redis().lrange(redisKey, orgRange.getMin(), orgRange.getMax() - 1); } else { cacheList = new ArrayList(chRange.getLength()); } for (Command command : commands) { command.applyToCache(cacheList, chRange); } return cacheList; } finally { sync.unlock(); } }
From source file:org.trimou.engine.parser.Template.java
private void renderingFinished(MustacheRenderingEvent event) { List<MustacheListener> listeners = engine.getConfiguration().getMustacheListeners(); if (listeners != null) { for (MustacheListener listener : Lists.reverse(listeners)) { listener.renderingFinished(event); }/* w w w.j av a2s . co m*/ } }
From source file:org.opendaylight.yangtools.yang.model.api.SchemaPath.java
private ImmutableList<QName> getLegacyPath() { ImmutableList<QName> ret = legacyPath; if (ret == null) { final List<QName> tmp = new ArrayList<>(); for (QName qname : getPathTowardsRoot()) { tmp.add(qname);// w w w .j a v a 2s. co m } ret = ImmutableList.copyOf(Lists.reverse(tmp)); LEGACYPATH_UPDATER.lazySet(this, ret); } return ret; }