List of usage examples for com.google.common.base Strings isNullOrEmpty
public static boolean isNullOrEmpty(@Nullable String string)
From source file:org.carrot2.source.microsoft.FetchAndSaveBingResponse.java
public static void main(String[] args) throws Exception { final Controller controller = ControllerFactory.createSimple(); try {/* w w w. java2 s . c o m*/ String appid = System.getProperty(Bing3DocumentSource.SYSPROP_BING3_API); if (Strings.isNullOrEmpty(appid)) { System.err.println("Provide Bing3 API key in property: " + Bing3DocumentSource.SYSPROP_BING3_API); } final Map<String, Object> attributes = new HashMap<String, Object>(); CommonAttributesDescriptor.attributeBuilder(attributes).query(" ") .results(200); /* Put your own API key here or in a system property! */ Bing3WebDocumentSourceDescriptor.attributeBuilder(attributes).appid(appid).market((MarketOption) null); ProcessingResult result = controller.process(attributes, Bing3WebDocumentSource.class); Persister p = new Persister(); p.write(result, new File("result.xml")); } finally { controller.dispose(); } }
From source file:bst.examples.BSTExamples.java
/** * @param args the command line arguments *///from w w w . ja va2 s .c o m public static void main(String[] args) { // TODO code application logic here BinarySearchTree b = new BinarySearchTree(); b.insert(3); b.insert(8); b.insert(1); b.insert(4); b.insert(6); b.insert(2); b.insert(10); b.insert(9); b.insert(20); b.insert(25); b.insert(15); b.insert(16); System.out.println("Original Tree : "); List<String> myList = Arrays.asList("a1", "a2", "b1", "c2", "c1"); System.out.println(Strings.isNullOrEmpty("")); myList.stream().filter(s -> s.startsWith("c")).map(String::toUpperCase).sorted() .forEach(System.out::println); }
From source file:qa.qcri.nadeef.web.Dashboard.java
public static void main(String[] args) { Bootstrap.start();/*ww w .j a v a 2 s .co m*/ Tracer tracer = Tracer.getTracer(Dashboard.class); String rootDir = System.getProperty("rootDir"); if (Strings.isNullOrEmpty(rootDir)) { staticFileLocation("qa/qcri/nadeef/web/public"); } else { externalStaticFileLocation(rootDir); } get("/", (request, response) -> { response.redirect("/index.html"); return 0; }); exception(Exception.class, (ex, request, response) -> { response.status(400); tracer.err("Exception happens ", ex); JsonObject json = new JsonObject(); json.add("error", new JsonPrimitive(ex.getMessage())); response.body(json.toString()); }); SQLDialect dialect = NadeefConfiguration.getDbConfig().getDialect(); WidgetAction.setup(dialect); TableAction.setup(dialect); RuleAction.setup(dialect); SourceAction.setup(dialect); RemoteAction.setup(dialect); ProjectAction.setup(dialect); AnalyticAction.setup(dialect); }
From source file:org.seedstack.seed.core.SeedMain.java
/** * Entry point of Seed standalone applications (launched from the command-line). * * @param args The command-line arguments. *//*ww w .ja va2 s. c o m*/ public static void main(String[] args) { String toolName = System.getProperty("seedstack.tool"); SeedLauncher seedLauncher; if (!Strings.isNullOrEmpty(toolName)) { seedLauncher = getToolLauncher(toolName); } else { seedLauncher = getLauncher(); } Runtime.getRuntime().addShutdownHook(new Thread(() -> { try { seedLauncher.shutdown(); } catch (Exception e) { handleException(e); } Seed.close(); }, "shutdown")); try { seedLauncher.launch(args); } catch (Exception e) { handleException(e); System.exit(-1); } }
From source file:com.github.fge.jsonschema.misc.WebApp.java
public static void main(final String... args) throws Exception { final String webappDirLocation = "src/main/webapp/"; //The port that we should run on can be set into an environment variable //Look for that variable and default to 8080 if it isn't there. String webPort = System.getenv("PORT"); if (Strings.isNullOrEmpty(webPort)) webPort = "8080"; final Server server = new Server(Integer.valueOf(webPort)); final WebAppContext root = new WebAppContext(); root.setContextPath("/"); root.setDescriptor(webappDirLocation + "/WEB-INF/web.xml"); root.setResourceBase(webappDirLocation); //Parent loader priority is a class loader setting that Jetty accepts. //By default Jetty will behave like most web containers in that it will //allow your application to replace non-server libraries that are part of the //container. Setting parent loader priority to true changes this behavior. //Read more here: http://wiki.eclipse.org/Jetty/Reference/Jetty_Classloading root.setParentLoaderPriority(true);//from w w w . j a v a 2s . c om server.setHandler(root); server.start(); server.join(); }
From source file:com.google.devtools.kythe.extractors.jvm.JarExtractor.java
public static void main(String[] args) throws IOException, ExtractionException { JvmExtractor.Options options = new JvmExtractor.Options(); JCommander jc = new JCommander(options, args); jc.setProgramName("jar_extractor"); if (options.help) { jc.usage();/*from ww w. j a v a 2 s . co m*/ System.exit(2); } CompilationDescription indexInfo = JvmExtractor.extract(options); String outputFile = System.getenv("KYTHE_OUTPUT_FILE"); if (!Strings.isNullOrEmpty(outputFile)) { IndexInfoUtils.writeIndexInfoToFile(indexInfo, outputFile); } else { String outputDir = System.getenv("KYTHE_OUTPUT_DIRECTORY"); if (Strings.isNullOrEmpty(outputDir)) { throw new IllegalArgumentException( "required KYTHE_OUTPUT_FILE or KYTHE_OUTPUT_DIRECTORY environment variable is unset"); } if (Strings.isNullOrEmpty(System.getenv("KYTHE_INDEX_PACK"))) { String name = Hashing.sha256().hashUnencodedChars(Joiner.on(" ").join(args)).toString(); String path = IndexInfoUtils.getIndexPath(outputDir, name).toString(); IndexInfoUtils.writeIndexInfoToFile(indexInfo, path); } else { new Archive(outputDir).writeDescription(indexInfo); } } }
From source file:org.parboiled.examples.calculators.CalculatorParser.java
@SuppressWarnings({ "unchecked" }) public static <V, P extends CalculatorParser<V>> void main(Class<P> parserClass) { CalculatorParser<V> parser = Parboiled.createParser(parserClass); while (true) { System.out.print("Enter a calculators expression (single RETURN to exit)!\n"); String input = new Scanner(System.in).nextLine(); if (Strings.isNullOrEmpty(input)) break; ParsingResult<?> result = new RecoveringParseRunner(parser.inputLine()).run(input); if (result.hasErrors()) { System.out.println("\nParse Errors:\n" + printParseErrors(result)); }//from ww w .ja v a 2 s . c o m Object value = result.parseTreeRoot.getValue(); if (value != null) { String str = value.toString(); int ix = str.indexOf('|'); if (ix >= 0) str = str.substring(ix + 2); // extract value part of AST node toString() System.out.println(input + " = " + str + '\n'); } if (value instanceof GraphNode) { System.out.println("\nAbstract Syntax Tree:\n" + printTree((GraphNode) value, new ToStringFormatter(null)) + '\n'); } else { System.out.println("\nParse Tree:\n" + printNodeTree(result) + '\n'); } } }
From source file:org.attribyte.api.pubsub.impl.client.ReplicationTestEndpoint.java
public static void main(String[] args) throws Exception { Properties props = new Properties(); FileInputStream fis = new FileInputStream(args[0]); props.load(fis);/*from w w w . j a va2 s .c o m*/ fis.close(); String _hubURL = props.getProperty("hub.url"); if (_hubURL == null) { System.err.println("The 'hub.url' must be specified"); System.exit(1); } if (_hubURL.endsWith("/")) { _hubURL = _hubURL.substring(0, _hubURL.length() - 1); } final String hubURL = _hubURL; String _replicationTopicURL = props.getProperty("hub.replicationTopic"); if (Strings.isNullOrEmpty(_replicationTopicURL)) { System.err.println("The 'hub.replicationTopic' must be specified"); System.exit(1); } if (!_replicationTopicURL.startsWith("/")) { _replicationTopicURL = "/" + _replicationTopicURL; } final String replicationTopicURL = _replicationTopicURL; String hubUsername = props.getProperty("hub.username"); String hubPassword = props.getProperty("hub.password"); final Optional<BasicAuth> hubAuth; if (hubUsername != null && hubPassword != null) { hubAuth = Optional.of(new BasicAuth(hubUsername, hubPassword)); } else { hubAuth = Optional.absent(); } Topic replicationTopic = new Topic.Builder().setTopicURL(replicationTopicURL).setId(2L).create(); String listenAddress = props.getProperty("endpoint.listenAddress", "127.0.0.1"); int listenPort = Integer.parseInt(props.getProperty("endpoint.listenPort", "8088")); String endpointUsername = props.getProperty("endpoint.username"); String endpointPassword = props.getProperty("endpoint.password"); final Optional<BasicAuth> endpointAuth; if (!Strings.isNullOrEmpty(endpointUsername) && !Strings.isNullOrEmpty(endpointPassword)) { endpointAuth = Optional.of(new BasicAuth(endpointUsername, endpointPassword)); } else { endpointAuth = Optional.absent(); } final AtomicLong completeCount = new AtomicLong(); final NotificationEndpoint notificationEndpoint = new NotificationEndpoint(listenAddress, listenPort, endpointAuth, ImmutableList.of(replicationTopic), new NotificationEndpoint.Callback() { @Override public boolean notification(final Notification notification) { byte[] body = notification.getContent().toByteArray(); System.out.println(new String(body, Charsets.UTF_8)); Collection<Header> headers = notification.getHeaders(); if (headers != null) { for (Header header : headers) { System.out.println(header.toString()); } } completeCount.incrementAndGet(); return true; } }); notificationEndpoint.start(); String _endpointCallbackBase = props.getProperty("endpoint.callbackBase"); if (_endpointCallbackBase == null) { System.err.println("The 'endpoint.callbackBase' must be specified"); System.exit(1); } if (_endpointCallbackBase.endsWith("/")) { _endpointCallbackBase = _endpointCallbackBase.substring(0, _endpointCallbackBase.length() - 1); } final String endpointCallbackBase = _endpointCallbackBase; final SubscriptionClient subscriptionClient = new SubscriptionClient(); subscriptionClient.start(); SubscriptionClient.Result res = subscriptionClient.postSubscriptionRequest(replicationTopicURL, hubURL + "/subscribe", endpointCallbackBase + replicationTopicURL, 3600 * 24 * 365 * 5, endpointAuth, hubAuth); if (res.isError) { System.err.println("Problem creating subscription: " + res.code); if (res.message.isPresent()) { System.err.println(res.message.get()); } if (res.cause.isPresent()) { res.cause.get().printStackTrace(); } } else { System.out.println("Subscription created!"); } long elapsedMillis = 0L; long maxMillis = 30000L; while (elapsedMillis < maxMillis) { Thread.sleep(5000L); System.out.println("Completed " + completeCount.get()); elapsedMillis += 5000L; } System.out.println("Unsubscribing..."); subscriptionClient.postUnsubscribeRequest(replicationTopicURL, hubURL + "/subscribe", endpointCallbackBase + replicationTopicURL, endpointAuth, hubAuth); Thread.sleep(5000L); System.out.println("Shutting down subscription client..."); subscriptionClient.shutdown(); System.out.println("Shutting down notification endpoint..."); notificationEndpoint.stop(); System.out.println("Notification endpoint stopped..."); }
From source file:com.axelor.erp.data.Main.java
/** * Main method.//from w w w . j a v a 2s . c om * Can be launched by the script axelor-data.sh * * @param args * Arguments * * @throws Exception */ public static void main(String[] args) throws Exception { final Commander cmd = new Commander(); try { if (args == null || args.length == 0) throw new Exception(); cmd.parse(args); if (!cmd.getDataDir().isDirectory()) throw new Exception("invalid data directory"); if (!cmd.getConfig().isFile()) throw new Exception("invalid config file"); } catch (Exception e) { String message = e.getMessage(); if (!Strings.isNullOrEmpty(message)) System.err.println(e.getMessage()); Commander.usage(); return; } if (cmd.getShowHelp() == Boolean.TRUE) { Commander.usage(); return; } final String errorDir = cmd.getErrorDir() == null ? null : cmd.getErrorDir().getPath(); Injector injector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { install(new JpaModule("persistenceImportUnit", true, true)); install(new AuthModule.Simple()); bindConstant().annotatedWith(Names.named("axelor.data.config")).to(cmd.getConfig().toString()); bindConstant().annotatedWith(Names.named("axelor.data.dir")).to(cmd.getDataDir().toString()); bind(String.class).annotatedWith(Names.named("axelor.error.dir")) .toProvider(Providers.<String>of(errorDir)); } }); CSVImporter importer = injector.getInstance(CSVImporter.class); importer.addListener(new Listener() { @Override public void imported(Model bean) { } @Override public void imported(Integer total, Integer success) { System.out.println("/*** Records total : " + total); System.out.println("/*** Records success : " + success); } @Override public void handle(Model bean, Exception e) { } }); importer.run(null); }
From source file:com.axelor.apps.erp.Main.java
/** * Main method.//from w ww.ja v a2 s. c o m * Can be launched by the script axelor-data.sh * * @param args * Arguments * * @throws Exception */ public static void main(String[] args) throws Exception { final Commander cmd = new Commander(); try { if (args == null || args.length == 0) throw new Exception(); cmd.parse(args); if (!cmd.getDataDir().isDirectory()) throw new Exception("invalid data directory"); if (!cmd.getConfig().isFile()) throw new Exception("invalid config file"); } catch (Exception e) { String message = e.getMessage(); if (!Strings.isNullOrEmpty(message)) System.err.println(e.getMessage()); Commander.usage(); return; } if (cmd.getShowHelp() == Boolean.TRUE) { Commander.usage(); return; } final String errorDir = cmd.getErrorDir() == null ? null : cmd.getErrorDir().getPath(); Injector injector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { install(new JpaModule("persistenceUnit", true, true)); install(new AuthModule.Simple()); install(new AppModule()); bindConstant().annotatedWith(Names.named("axelor.data.config")).to(cmd.getConfig().toString()); bindConstant().annotatedWith(Names.named("axelor.data.dir")).to(cmd.getDataDir().toString()); bind(String.class).annotatedWith(Names.named("axelor.error.dir")) .toProvider(Providers.<String>of(errorDir)); } }); CSVImporter importer = injector.getInstance(CSVImporter.class); importer.addListener(new Listener() { @Override public void imported(Model bean) { } @Override public void imported(Integer total, Integer success) { System.out.println("/*** Records total : " + total); System.out.println("/*** Records success : " + success); } @Override public void handle(Model bean, Exception e) { } }); importer.run(null); }