List of usage examples for java.lang String isEmpty
public boolean isEmpty()
From source file:StringDemo.java
public static void main(String[] args) { String myString = ""; if (myString.isEmpty()) { System.out.println("Empty"); } else {/*from w ww . jav a 2s . co m*/ System.out.println("Not empty"); } }
From source file:com.skynetcomputing.skynettools.Main.java
/** * @param args the command line arguments *///from ww w. j ava 2 s. c om public static void main(String[] args) throws IOException { Scanner s = new Scanner(System.in); boolean isRunning = true; while (isRunning) { System.out.println("Enter file path for MD5 hash. Leave empty to quit"); String input = s.nextLine(); isRunning = !input.isEmpty(); if (isRunning) { File inputFile = new File(input); if (inputFile.length() > 0) { try (FileInputStream fis = new FileInputStream(inputFile)) { String md5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(fis); System.out.println("MD5: " + md5); } } } } }
From source file:web.ui.WebApplication.java
public static void main(String[] args) throws Exception { String webPort = System.getenv("PORT"); if (webPort == null || webPort.isEmpty()) { webPort = "8080"; }/*from w w w . j a v a 2 s .co m*/ System.setProperty("server.port", webPort); SpringApplication.run(WebApplication.class, args); }
From source file:example.ToCommonsEmpty.java
public static void main(String[] args) { String s = ""; boolean a = s == null || s.length() == 0; boolean b = s == null || s.isEmpty(); boolean c = s != null && s.isEmpty(); boolean d = s != null && s.length() == 0; }
From source file:Main.java
public static void main(String[] args) { String str1 = "Hello"; String str2 = ""; // Using the isEmpty() method boolean empty1 = str1.isEmpty(); // Assigns false to empty1 boolean empty2 = str2.isEmpty(); // Assigns true to empty1 // Using the equals() method boolean empty3 = "".equals(str1); // Assigns false to empty3 boolean empty4 = "".equals(str2); // Assigns true to empty4 // Comparing length of the string with 0 boolean empty5 = str1.length() == 0; // Assigns false to empty5 boolean empty6 = str2.length() == 0; // Assigns true to empty6 }
From source file:cc.vidr.datum.tools.Console.java
public static void main(String[] args) throws IOException { System.out.print("Warming up... "); System.out.flush();/* w w w . ja v a 2 s.co m*/ QA.query(""); System.out.println("Ready."); System.out.println("Ask me a question. Leave a blank line to exit."); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); while (true) { int numServers = Server.getNumServers(); int numFacts = Server.getNumFacts(); System.out.print("> "); String q = in.readLine(); if (q == null || q.isEmpty()) { System.out.println("Bye."); break; } Literal[] facts; if (q.startsWith("?-")) { try { Program program = new Program(q.substring(2)); Clause[] query = program.parse(); facts = Server.query(query[0].getHead()); } catch (RecognitionException e) { facts = new Literal[0]; } } else { facts = QA.query(q); } for (Literal fact : facts) printFact(fact, 0); if (facts.length == 0) System.out.println("I don't know."); if (DEBUG) { System.err.println((Server.getNumServers() - numServers) + " servers spawned"); System.err.println((Server.getNumFacts() - numFacts) + " facts retrieved/generated"); } } }
From source file:com.asual.lesscss.LessEngineCli.java
public static void main(String[] args) throws LessException, URISyntaxException { Options cmdOptions = new Options(); cmdOptions.addOption(LessOptions.CHARSET_OPTION, true, "Input file charset encoding. Defaults to UTF-8."); cmdOptions.addOption(LessOptions.COMPRESS_OPTION, false, "Flag that enables compressed CSS output."); cmdOptions.addOption(LessOptions.CSS_OPTION, false, "Flag that enables compilation of .css files."); cmdOptions.addOption(LessOptions.LESS_OPTION, true, "Path to a custom less.js for Rhino version."); try {/*ww w.j a va2s . co m*/ CommandLineParser cmdParser = new GnuParser(); CommandLine cmdLine = cmdParser.parse(cmdOptions, args); LessOptions options = new LessOptions(); if (cmdLine.hasOption(LessOptions.CHARSET_OPTION)) { options.setCharset(cmdLine.getOptionValue(LessOptions.CHARSET_OPTION)); } if (cmdLine.hasOption(LessOptions.COMPRESS_OPTION)) { options.setCompress(true); } if (cmdLine.hasOption(LessOptions.CSS_OPTION)) { options.setCss(true); } if (cmdLine.hasOption(LessOptions.LESS_OPTION)) { options.setLess(new File(cmdLine.getOptionValue(LessOptions.LESS_OPTION)).toURI().toURL()); } LessEngine engine = new LessEngine(options); if (System.in.available() != 0) { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringWriter sw = new StringWriter(); char[] buffer = new char[1024]; int n = 0; while (-1 != (n = in.read(buffer))) { sw.write(buffer, 0, n); } String src = sw.toString(); if (!src.isEmpty()) { System.out.println(engine.compile(src, null, options.isCompress())); System.exit(0); } } String[] files = cmdLine.getArgs(); if (files.length == 1) { System.out.println(engine.compile(new File(files[0]), options.isCompress())); System.exit(0); } if (files.length == 2) { engine.compile(new File(files[0]), new File(files[1]), options.isCompress()); System.exit(0); } } catch (IOException ioe) { System.err.println("Error opening input file."); } catch (ParseException pe) { System.err.println("Error parsing arguments."); } String[] paths = LessEngine.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath() .split(File.separator); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar " + paths[paths.length - 1] + " input [output] [options]", cmdOptions); System.exit(1); }
From source file:com.floragunn.searchguard.tools.Hasher.java
public static void main(final String[] args) { final Options options = new Options(); final HelpFormatter formatter = new HelpFormatter(); options.addOption(//from www.j av a 2 s. c om Option.builder("p").argName("password").hasArg().desc("Cleartext password to hash").build()); options.addOption(Option.builder("env").argName("name environment variable").hasArg() .desc("name environment variable to read password from").build()); final CommandLineParser parser = new DefaultParser(); try { final CommandLine line = parser.parse(options, args); if (line.hasOption("p")) { System.out.println(hash(line.getOptionValue("p").getBytes("UTF-8"))); } else if (line.hasOption("env")) { final String pwd = System.getenv(line.getOptionValue("env")); if (pwd == null || pwd.isEmpty()) { throw new Exception("No environment variable '" + line.getOptionValue("env") + "' set"); } System.out.println(hash(pwd.getBytes("UTF-8"))); } else { final Console console = System.console(); if (console == null) { throw new Exception("Cannot allocate a console"); } final char[] passwd = console.readPassword("[%s]", "Password:"); System.out.println(hash(new String(passwd).getBytes("UTF-8"))); } } catch (final Exception exp) { System.err.println("Parsing failed. Reason: " + exp.getMessage()); formatter.printHelp("hasher.sh", options, true); System.exit(-1); } }
From source file:edu.mit.fss.tutorial.part4.ElementGUI.java
/** * The main method./* ww w . ja va 2 s . c o m*/ * * @param args the arguments * @throws RTIexception the RTI exception */ public static void main(String[] args) throws RTIexception { // Configure the logger and set it to display info messages. BasicConfigurator.configure(); logger.setLevel(Level.INFO); // Use an input dialog to request the element's name. String name = null; while (name == null || name.isEmpty()) { name = JOptionPane.showInputDialog("Enter element name:"); } // Create a MobileElement object instance. The "final" keyword allows // it to be referenced in the GUI thread below. final MobileElement element = new MobileElement(name, new Vector3D(0, 0, 0)); // Create an OnlineTutorialFederate object instance. The "final" // keyword allows it to be referenced in the GUI thread below. final OnlineTutorialFederate fed = new OnlineTutorialFederate(element); // Create the graphical user interface using the Event Dispatch Thread. try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { // Create a new ControlPanel object instance. ControlPanel controlPanel = new ControlPanel(); // Bind it to the element above. controlPanel.setBoundElement(element); // Add the control panel as an object change listener. fed.addObjectChangeListener(controlPanel); // Create a new frame to display the panel. Add the panel // as the content, pack it, and make it visible. JFrame frame = new JFrame(); frame.setContentPane(controlPanel); frame.pack(); frame.setVisible(true); // Add a new WindowAdapter object instance to exit the // federate when the window is closing. frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { fed.exit(); } }); } }); } catch (InvocationTargetException | InterruptedException e) { logger.error(e); } // Execute the federate. fed.execute(0, Long.MAX_VALUE, 1000); }
From source file:com.example.main.Main.java
/** * @param args/*from w w w . j a va2 s . c o m*/ */ public static void main(String[] args) throws Exception { 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 (webPort == null || webPort.isEmpty()) { webPort = "8082"; } Server server = new Server(Integer.valueOf(webPort)); WebAppContext root = new WebAppContext(); root.setContextPath("/"); root.setDescriptor(webappDirLocation + "/WEB-INF/web.xml"); root.setResourceBase(webappDirLocation); PersistenceManager.getInstance().getEntityManagerFactory(); // 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); try { JSONObject datos = new JSONObject(); datos.put("nombrePagina", "Competencias"); datos.put("urlPagina", "localHost:8082"); JSONObject datos2 = new JSONObject(); datos2.put("nombrePagina", "Competencias"); datos2.put("nuevoEstado", "Activo"); JSONObject datos3 = new JSONObject(); datos3.put("nombrePagina", "Competencias"); datos3.put("nombreServicio", "Competencias"); datos3.put("rutaServicio", "Competencias"); JSONObject datos4 = new JSONObject(); datos4.put("nombrePagina", "Competencias"); datos4.put("nombreServicio", "Ganadores"); datos4.put("rutaServicio", "Competencias/winners/{name}"); Client client = Client.create(); WebResource target = client.resource(SERVIDOR_ZK + "inscribirPagina"); target.post(JSONObject.class, datos); target = client.resource(SERVIDOR_ZK + "estadoPagina"); target.post(JSONObject.class, datos2); target = client.resource(SERVIDOR_ZK + "servicioPagina"); target.post(JSONObject.class, datos3); target = client.resource(SERVIDOR_ZK + "servicioPagina"); target.post(JSONObject.class, datos4); client.destroy(); } catch (Exception e) { e.printStackTrace(); } server.setHandler(root); server.start(); server.join(); }