List of usage examples for org.apache.commons.lang3 StringUtils isBlank
public static boolean isBlank(final CharSequence cs)
Checks if a CharSequence is whitespace, empty ("") or null.
StringUtils.isBlank(null) = true StringUtils.isBlank("") = true StringUtils.isBlank(" ") = true StringUtils.isBlank("bob") = false StringUtils.isBlank(" bob ") = false
From source file:de.thomasvolk.genexample.GenAlg.java
public static void main(String[] args) throws IOException, ParseException { System.out.println("Genetische Algorithmen"); Options options = new Options(); options.addOption(option("s", "Jede s Generation wird im Bericht ausgegeben")); options.addOption(option("w", "Quelldatei Wagon")); options.addOption(option("l", "Quelldatei Passagierliste")); options.addOption(option("d", "Zielverzeichnis Bericht")); options.addOption(option("a", "Algorithmus Typ " + Arrays.asList(AlgorithmusTyp.values()).toString())); options.addOption(option("g", "Anzahl der Generationen")); options.addOption(option("p", "Anzahl der Populationen")); options.addOption("h", false, "Hilfe"); CommandLineParser parser = new PosixParser(); try {/*w ww . j a v a2 s .com*/ CommandLine cmd = parser.parse(options, args); if (cmd.hasOption('h')) { printUsage(options); System.exit(0); } int generationen = getNummer(options, cmd.getOptionValue('g'), 2000); int populationen = getNummer(options, cmd.getOptionValue('p'), 20); int schritte = getNummer(options, cmd.getOptionValue('s'), 100); AlgorithmusTyp[] alg = AlgorithmusTyp.values(); if (cmd.hasOption('a')) { try { alg = new AlgorithmusTyp[] { AlgorithmusTyp.valueOf(cmd.getOptionValue('a')) }; } catch (IllegalArgumentException e) { printErrorAndExit(e, options); } } String reportDir = cmd.getOptionValue('d'); reportDir = StringUtils.isBlank(reportDir) ? "report" : reportDir; String wagonDatei = cmd.getOptionValue('w'); String passagierDatei = cmd.getOptionValue('l'); if (wagonDatei == null) { wagonDatei = erzeugeBeispielDatei("wagon.txt"); } if (passagierDatei == null) { passagierDatei = erzeugeBeispielDatei("passagiere.csv"); } System.out.println("Wagon Datein: " + wagonDatei); System.out.println("Passagier Datei: " + passagierDatei); System.out.println("Bericht: " + new File(reportDir).getAbsolutePath()); System.out.println("Anzahl Generationen: " + generationen); System.out.println("Anzahl Populationen: " + populationen); System.out.printf("Protokolliere jede %dte Generation im Bericht\n", schritte); WagonFactory wagonFactory = new WagonFactory(); PassagierFactory passagierFactory = new CSVPassagierFactory(); GenAlg genAlg = new GenAlg(wagonFactory, passagierFactory); genAlg.run(alg, passagierDatei, wagonDatei, reportDir, schritte, generationen, populationen); } catch (ParseException e) { printErrorAndExit(e, options); } }
From source file:com.sishuok.es.generate.Generate.java
public static void main(String[] args) throws Exception { // ========== ?? ==================== // ??????// w ww .ja va 2 s. c om // ?{packageName}/{moduleName}/{dao,entity,service,web}/{subModuleName}/{className} // packageName ????applicationContext.xmlsrping-mvc.xml?base-package?packagesToScan?4? String packageName = "com.sishuok.es"; String sysName = "sys"; // ??sys?showcase?maintain?personal?shop String moduleName = "xxs"; // ???? String tableName = "sys_xxs_attribute"; // user String className = "XxsAttribute"; // ??User String permissionName = "sys:xxsAttribute";//?????????? String folderName = "xxs";//?? String classAuthor = "xxs"; // ThinkGem String functionName = "??????"; // ?? // ??? //Boolean isEnable = false; Boolean isEnable = true; // ========== ?? ==================== if (!isEnable) { logger.error("????isEnable = true"); return; } if (StringUtils.isBlank(moduleName) || StringUtils.isBlank(moduleName) || StringUtils.isBlank(className) || StringUtils.isBlank(functionName)) { logger.error("??????????????"); return; } // ? String separator = File.separator; // ? File projectPath = new DefaultResourceLoader().getResource("").getFile(); while (!new File(projectPath.getPath() + separator + "src" + separator + "main").exists()) { projectPath = projectPath.getParentFile(); } logger.info("Project Path: {}", projectPath); // ? String tplPath = StringUtils.replace(projectPath + "/src/main/java/com/sishuok/es/generate/template", "/", separator); logger.info("Template Path: {}", tplPath); // Java String javaPath = StringUtils.replaceEach( projectPath + "/src/main/java/" + StringUtils.lowerCase(packageName), new String[] { "/", "." }, new String[] { separator, separator }); logger.info("Java Path: {}", javaPath); // String viewPath = StringUtils.replace(projectPath + "/src/main/webapp/WEB-INF/jsp/admin", "/", separator); logger.info("View Path: {}", viewPath); // ??? Configuration cfg = new Configuration(); cfg.setDefaultEncoding("UTF-8"); cfg.setDirectoryForTemplateLoading(new File(tplPath)); // ??? Map<String, String> model = Maps.newHashMap(); model.put("packageName", StringUtils.lowerCase(packageName)); // model.put("sysName", StringUtils.lowerCase(sysName)); //??? model.put("moduleName", StringUtils.lowerCase(moduleName)); //??? model.put("tableName", StringUtils.lowerCase(tableName)); // model.put("className", StringUtils.uncapitalize(className)); //??? model.put("permissionName", permissionName); //???? model.put("ClassName", StringUtils.capitalize(className)); //?? model.put("classAuthor", StringUtils.isNotBlank(classAuthor) ? classAuthor : "Generate Tools"); // model.put("classVersion", DateUtils.getDate()); // model.put("functionName", functionName); //??? model.put("folderName", folderName); //?? model.put("urlPrefix", model.get("moduleName") + "_" + model.get("className")); //jsp?? model.put("viewPrefix", //StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+ model.get("urlPrefix")); model.put("permissionPrefix", model.get("sysName") + ":" + model.get("moduleName")); //?? // ? Entity Template template = cfg.getTemplate("entity.ftl"); String content = FreeMarkers.renderTemplate(template, model); String filePath = javaPath + separator + model.get("sysName") + separator + model.get("moduleName") + separator + "entity" + separator + model.get("ClassName") + ".java"; System.out.println("Entity filePath" + filePath); writeFile(content, filePath); logger.info("Entity: {}", filePath); // ? Repository template = cfg.getTemplate("repository.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = javaPath + separator + model.get("sysName") + separator + model.get("moduleName") + separator + "repository" + separator + separator + model.get("ClassName") + "Repository.java"; System.out.println("repository filePath" + filePath); writeFile(content, filePath); logger.info("Dao: {}", filePath); // ? Service template = cfg.getTemplate("service.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = javaPath + separator + model.get("sysName") + separator + model.get("moduleName") + separator + "service" + separator + separator + model.get("ClassName") + "Service.java"; System.out.println("Service filePath" + filePath); writeFile(content, filePath); logger.info("Service: {}", filePath); // ? ??Controller template = cfg.getTemplate("frontController.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = javaPath + separator + model.get("sysName") + separator + model.get("moduleName") + separator + "web" + separator + "controller" + separator + "front" + separator + model.get("ClassName") + "Controller.java"; System.out.println("Controller filePath" + filePath); writeFile(content, filePath); logger.info("Controller: {}", filePath); // ? ??Controller template = cfg.getTemplate("adminController.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = javaPath + separator + model.get("sysName") + separator + model.get("moduleName") + separator + "web" + separator + "controller" + separator + "admin" + separator + model.get("ClassName") + "Controller.java"; System.out.println("Controller filePath" + filePath); writeFile(content, filePath); logger.info("Controller: {}", filePath); // ? editForm template = cfg.getTemplate("editForm.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = viewPath + separator + model.get("sysName") + separator + model.get("folderName") + separator + "editForm.jsp"; System.out.println("---------------------------------------------------"); System.out.println("ViewForm filePath" + filePath); writeFile(content, filePath); logger.info("ViewForm: {}", filePath); // ? list template = cfg.getTemplate("list.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = viewPath + separator + model.get("sysName") + separator + model.get("folderName") + separator + "list.jsp"; writeFile(content, filePath); System.out.println("ViewListfilePath" + filePath); logger.info("ViewList: {}", filePath); // ? searcheForm template = cfg.getTemplate("searchForm.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = viewPath + separator + model.get("sysName") + separator + model.get("folderName") + separator + "searchForm.jsp"; writeFile(content, filePath); System.out.println("searcheForm filePath" + filePath); logger.info("ViewList: {}", filePath); // ? listTable template = cfg.getTemplate("listTable.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = viewPath + separator + model.get("sysName") + separator + model.get("folderName") + separator + "listTable.jsp"; writeFile(content, filePath); System.out.println("listTable filePath" + filePath); logger.info("ViewList: {}", filePath); logger.info("Generate Success."); }
From source file:com.sccl.attech.generate.Generate.java
/** * The main method.//from w w w . j a v a 2s. co m * * @param args the arguments * @throws Exception the exception */ public static void main(String[] args) throws Exception { // ========== ?? ====================1412914 // ?????? // ?{packageName}/{moduleName}/{dao,entity,service,web}/{subModuleName}/{className} // packageName ????applicationContext.xmlsrping-mvc.xml?base-package?packagesToScan?4? String packageName = "com.sccl.attech.modules"; String moduleName = "mobil"; // ???sys String subModuleName = ""; // ????? String className = "updateApp"; // ??user List<GenerateField> fields = Lists.newArrayList(); fields.add(new GenerateField("name", "??")); fields.add(new GenerateField("type", "")); fields.add(new GenerateField("version", "")); fields.add(new GenerateField("path", "")); String classAuthor = "zzz"; // zhaozz String functionName = "App?"; // ?? // ??? //Boolean isEnable = false; Boolean isEnable = true; // ========== ?? ==================== if (!isEnable) { logger.error("????isEnable = true"); return; } if (StringUtils.isBlank(moduleName) || StringUtils.isBlank(moduleName) || StringUtils.isBlank(className) || StringUtils.isBlank(functionName)) { logger.error("??????????????"); return; } // ? String separator = File.separator; // ? File projectPath = new DefaultResourceLoader().getResource("").getFile(); while (!new File(projectPath.getPath() + separator + "src" + separator + "main").exists()) { projectPath = projectPath.getParentFile(); } logger.info("Project Path: {}", projectPath); // ? String tplPath = StringUtils.replace(projectPath + "/src/main/java/com/sccl/attech/generate/template", "/", separator); logger.info("Template Path: {}", tplPath); // Java String javaPath = StringUtils.replaceEach( projectPath + "/src/main/java/" + StringUtils.lowerCase(packageName), new String[] { "/", "." }, new String[] { separator, separator }); logger.info("Java Path: {}", javaPath); // String viewPath = StringUtils.replace(projectPath + "/WebRoot/pages", "/", separator); logger.info("View Path: {}", viewPath); String resPath = StringUtils.replace(projectPath + "/WebRoot/assets/js", "/", separator); logger.info("Res Path: {}", resPath); // ??? Configuration cfg = new Configuration(); cfg.setDefaultEncoding("UTF-8"); cfg.setDirectoryForTemplateLoading(new File(tplPath)); // ??? Map<String, Object> model = Maps.newHashMap(); model.put("packageName", StringUtils.lowerCase(packageName)); model.put("moduleName", StringUtils.lowerCase(moduleName)); model.put("fields", fields); model.put("subModuleName", StringUtils.isNotBlank(subModuleName) ? "." + StringUtils.lowerCase(subModuleName) : ""); model.put("className", StringUtils.uncapitalize(className)); model.put("ClassName", StringUtils.capitalize(className)); model.put("classAuthor", StringUtils.isNotBlank(classAuthor) ? classAuthor : "Generate Tools"); model.put("classVersion", DateUtils.getDate()); model.put("functionName", functionName); model.put("tableName", model.get("moduleName") + (StringUtils.isNotBlank(subModuleName) ? "_" + StringUtils.lowerCase(subModuleName) : "") + "_" + model.get("className")); model.put("urlPrefix", model.get("moduleName") + (StringUtils.isNotBlank(subModuleName) ? "/" + StringUtils.lowerCase(subModuleName) : "") + "/" + model.get("className")); model.put("viewPrefix", //StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+ model.get("urlPrefix")); model.put("permissionPrefix", model.get("moduleName") + (StringUtils.isNotBlank(subModuleName) ? ":" + StringUtils.lowerCase(subModuleName) : "") + ":" + model.get("className")); // ? Entity Template template = cfg.getTemplate("entity.ftl"); String content = FreeMarkers.renderTemplate(template, model); String filePath = javaPath + separator + model.get("moduleName") + separator + "entity" + separator + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + ".java"; writeFile(content, filePath); logger.info("Entity: {}", filePath); // ? Dao template = cfg.getTemplate("dao.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = javaPath + separator + model.get("moduleName") + separator + "dao" + separator + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + "Dao.java"; writeFile(content, filePath); logger.info("Dao: {}", filePath); // ? Service template = cfg.getTemplate("service.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = javaPath + separator + model.get("moduleName") + separator + "service" + separator + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + "Service.java"; writeFile(content, filePath); logger.info("Service: {}", filePath); // ? Controller createJavaFile(subModuleName, separator, javaPath, cfg, model); // ? ViewForm template = cfg.getTemplate("viewForm.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = viewPath//+separator+StringUtils.substringAfterLast(model.get("packageName"),".") + separator + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName) + separator + model.get("className") + "Form.html"; writeFile(content, filePath); logger.info("ViewForm: {}", filePath); // ? ViewFormJs template = cfg.getTemplate("viewFormJs.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = resPath//+separator+StringUtils.substringAfterLast(model.get("packageName"),".") + separator + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName) + separator + model.get("className") + "FormCtrl.js"; writeFile(content, filePath); logger.info("ViewFormJs: {}", filePath); // ? ViewList template = cfg.getTemplate("viewList.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = viewPath//+separator+StringUtils.substringAfterLast(model.get("packageName"),".") + separator + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName) + separator + model.get("className") + "List.html"; writeFile(content, filePath); logger.info("ViewList: {}", filePath); // ? ViewListJs template = cfg.getTemplate("viewListJs.ftl"); content = FreeMarkers.renderTemplate(template, model); filePath = resPath//+separator+StringUtils.substringAfterLast(model.get("packageName"),".") + separator + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName) + separator + model.get("className") + "ListCtrl.js"; writeFile(content, filePath); logger.info("ViewList: {}", filePath); // ? ??sql template = cfg.getTemplate("sql.ftl"); model.put("uid", IdGen.uuid()); model.put("uid1", IdGen.uuid()); content = FreeMarkers.renderTemplate(template, model); filePath = viewPath//+separator+StringUtils.substringAfterLast(model.get("packageName"),".") + separator + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName) + separator + model.get("className") + ".sql"; writeFile(content, filePath); logger.info("ViewList: {}", filePath); logger.info("Generate Success."); }
From source file:WriteIndex.java
/** * @param args/* ww w. jav a2 s. c o m*/ */ public static void main(String[] args) throws IOException { File docs = new File("documents"); File indexDir = new File(INDEX_DIRECTORY); Directory directory = FSDirectory.open(indexDir); Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_35); IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_35, analyzer); IndexWriter writer = new IndexWriter(directory, conf); writer.deleteAll(); for (File file : docs.listFiles()) { Metadata metadata = new Metadata(); ContentHandler handler = new BodyContentHandler(); ParseContext context = new ParseContext(); Parser parser = new AutoDetectParser(); InputStream stream = new FileInputStream(file); try { parser.parse(stream, handler, metadata, context); } catch (TikaException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } finally { stream.close(); } String text = handler.toString(); String fileName = file.getName(); Document doc = new Document(); doc.add(new Field("file", fileName, Store.YES, Index.NO)); for (String key : metadata.names()) { String name = key.toLowerCase(); String value = metadata.get(key); if (StringUtils.isBlank(value)) { continue; } if ("keywords".equalsIgnoreCase(key)) { for (String keyword : value.split(",?(\\s+)")) { doc.add(new Field(name, keyword, Store.YES, Index.NOT_ANALYZED)); } } else if ("title".equalsIgnoreCase(key)) { doc.add(new Field(name, value, Store.YES, Index.ANALYZED)); } else { doc.add(new Field(name, fileName, Store.YES, Index.NOT_ANALYZED)); } } doc.add(new Field("text", text, Store.NO, Index.ANALYZED)); writer.addDocument(doc); } writer.commit(); writer.deleteUnusedFiles(); System.out.println(writer.maxDoc() + " documents written"); }
From source file:com.bolingcavalry.StreamingJob.java
public static void main(String[] args) throws Exception { // ?/* w ww . j av a 2 s . c o m*/ final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); env.addSource(new WikipediaEditsSource()) //??key .keyBy((KeySelector<WikipediaEditEvent, String>) wikipediaEditEvent -> wikipediaEditEvent.getUser()) //?5 .timeWindow(Time.seconds(15)) //?key???? .aggregate( new AggregateFunction<WikipediaEditEvent, Tuple3<String, Integer, StringBuilder>, Tuple3<String, Integer, StringBuilder>>() { @Override public Tuple3<String, Integer, StringBuilder> createAccumulator() { //ACC return new Tuple3<>("", 0, new StringBuilder()); } @Override public Tuple3<String, Integer, StringBuilder> add(WikipediaEditEvent wikipediaEditEvent, Tuple3<String, Integer, StringBuilder> tuple3) { StringBuilder sbud = tuple3.f2; //?"Details "? //?? if (StringUtils.isBlank(sbud.toString())) { sbud.append("Details : "); } else { sbud.append(" "); } //?? return new Tuple3<>(wikipediaEditEvent.getUser(), wikipediaEditEvent.getByteDiff() + tuple3.f1, sbud.append(wikipediaEditEvent.getByteDiff())); } @Override public Tuple3<String, Integer, StringBuilder> getResult( Tuple3<String, Integer, StringBuilder> tuple3) { return tuple3; } @Override public Tuple3<String, Integer, StringBuilder> merge( Tuple3<String, Integer, StringBuilder> tuple3, Tuple3<String, Integer, StringBuilder> acc1) { //??? return new Tuple3<>(tuple3.f0, tuple3.f1 + acc1.f1, tuple3.f2.append(acc1.f2)); } }) //?????key??? .map((MapFunction<Tuple3<String, Integer, StringBuilder>, String>) tuple3 -> tuple3.toString()) //?STDOUT .print(); // env.execute("Flink Streaming Java API Skeleton"); }
From source file:com.sludev.mssqlapplylog.MSSQLApplyLogMain.java
public static void main(String[] args) { CommandLineParser parser = new DefaultParser(); Options options = new Options(); // Most of the following defaults should be changed in // the --conf or "conf.properties" file String sqlURL = null;//from w ww .jav a 2 s .c om String sqlUser = null; String sqlPass = null; String sqlDb = null; String sqlHost = "127.0.0.1"; String backupDirStr = null; String laterThanStr = ""; String fullBackupPathStr = null; String fullBackupPatternStr = "(?:[\\w_-]+?)(\\d+)\\.bak"; String fullBackupDatePatternStr = "yyyyMMddHHmm"; String sqlProcessUser = null; String logBackupPatternStr = "(.*)\\.trn"; String logBackupDatePatternStr = "yyyyMMddHHmmss"; boolean doFullRestore = false; Boolean useLogFileLastMode = null; Boolean monitorLogBackupDir = null; options.addOption(Option.builder().longOpt("conf").desc("Configuration file.").hasArg().build()); options.addOption(Option.builder().longOpt("laterthan").desc("'Later Than' file filter.").hasArg().build()); options.addOption(Option.builder().longOpt("restore-full") .desc("Restore the full backup before continuing.").build()); options.addOption(Option.builder().longOpt("use-lastmod") .desc("Sort/filter the log backups using their File-System 'Last Modified' date.").build()); options.addOption(Option.builder().longOpt("monitor-backup-dir") .desc("Monitor the backup directory for new log backups, and apply them.").build()); CommandLine line = null; try { try { line = parser.parse(options, args); } catch (ParseException ex) { throw new MSSQLApplyLogException(String.format("Error parsing command line.'%s'", ex.getMessage()), ex); } String confFile = null; // Process the command line arguments Iterator cmdI = line.iterator(); while (cmdI.hasNext()) { Option currOpt = (Option) cmdI.next(); String currOptName = currOpt.getLongOpt(); switch (currOptName) { case "conf": // Parse the configuration file confFile = currOpt.getValue(); break; case "laterthan": // "Later Than" file date filter laterThanStr = currOpt.getValue(); break; case "restore-full": // Do a full backup restore before restoring logs doFullRestore = true; break; case "monitor-backup-dir": // Monitor the backup directory for new logs monitorLogBackupDir = true; break; case "use-lastmod": // Use the last-modified date on Log Backup files for sorting/filtering useLogFileLastMode = true; break; } } Properties confProperties = null; if (StringUtils.isBlank(confFile) || Files.isReadable(Paths.get(confFile)) == false) { throw new MSSQLApplyLogException( "Missing or unreadable configuration file. Please specify --conf"); } else { // Process the conf.properties file confProperties = new Properties(); try { confProperties.load(Files.newBufferedReader(Paths.get(confFile))); } catch (IOException ex) { throw new MSSQLApplyLogException("Error loading properties file", ex); } sqlURL = confProperties.getProperty("sqlURL", ""); sqlUser = confProperties.getProperty("sqlUser", ""); sqlPass = confProperties.getProperty("sqlPass", ""); sqlDb = confProperties.getProperty("sqlDb", ""); sqlHost = confProperties.getProperty("sqlHost", ""); backupDirStr = confProperties.getProperty("backupDir", ""); if (StringUtils.isBlank(laterThanStr)) { laterThanStr = confProperties.getProperty("laterThan", ""); } fullBackupPathStr = confProperties.getProperty("fullBackupPath", fullBackupPathStr); fullBackupPatternStr = confProperties.getProperty("fullBackupPattern", fullBackupPatternStr); fullBackupDatePatternStr = confProperties.getProperty("fullBackupDatePattern", fullBackupDatePatternStr); sqlProcessUser = confProperties.getProperty("sqlProcessUser", ""); logBackupPatternStr = confProperties.getProperty("logBackupPattern", logBackupPatternStr); logBackupDatePatternStr = confProperties.getProperty("logBackupDatePattern", logBackupDatePatternStr); if (useLogFileLastMode == null) { String useLogFileLastModeStr = confProperties.getProperty("useLogFileLastMode", "false"); useLogFileLastMode = Boolean .valueOf(StringUtils.lowerCase(StringUtils.trim(useLogFileLastModeStr))); } if (monitorLogBackupDir == null) { String monitorBackupDirStr = confProperties.getProperty("monitorBackupDir", "false"); monitorLogBackupDir = Boolean .valueOf(StringUtils.lowerCase(StringUtils.trim(monitorBackupDirStr))); } } } catch (MSSQLApplyLogException ex) { try (StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw)) { pw.append(String.format("Error : '%s'\n\n", ex.getMessage())); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(pw, 80, "\njava -jar mssqlapplylog.jar ", "\nThe MSSQLApplyLog application can be used in a variety of options and modes.\n", options, 0, 2, " All Rights Reserved.", true); System.out.println(sw.toString()); } catch (IOException iex) { LOGGER.debug("Error processing usage", iex); } System.exit(1); } MSSQLApplyLogConfig config = MSSQLApplyLogConfig.from(backupDirStr, fullBackupPathStr, fullBackupDatePatternStr, laterThanStr, fullBackupPatternStr, logBackupPatternStr, logBackupDatePatternStr, sqlHost, sqlDb, sqlUser, sqlPass, sqlURL, sqlProcessUser, useLogFileLastMode, doFullRestore, monitorLogBackupDir); MSSQLApplyLog logProc = MSSQLApplyLog.from(config); BasicThreadFactory thFactory = new BasicThreadFactory.Builder().namingPattern("restoreThread-%d").build(); ExecutorService mainThreadExe = Executors.newSingleThreadExecutor(thFactory); Future<Integer> currRunTask = mainThreadExe.submit(logProc); mainThreadExe.shutdown(); Integer resp = 0; try { resp = currRunTask.get(); } catch (InterruptedException ex) { LOGGER.error("Application 'main' thread was interrupted", ex); } catch (ExecutionException ex) { LOGGER.error("Application 'main' thread execution error", ex); } finally { // If main leaves for any reason, shutdown all threads mainThreadExe.shutdownNow(); } System.exit(resp); }
From source file:SampleLang.java
/** * Check if the key is valid// ww w . ja v a2 s .c om * @param key license key value * @return true if key is valid, false otherwise. */ public static boolean checkLicenseKey(String key) { //checks if empty or null if (StringUtils.isBlank(key)) { return false; } //delete all white space key = StringUtils.deleteWhitespace(key); //Split String using the - separator String[] keySplit = StringUtils.split(key, "-"); //check lengths of whole and parts if (keySplit.length != 2 || keySplit[0].length() != 4 || keySplit[1].length() != 4) { return false; } //Check if first part is numeric if (!StringUtils.isNumeric(keySplit[0])) { return false; } //Check if second part contains only //the four characters 'J', 'A', 'V' and 'A' if (!StringUtils.containsOnly(keySplit[1], new char[] { 'J', 'A', 'V', 'A' })) { return false; } //Check if the fourth character //in the first part is a '0' if (StringUtils.indexOf(keySplit[0], '0') != 3) { return false; } //If all conditions are fulfilled, key is valid. return true; }
From source file:kenh.xscript.ScriptUtils.java
public static void main(String[] args) { String file = null;// w w w.j a va 2 s . c o m for (String arg : args) { if (StringUtils.startsWithAny(StringUtils.lowerCase(arg), "-f:", "-file:")) { file = StringUtils.substringAfter(arg, ":"); } } Element e = null; try { if (StringUtils.isBlank(file)) { JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("xScript"); chooser.setAcceptAllFileFilterUsed(false); chooser.setFileFilter(new FileFilter() { public boolean accept(File f) { if (f.isDirectory()) { return true; } else if (f.isFile() && StringUtils.endsWithIgnoreCase(f.getName(), ".xml")) { return true; } return false; } public String getDescription() { return "xScript (*.xml)"; } }); int returnVal = chooser.showOpenDialog(null); chooser.requestFocus(); if (returnVal == JFileChooser.CANCEL_OPTION) return; File f = chooser.getSelectedFile(); e = getInstance(f, null); } else { e = getInstance(new File(file), null); } //debug(e); //System.out.println("----------------------"); int result = e.invoke(); if (result == Element.EXCEPTION) { Object obj = e.getEnvironment().getVariable(Constant.VARIABLE_EXCEPTION); if (obj != null && obj instanceof Throwable) { System.err.println(); ((Throwable) obj).printStackTrace(); } else { System.err.println(); System.err.println("Unknown EXCEPTION is thrown."); } } } catch (Exception ex) { ex.printStackTrace(); System.err.println(); if (ex instanceof UnsupportedScriptException) { UnsupportedScriptException ex_ = (UnsupportedScriptException) ex; if (ex_.getElement() != null) { debug(ex_.getElement(), System.err); } } } finally { if (e != null) e.getEnvironment().callback(); } }
From source file:com.naver.divideandconquer.levenshtein.Levenshtein.java
private static int calculateDistance(String str1, String str2, int distance) { if (StringUtils.isBlank(str1) && StringUtils.isBlank(str2)) { return distance; }/*from w w w . j a v a 2 s . co m*/ if (StringUtils.isBlank(str1)) { return distance + str2.length(); } if (StringUtils.isBlank(str2)) { return distance + str1.length(); } boolean isEqualEndChar = str1.charAt(str1.length() - 1) == str2.charAt(str2.length() - 1); if (isEqualEndChar) { return calculateDistance(str1.substring(0, str1.length() - 1), str2.substring(0, str2.length() - 1), distance); } else { int case1 = calculateDistance(str1.substring(0, str1.length() - 1), str2.substring(0, str2.length() - 1), distance + 1); int case2 = calculateDistance(str1, str2.substring(0, str2.length() - 1), distance + 1); int case3 = calculateDistance(str1.substring(0, str1.length() - 1), str2, distance + 1); return NumberUtils.min(case1, case2, case3); } }
From source file:ext.sns.service.ProviderType.java
public static boolean validateType(String type) { if (StringUtils.isBlank(type)) { return false; }//from w ww. ja va 2 s . c o m if (type.equals(SNS) || type.equals(LOGIN)) { return true; } else { return false; } }