List of usage examples for java.util.regex Pattern quote
public static String quote(String s)
From source file:unalcol.termites.boxplots.SucessfulRatesHybrid.java
private static CategoryDataset createDataset(ArrayList<Double> Pf) { DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset(); String sDirectorio = ".\\experiments\\2015-10-14-Maze\\results"; File f = new File(sDirectorio); String extension;/*from ww w . j av a 2s .c o m*/ File[] files = f.listFiles(); Hashtable<String, String> Pop = new Hashtable<>(); PrintWriter escribir; Scanner sc = null; double sucessfulExp = 0.0; for (File file : files) { extension = ""; int i = file.getName().lastIndexOf('.'); int p = Math.max(file.getName().lastIndexOf('/'), file.getName().lastIndexOf('\\')); if (i > p) { extension = file.getName().substring(i + 1); } // System.out.println(file.getName() + "extension" + extension); if (file.isFile() && extension.equals("csv") && file.getName().startsWith("experiment")) { System.out.println(file.getName()); System.out.println("get: " + file.getName()); String[] filenamep = file.getName().split(Pattern.quote("+")); System.out.println("file" + filenamep[8]); int popsize = Integer.valueOf(filenamep[2]); double pf = Double.valueOf(filenamep[4]); String mode = filenamep[6]; int maxIter = -1; //if (!filenamep[8].isEmpty()) { maxIter = Integer.valueOf(filenamep[8]); //} int n = 0; int rho = 0; double evapRate = 0.0; //14, 16, 16 if (mode.equals("hybrid")) { n = Integer.valueOf(filenamep[14]); rho = Integer.valueOf(filenamep[16]); String[] tmp = filenamep[18].split(Pattern.quote(".")); System.out.println("history size:" + n); System.out.println("rho:" + rho); String sEvap = tmp[0] + "." + tmp[1]; evapRate = Double.valueOf(sEvap); } System.out.println("psize:" + popsize); System.out.println("pf:" + pf); System.out.println("mode:" + mode); System.out.println("maxIter:" + maxIter); //String[] aMode = {"random", "levywalk", "sandc", "sandclw"}; //String[] aMode = {"lwphclwevap", "lwsandc2", "lwsandc", "lwphevap2", "lwphevap"}; String[] aMode = { "hybrid", "lwphevap" }; if (isInMode(aMode, mode)) { final List list = new ArrayList(); try { sc = new Scanner(file); } catch (FileNotFoundException ex) { Logger.getLogger(DataCollectedLatexConsolidatorSASOMessagesSend1.class.getName()) .log(Level.SEVERE, null, ex); } int agentsCorrect = 0; int worldSize = 0; double averageExplored = 0.0; int bestRoundNumber = 0; double avgSend = 0; double avgRecv = 0; double avgdataExplInd = 0; ArrayList<Double> acSt = new ArrayList<>(); ArrayList<Double> avgExp = new ArrayList<>(); ArrayList<Double> bestR = new ArrayList<>(); ArrayList<Double> avSnd = new ArrayList<>(); ArrayList<Double> avRecv = new ArrayList<>(); ArrayList<Double> avIndExpl = new ArrayList<>(); String[] data = null; while (sc.hasNext()) { String line = sc.nextLine(); //System.out.println("line:" + line); data = line.split(","); agentsCorrect = Integer.valueOf(data[0]); //agentsIncorrect = Integer.valueOf(data[1]); // not used worldSize = Integer.valueOf(data[3]); averageExplored = Double.valueOf(data[4]); // data[3] stdavgExplored - not used bestRoundNumber = Integer.valueOf(data[6]); avgSend = Double.valueOf(data[7]); avgRecv = Double.valueOf(data[8]); avgdataExplInd = Double.valueOf(data[11]); //Add Data and generate statistics acSt.add((double) agentsCorrect); avgExp.add(averageExplored); avSnd.add(avgSend); avRecv.add(avgRecv); avIndExpl.add(avgdataExplInd); sucessfulExp = 0.0; for (int j = 0; j < acSt.size(); j++) { if (acSt.get(j) > 0) { sucessfulExp++; } } } if (Pf.contains(pf)) { if (mode.equals("hybrid")) { String nameSeries = n + "-" + rho + "-" + evapRate; defaultcategorydataset.addValue(((double) sucessfulExp) / acSt.size() * 100.0, "" + popsize, nameSeries); } else { defaultcategorydataset.addValue(((double) sucessfulExp) / acSt.size() * 100.0, "" + popsize, getTechniqueName(mode) + "\nPf:" + pf); } /*pf == 1.0E-4 || pf == 3.0E-4*/ } } } } return defaultcategorydataset; }
From source file:com.celements.web.plugin.cmd.SuggestListCommand.java
String getSeparatedInput(String input, String sep, Boolean isMultiSelect) { if (isMultiSelect && (sep != null) && !"".equals(sep)) { String[] inputWords = input.split(Pattern.quote(sep)); System.out.println(inputWords.length); input = inputWords[inputWords.length - 1].trim(); }/*w w w.ja va2 s. com*/ return input; }
From source file:com.haulmont.cuba.core.sys.dbupdate.ScriptScanner.java
public List<String> getModuleDirs() { try {/*from ww w. j a va 2 s .c o m*/ Resource[] resources = createAppropriateResourceResolver() .getResources(dbScriptsDirectoryForSearch() + "/**/*.*"); String dbDirPath = dbScriptDirectoryPath(); log.trace("DB scripts directory: {}", dbDirPath); List<String> modules = Arrays.stream(resources).map(resource -> { try { String decodedUrl = URLEncodeUtils.decodeUtf8(resource.getURL().toString()); String resourcePath = decodedUrl.replaceFirst(".+?:", ""); Matcher matcher = Pattern.compile(".*" + Pattern.quote(dbDirPath) + "/?(.+?)/.*") .matcher(resourcePath); return matcher.find() ? matcher.group(1) : null; } catch (IOException e) { throw new RuntimeException("An error occurred while detecting modules", e); } }).filter(element -> element != null).collect(Collectors.toSet()).stream().sorted() .collect(Collectors.toList()); if (modules.isEmpty()) { throw new RuntimeException(String.format( "No existing modules found. " + "Please check if [%s] contains DB scripts.", dbDirPath)); } log.trace("Found modules: {}", modules); return modules; } catch (IOException e) { throw new RuntimeException("An error occurred while detecting modules", e); } }
From source file:de.unidue.inf.is.ezdl.gframedl.utils.HighlightingUtils.java
/** * Returns {@link Matcher} for highlighting. * /*from w w w .j a v a 2 s. c o m*/ * @param highlightStrings * @param escapeHighlightStrings * @param stringToHighlight * @param highlightOnlyWords * true, if only words should be highlighted * @return */ public static Matcher matcher(List<String> highlightStrings, boolean escapeHighlightStrings, String stringToHighlight, boolean highlightOnlyWords) { if (stringToHighlight == null || highlightStrings.isEmpty() || highlightStrings.size() == 1 && highlightStrings.get(0).isEmpty()) { return null; } String p = highlightOnlyWords ? "\\b(" : "("; for (int i = 0; i < highlightStrings.size(); i++) { String queryTerm = highlightStrings.get(i); if (escapeHighlightStrings) { p += Pattern.quote(queryTerm); } else { p += queryTerm; } if (i < highlightStrings.size() - 1) { p += "|"; } } p += highlightOnlyWords ? ")\\b" : ")"; Pattern pattern = Pattern.compile(p, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); Matcher matcher = pattern.matcher(stringToHighlight); return matcher; }
From source file:de.micromata.genome.util.text.TextSplitterUtils.java
/** * Parses the string tokens./*from www . java2 s . c om*/ * * @param text the text * @param tokens used as RegExp * @param escapeChar the escape char * @param returnDelimiter the return delimiter * @param returnUnescaped the return unescaped * @return the list */ public static List<String> parseStringTokens(String text, String[] tokens, char escapeChar, boolean returnDelimiter, boolean returnUnescaped) { Token[] tks = new Token[tokens.length]; for (int i = 0; i < tokens.length; ++i) { String p = tokens[i]; p = Pattern.quote(p); p = "^(" + p + ")(.*)"; tks[i] = new RegExpToken(i + 1, p); } List<TokenResult> tksr = parseStringTokens(text, tks, escapeChar, returnDelimiter, returnUnescaped); List<String> ret = new ArrayList<String>(); for (TokenResult tkr : tksr) { ret.add(tkr.getConsumed()); } return ret; }
From source file:edu.umass.cs.gnsclient.console.ConsoleBasedTest.java
/** * Test GUID creation and deletion//from w w w. ja v a 2 s . c om */ @Test public void testField() { String inCommands; String expectedOutput; inCommands = "field_create " + FIELD1 + "\n"; inCommands += "field_write " + FIELD1 + " " + VALUE1 + "\n"; inCommands += "field_read " + FIELD1 + "\n"; inCommands += "field_delete " + FIELD1 + "\n"; inCommands += "field_create " + FIELD1 + " zero\n"; inCommands += "field_read " + FIELD1 + "\n"; inCommands += "field_append " + FIELD1 + " one\n"; inCommands += "field_read " + FIELD1 + "\n"; inCommands += "field_set 1 " + FIELD1 + " two\n"; inCommands += "field_read " + FIELD1 + "\n"; inCommands += "field_clear " + FIELD1 + "\n"; inCommands += "field_read " + FIELD1 + "\n"; inCommands += "field_delete " + FIELD1 + "\n"; inCommands += "field_read " + FIELD1 + "\n"; inCommands += "field_write " + FIELD1 + " " + VALUE1 + "\n"; inCommands += "field_read " + FIELD1 + "\n"; inCommands += "field_write " + FIELD1 + " " + VALUE2 + "\n"; inCommands += "field_read " + FIELD1 + "\n"; inCommands += "field_delete " + FIELD1 + "\n"; expectedOutput = "New field " + FIELD1 + " created with value ''.*\n"; expectedOutput += "Value '" + VALUE1 + "' written to field " + FIELD1 + " for GUID .*\n"; expectedOutput += Pattern.quote("[\"" + VALUE1 + "\"]") + ".*\n"; expectedOutput += "Field " + FIELD1 + " removed from GUID .*\n"; expectedOutput += "New field " + FIELD1 + " created with value 'zero'.*\n"; expectedOutput += Pattern.quote("[\"zero\"]") + ".*\n"; expectedOutput += "Value 'one' appended to field " + FIELD1 + " for GUID .*\n"; expectedOutput += Pattern.quote("[\"zero\",\"one\"]") + ".*\n"; expectedOutput += "Value 'two' written at index 1 of field " + FIELD1 + " for GUID .*\n"; expectedOutput += Pattern.quote("[\"zero\",\"two\"]") + ".*\n"; expectedOutput += "Field " + FIELD1 + " cleared.*\n"; expectedOutput += Pattern.quote("[]") + ".*\n"; expectedOutput += "Field " + FIELD1 + " removed from GUID .*\n"; expectedOutput += Pattern.quote( "Failed to access GNS ( edu.umass.cs.gnsclient.exceptions.GnsException: General command failure: +GENERICEERROR+)") + ".*\n"; expectedOutput += "Value '" + VALUE1 + "' written to field " + FIELD1 + " for GUID .*\n"; expectedOutput += Pattern.quote("[\"" + VALUE1 + "\"]") + ".*\n"; expectedOutput += "Value '" + VALUE2 + "' written to field " + FIELD1 + " for GUID .*\n"; expectedOutput += Pattern.quote("[\"" + VALUE2 + "\"]") + ".*\n"; expectedOutput += "Field " + FIELD1 + " removed from GUID .*\n"; runCommandsInConsole(inCommands, expectedOutput, true, true); }
From source file:com.genentech.chemistry.openEye.apps.SDFTopologicalIndexer.java
private void run(String inFile) { oemolithread ifs = new oemolithread(inFile); long start = System.currentTimeMillis(); int iCounter = 0; //Structures in the SD file. OEMolBase mol = new OEGraphMol(); while (oechem.OEReadMolecule(ifs, mol)) { iCounter++;/*from www . ja v a 2 s . c o m*/ try { indexer.computeIndexes(mol); //System.err.println(OETools.molToCanSmi(mol, true)); if (doJ) oechem.OESetSDData(mol, "J", DataFormat.formatNumber(indexer.getBalabanJIndex(), "r3")); if (doJStar) oechem.OESetSDData(mol, "JStar", DataFormat.formatNumber(indexer.getBalabanJStarIndex(), "r3")); if (doJX) oechem.OESetSDData(mol, "JX", DataFormat.formatNumber(indexer.getBalabanJXIndex(), "r3")); if (doJXStar) oechem.OESetSDData(mol, "JXStar", DataFormat.formatNumber(indexer.getBalabanJXStarIndex(), "r3")); if (doJY) oechem.OESetSDData(mol, "JY", DataFormat.formatNumber(indexer.getBalabanJYIndex(), "r3")); if (doJYStar) oechem.OESetSDData(mol, "JYStar", DataFormat.formatNumber(indexer.getBalabanJYStarIndex(), "r3")); if (doWiener) oechem.OESetSDData(mol, "Wiener", Long.toString(indexer.getWienerIndex())); if (doZagreb) oechem.OESetSDData(mol, "Zagreb", Integer.toString(indexer.getZagrebIndex())); } catch (TimeoutException e) { System.err .println("Conmputing topological Index timeed out for: " + OETools.molToCanSmi(mol, true)); } catch (NumberFormatException e) { System.err.println("Conmputing topological Index caused NumberFormatException for: " + OETools.molToCanSmi(mol, true)); e.printStackTrace(System.err); } catch (OutOfMemoryError e) { System.err.println("Conmputing topological Index caused OutOfMemoryError for: " + OETools.molToCanSmi(mol, true)); throw e; } oechem.OEWriteMolecule(outputOEThread, mol); //Output "." to show that the program is running. if (iCounter % 100 == 0) System.err.print("."); if (iCounter % 4000 == 0) { System.err.printf(" %d %dsec\n", iCounter, (System.currentTimeMillis() - start) / 1000); } } mol.delete(); ifs.close(); inFile = inFile.replaceAll(".*" + Pattern.quote(File.separator), ""); System.err.printf("%s: Read %d structures from %s. in %d sec\n", MY_NAME, iCounter, inFile, (System.currentTimeMillis() - start) / 1000); }
From source file:unalcol.termites.boxplots.ECALinfoCollected.java
/** * Creates a sample dataset.// w w w . j ava2 s . c om * * @return A sample dataset. */ private BoxAndWhiskerCategoryDataset createSampleDataset(ArrayList<Double> Pf) { final int seriesCount = 5; final int categoryCount = 4; final int entityCount = 22; String sDirectorio = ".\\experiments\\ECAL CR"; File f = new File(sDirectorio); String extension; File[] files = f.listFiles(); Hashtable<String, String> Pop = new Hashtable<>(); PrintWriter escribir; Scanner sc = null; ArrayList<Integer> aPops = new ArrayList<>(); ArrayList<Double> aPf = new ArrayList<>(); ArrayList<String> aTech = new ArrayList<>(); final DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); for (File file : files) { extension = ""; int i = file.getName().lastIndexOf('.'); int p = Math.max(file.getName().lastIndexOf('/'), file.getName().lastIndexOf('\\')); if (i > p) { extension = file.getName().substring(i + 1); } // System.out.println(file.getName() + "extension" + extension); if (file.isFile() && extension.equals("csv") && file.getName().startsWith("experiment")) { System.out.println(file.getName()); System.out.println("get: " + file.getName()); String[] filenamep = file.getName().split(Pattern.quote("+")); System.out.println("file" + filenamep[8]); int popsize = Integer.valueOf(filenamep[2]); double pf = Double.valueOf(filenamep[4]); String mode = filenamep[6]; int maxIter = -1; //if (!filenamep[8].isEmpty()) { maxIter = Integer.valueOf(filenamep[8]); //} System.out.println("psize:" + popsize); System.out.println("pf:" + pf); System.out.println("mode:" + mode); System.out.println("maxIter:" + maxIter); String[] aMode = { "random", "levywalk", "sandc" }; if (/*Pf == pf && */isInMode(aMode, mode)) { final List list = new ArrayList(); try { sc = new Scanner(file); } catch (FileNotFoundException ex) { Logger.getLogger(DataCollectedLatexConsolidatorSASOMessagesSend1.class.getName()) .log(Level.SEVERE, null, ex); } int agentsCorrect = 0; int worldSize = 0; double averageExplored = 0.0; int bestRoundNumber = 0; double avgSend = 0; double avgRecv = 0; double avgdataExplInd = 0; ArrayList<Double> acSt = new ArrayList<>(); ArrayList<Double> avgExp = new ArrayList<>(); ArrayList<Double> bestR = new ArrayList<>(); ArrayList<Double> avSnd = new ArrayList<>(); ArrayList<Double> avRecv = new ArrayList<>(); ArrayList<Double> avIndExpl = new ArrayList<>(); String[] data = null; while (sc.hasNext()) { String line = sc.nextLine(); //System.out.println("line:" + line); data = line.split(","); agentsCorrect = Integer.valueOf(data[0]); //agentsIncorrect = Integer.valueOf(data[1]); // not used worldSize = Integer.valueOf(data[3]); averageExplored = Double.valueOf(data[4]); // data[3] stdavgExplored - not used bestRoundNumber = Integer.valueOf(data[6]); avgSend = Double.valueOf(data[7]); avgRecv = Double.valueOf(data[8]); avgdataExplInd = Double.valueOf(data[11]); //Add Data and generate statistics acSt.add((double) agentsCorrect); avgExp.add(averageExplored); avSnd.add(avgSend); avRecv.add(avgRecv); avIndExpl.add(avgdataExplInd); list.add(new Double(averageExplored / (double) worldSize * 100)); } LOGGER.debug("Adding series " + i); LOGGER.debug(list.toString()); if (Pf.contains(pf)) { /*pf == 1.0E-4 || pf == 3.0E-4*/ if (Pf.size() == 1) { dataset.add(list, popsize, getTechniqueName(mode)); } else { dataset.add(list, String.valueOf(popsize) + "-" + pf, getTechniqueName(mode)); } } } } } /*for (int i = 0; i < seriesCount; i++) { for (int j = 0; j < categoryCount; j++) { final List list = new ArrayList(); // add some values... for (int k = 0; k < entityCount; k++) { final double value1 = 10.0 + Math.random() * 3; list.add(new Double(value1)); final double value2 = 11.25 + Math.random(); // concentrate values in the middle list.add(new Double(value2)); } LOGGER.debug("Adding series " + i); LOGGER.debug(list.toString()); dataset.add(list, "Series " + i, " Type " + j); } }*/ return dataset; }
From source file:unalcol.termites.boxplots.HybridRoundNumberReport.java
/** * Creates a sample dataset./*from w ww.ja va 2 s. c o m*/ * * @return A sample dataset. */ private BoxAndWhiskerCategoryDataset createSampleDataset(ArrayList<Double> Pf) { final int seriesCount = 5; final int categoryCount = 4; final int entityCount = 22; String sDirectorio = ".\\experiments\\2015-10-07-Hybrid\\hybridres"; File f = new File(sDirectorio); String extension; File[] files = f.listFiles(); Hashtable<String, String> Pop = new Hashtable<>(); PrintWriter escribir; Scanner sc = null; ArrayList<Integer> aPops = new ArrayList<>(); ArrayList<Double> aPf = new ArrayList<>(); ArrayList<String> aTech = new ArrayList<>(); final DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); for (File file : files) { extension = ""; int i = file.getName().lastIndexOf('.'); int p = Math.max(file.getName().lastIndexOf('/'), file.getName().lastIndexOf('\\')); if (i > p) { extension = file.getName().substring(i + 1); } // System.out.println(file.getName() + "extension" + extension); if (file.isFile() && extension.equals("csv") && file.getName().startsWith("experiment")) { System.out.println(file.getName()); System.out.println("get: " + file.getName()); String[] filenamep = file.getName().split(Pattern.quote("+")); System.out.println("file" + filenamep[8]); int popsize = Integer.valueOf(filenamep[2]); double pf = Double.valueOf(filenamep[4]); String mode = filenamep[6]; int maxIter = -1; //if (!filenamep[8].isEmpty()) { maxIter = Integer.valueOf(filenamep[8]); //} int n = 0; int rho = 0; double evapRate = 0.0; //14, 16, 16 if (mode.equals("hybrid")) { n = Integer.valueOf(filenamep[14]); rho = Integer.valueOf(filenamep[16]); String[] tmp = filenamep[18].split(Pattern.quote(".")); System.out.println("history size:" + n); System.out.println("rho:" + rho); String sEvap = tmp[0] + "." + tmp[1]; evapRate = Double.valueOf(sEvap); } System.out.println("psize:" + popsize); System.out.println("pf:" + pf); System.out.println("mode:" + mode); System.out.println("maxIter:" + maxIter); System.out.println("evap:" + evapRate); String[] aMode = { "hybrid", "lwphevap" }; if (isInMode(aMode, mode)) { final List list = new ArrayList(); try { sc = new Scanner(file); } catch (FileNotFoundException ex) { Logger.getLogger(DataCollectedLatexConsolidatorSASOMessagesSend1.class.getName()) .log(Level.SEVERE, null, ex); } int agentsCorrect = 0; int worldSize = 0; double averageExplored = 0.0; int bestRoundNumber = 0; double avgSend = 0; double avgRecv = 0; double avgdataExplInd = 0; ArrayList<Double> acSt = new ArrayList<>(); ArrayList<Double> avgExp = new ArrayList<>(); ArrayList<Double> bestR = new ArrayList<>(); ArrayList<Double> avSnd = new ArrayList<>(); ArrayList<Double> avRecv = new ArrayList<>(); ArrayList<Double> avIndExpl = new ArrayList<>(); String[] data = null; while (sc.hasNext()) { String line = sc.nextLine(); //System.out.println("line:" + line); data = line.split(","); agentsCorrect = Integer.valueOf(data[0]); //agentsIncorrect = Integer.valueOf(data[1]); // not used worldSize = Integer.valueOf(data[3]); averageExplored = Double.valueOf(data[4]); // data[3] stdavgExplored - not used bestRoundNumber = Integer.valueOf(data[6]); avgSend = Double.valueOf(data[7]); avgRecv = Double.valueOf(data[8]); avgdataExplInd = Double.valueOf(data[11]); //Add Data and generate statistics acSt.add((double) agentsCorrect); avgExp.add(averageExplored); avSnd.add(avgSend); avRecv.add(avgRecv); avIndExpl.add(avgdataExplInd); if (bestRoundNumber != 0 && bestRoundNumber != -1) { list.add(new Double(bestRoundNumber)); } } LOGGER.debug("Adding series " + i); LOGGER.debug(list.toString()); if (Pf.contains(pf)) { /*pf == 1.0E-4 || pf == 3.0E-4*/ if (Pf.size() == 1) { if (mode.equals("hybrid")) { dataset.add(list, popsize, /*getTechniqueName(mode) + */ rho + "-" + evapRate + "-" + n); } else { dataset.add(list, popsize, getTechniqueName(mode)); } } else { if (mode.equals("hybrid")) { dataset.add(list, String.valueOf(popsize) + "-" + pf, /*getTechniqueName(mode) +*/ rho + "-" + evapRate + "-" + n); } else { dataset.add(list, String.valueOf(popsize) + "-" + pf, getTechniqueName(mode)); } } } } } } /*for (int i = 0; i < seriesCount; i++) { for (int j = 0; j < categoryCount; j++) { final List list = new ArrayList(); // add some values... for (int k = 0; k < entityCount; k++) { final double value1 = 10.0 + Math.random() * 3; list.add(new Double(value1)); final double value2 = 11.25 + Math.random(); // concentrate values in the middle list.add(new Double(value2)); } LOGGER.debug("Adding series " + i); LOGGER.debug(list.toString()); dataset.add(list, "Series " + i, " Type " + j); } }*/ return dataset; }