List of usage examples for com.google.common.collect Iterables getLast
@Nullable public static <T> T getLast(Iterable<? extends T> iterable, @Nullable T defaultValue)
From source file:actors.DeployLogRelay.java
@Override public void onReceive(final Object message) throws Exception { if ("check".equals(message)) { final List<DeploymentLog> logs = DeploymentLog.getLogsSince(_deployment, DeploymentLog.ref(_lastId)); final ObjectNode node = JsonNodeFactory.instance.objectNode(); final ArrayNode messages = node.putArray("messages"); logs.forEach((logLine) -> messages.addObject().put("line", logLine.getMessage()) .put("timestamp", logLine.getLogTime().toString()).put("host", Optional.fromNullable(logLine.getHost()).transform(Host::getName).or("Deployment"))); pushLog(node);//from ww w . j a va 2s . co m _lastId = Optional.fromNullable(Iterables.getLast(logs, null)).transform(DeploymentLog::getId) .or(_lastId); _deployment.refresh(); _logger.info("Refreshed the deploy, finished=" + _deployment.getFinished()); if (_deployment.getFinished() != null) { pushEnd(); context().system().scheduler().scheduleOnce(FiniteDuration.apply(10, TimeUnit.SECONDS), self(), "close", context().dispatcher(), self()); } } else if ("close".equals(message)) { _channel.eofAndEnd(); self().tell(PoisonPill.getInstance(), self()); } }
From source file:cz.cuni.mff.ms.brodecva.botnicek.ide.check.code.model.checker.DefaultCodeChecker.java
/** * Nejlep snaha o odstrann implementa?nch podrobnost a zachovn pouze * samotnho tla zprvy.// www . java 2 s . co m */ private static String cutMessage(final String message) { if (message == Intended.nullReference()) { return ""; } return Iterables.getLast(Splitter.on(MESSAGE_PARTS_SEPARATOR).splitToList(message), "").trim(); }
From source file:com.jeroensteenbeeke.andalite.java.transformation.operations.impl.EnsureEndReturnStatement.java
@Override public ActionResult verify(IBodyContainer input) { AnalyzedStatement last = Iterables.getLast(input.getStatements(), null); if (last instanceof ReturnStatement) { ReturnStatement statement = (ReturnStatement) last; AnalyzedExpression returnExpression = statement.getReturnExpression(); if (!returnExpression.toJavaString().equals(returnValue)) { return ActionResult.error("Invalid return expression: %s", returnExpression.toJavaString()); }//w w w .j a v a2 s .com return ActionResult.ok(); } if (last != null) { return ActionResult.error("Last statement is not a return statement: %s", last.toJavaString()); } else { return ActionResult.error("Body has no statements"); } }
From source file:org.apache.metron.management.ConfigurationFunctions.java
private static synchronized void setupTreeCache(Context context) throws Exception { try {//from w w w. j a v a 2 s.c om Optional<Object> treeCacheOpt = context.getCapability("treeCache"); if (treeCacheOpt.isPresent()) { return; } } catch (IllegalStateException ex) { } Optional<Object> clientOpt = context.getCapability(Context.Capabilities.ZOOKEEPER_CLIENT); if (!clientOpt.isPresent()) { throw new IllegalStateException( "I expected a zookeeper client to exist and it did not. Please connect to zookeeper."); } CuratorFramework client = (CuratorFramework) clientOpt.get(); TreeCache cache = new TreeCache(client, Constants.ZOOKEEPER_TOPOLOGY_ROOT); TreeCacheListener listener = new TreeCacheListener() { @Override public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exception { if (event.getType().equals(TreeCacheEvent.Type.NODE_ADDED) || event.getType().equals(TreeCacheEvent.Type.NODE_UPDATED)) { String path = event.getData().getPath(); byte[] data = event.getData().getData(); String sensor = Iterables.getLast(Splitter.on("/").split(path), null); if (path.startsWith(ConfigurationType.PARSER.getZookeeperRoot())) { Map<String, String> sensorMap = (Map<String, String>) configMap .get(ConfigurationType.PARSER); sensorMap.put(sensor, new String(data)); } else if (ConfigurationType.GLOBAL.getZookeeperRoot().equals(path)) { configMap.put(ConfigurationType.GLOBAL, new String(data)); } else if (ConfigurationType.PROFILER.getZookeeperRoot().equals(path)) { configMap.put(ConfigurationType.PROFILER, new String(data)); } else if (path.startsWith(ConfigurationType.ENRICHMENT.getZookeeperRoot())) { Map<String, String> sensorMap = (Map<String, String>) configMap .get(ConfigurationType.ENRICHMENT); sensorMap.put(sensor, new String(data)); } else if (path.startsWith(ConfigurationType.INDEXING.getZookeeperRoot())) { Map<String, String> sensorMap = (Map<String, String>) configMap .get(ConfigurationType.INDEXING); sensorMap.put(sensor, new String(data)); } } else if (event.getType().equals(TreeCacheEvent.Type.NODE_REMOVED)) { String path = event.getData().getPath(); String sensor = Iterables.getLast(Splitter.on("/").split(path), null); if (path.startsWith(ConfigurationType.PARSER.getZookeeperRoot())) { Map<String, String> sensorMap = (Map<String, String>) configMap .get(ConfigurationType.PARSER); sensorMap.remove(sensor); } else if (path.startsWith(ConfigurationType.ENRICHMENT.getZookeeperRoot())) { Map<String, String> sensorMap = (Map<String, String>) configMap .get(ConfigurationType.ENRICHMENT); sensorMap.remove(sensor); } else if (path.startsWith(ConfigurationType.INDEXING.getZookeeperRoot())) { Map<String, String> sensorMap = (Map<String, String>) configMap .get(ConfigurationType.INDEXING); sensorMap.remove(sensor); } else if (ConfigurationType.PROFILER.getZookeeperRoot().equals(path)) { configMap.put(ConfigurationType.PROFILER, null); } else if (ConfigurationType.GLOBAL.getZookeeperRoot().equals(path)) { configMap.put(ConfigurationType.GLOBAL, null); } } } }; cache.getListenable().addListener(listener); cache.start(); for (ConfigurationType ct : ConfigurationType.values()) { switch (ct) { case GLOBAL: case PROFILER: { String data = ""; try { byte[] bytes = ConfigurationsUtils.readFromZookeeper(ct.getZookeeperRoot(), client); data = new String(bytes); } catch (Exception ex) { } configMap.put(ct, data); } break; case INDEXING: case ENRICHMENT: case PARSER: { List<String> sensorTypes = client.getChildren().forPath(ct.getZookeeperRoot()); Map<String, String> sensorMap = (Map<String, String>) configMap.get(ct); for (String sensorType : sensorTypes) { sensorMap.put(sensorType, new String(ConfigurationsUtils .readFromZookeeper(ct.getZookeeperRoot() + "/" + sensorType, client))); } } break; } } context.addCapability("treeCache", () -> cache); }
From source file:com.android.tools.idea.welcome.wizard.ConsoleHighlighter.java
public synchronized void print(String string, @Nullable TextAttributes attributes) { Application application = ApplicationManager.getApplication(); myPendingStrings.append(string);//from w w w. j av a 2 s. c om if (!myIsUpdatePending && application != null && !application.isUnitTestMode()) { myIsUpdatePending = true; application.invokeLater(new Runnable() { @Override public void run() { appendToDocument(); } }, myModalityState); } HighlightRange lastRange = Iterables.getLast(myRanges, HighlightRange.EMPTY); assert lastRange != null; int start = lastRange.end; myRanges.add(new HighlightRange(start, start + string.length(), attributes)); }
From source file:org.apache.metron.writer.NoopWriter.java
private Function<Void, Void> getSleepFunction(String sleepConfig) { String usageMessage = "Unexpected: " + sleepConfig + " Expected value: integer for a fixed sleep duration in milliseconds (e.g. 10) " + "or a range of latencies separated by a comma (e.g. \"10, 20\") to sleep a random amount in that range."; try {/*from w ww . ja v a2s. c o m*/ if (sleepConfig.contains(",")) { // random latency within a range. Iterable<String> it = Splitter.on(',').split(sleepConfig); Integer min = ConversionUtils.convert(Iterables.getFirst(it, "").trim(), Integer.class); Integer max = ConversionUtils.convert(Iterables.getLast(it, "").trim(), Integer.class); if (min != null && max != null) { return new RandomLatency(min, max); } } else { //fixed latency Integer latency = ConversionUtils.convert(sleepConfig.trim(), Integer.class); if (latency != null) { return new FixedLatency(latency); } } } catch (Throwable t) { throw new IllegalArgumentException(usageMessage, t); } throw new IllegalArgumentException(usageMessage); }
From source file:org.opendaylight.controller.config.persist.storage.file.xml.model.Config.java
public Optional<ConfigSnapshot> getLastSnapshot() { ConfigSnapshot last = Iterables.getLast(snapshots, null); return last == null ? Optional.<ConfigSnapshot>absent() : Optional.of(last); }
From source file:nextmethod.web.razor.parser.syntaxtree.Block.java
public Span findLastDescendentSpan() { SyntaxTreeNode current = this; while (current != null && current.isBlock()) { current = Iterables.getLast(((Block) current).children, null); }/*from w w w . j a v a 2 s.c om*/ return typeAs(current, Span.class); }
From source file:com.madvay.tools.android.perf.apat.CommandLine.java
public String getUnaryFlagWithDefault(String name, String def) { return Iterables.getLast(flags.get(name), def); }
From source file:com.b2international.snowowl.datastore.BranchPath.java
@Override public String lastSegment() { if (BranchPathUtils.isMain(this)) { return IBranchPath.MAIN_BRANCH; }// ww w . j av a 2 s . c om if (StringUtils.isEmpty(path)) { return IBranchPath.EMPTY_PATH; } final Splitter splitter = Splitter.on(IBranchPath.SEPARATOR_CHAR).omitEmptyStrings().trimResults(); final Iterable<String> segments = splitter.split(path); return Iterables.getLast(segments, IBranchPath.EMPTY_PATH); }