List of usage examples for java.util.regex Pattern quote
public static String quote(String s)
From source file:net.landora.anidb.mylist.ListReader.java
private String getString(String name) { String value = values.get(name); if (value == null) { return null; }/*from ww w .jav a 2 s .co m*/ return value.replaceAll(Pattern.quote("<br />"), "\n"); }
From source file:unalcol.termites.boxplots.RoundNumberGlobal.java
/** * Creates a sample dataset./* www.j av a 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-30-mazeoff"; File f = new File(experimentsDir); 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<>(); Hashtable<String, List> info = new Hashtable(); //String[] aMode = {"levywalk", "lwphevap", "hybrid", "hybrid3", "hybrid4"}; for (String mode : aMode) { info.put(mode, 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("dataCollected")) { 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[3]); double pf = Double.valueOf(filenamep[5]); String mode = filenamep[7]; int maxIter = -1; //if (!filenamep[8].isEmpty()) { maxIter = Integer.valueOf(filenamep[9]); //} 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 = {"levywalk", "lwphevap", "hybrid", "hybrid3", "hybrid4", "sequential"}; //String[] aMode = {"levywalk", "lwphevap", "hybrid", "sequential"}; 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 roundNumber = 0; double globalInfoCollected = 0; String[] data = null; while (sc.hasNext()) { String line = sc.nextLine(); data = line.split(","); //System.out.println("data"); roundNumber = Integer.valueOf(data[0]); globalInfoCollected = Double.valueOf(data[4]); if (globalInfoCollected >= 90 && Pf.contains(pf)) { info.get(mode).add(roundNumber); break; } } 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 (String key : info.keySet()) { System.out.println(key + ":" + info.get(key).size() / 30 * 100.0); dataset.add(info.get(key), 10, getTechniqueName(key)); } return dataset; }
From source file:unalcol.termites.boxplots.BestAgentsRoundInfoCollected.java
/** * Creates a sample dataset.// w ww.j av a2 s .com * * @return A sample dataset. */ private void createSampleDataset(ArrayList<Double> Pf, Hashtable<String, List> info) { String sDirectorio = experimentsDir; File f = new File(sDirectorio); String extension; File[] files = f.listFiles(); Hashtable<String, String> Pop = new Hashtable<>(); Scanner sc = null; ArrayList<Integer> aPops = new ArrayList<>(); ArrayList<Double> aPf = new ArrayList<>(); ArrayList<String> aTech = new ArrayList<>(); 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") && file.getName().contains(mazeMode)) { //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 = {"sandclw", "lwsandc2", "lwsandc", "lwphevap2", "lwphevap"}; //String[] aMode = {"levywalk", "lwphevap", "hybrid", "hybrid3", "hybrid4", "sequential"}; // String[] aMode = {"turnoncontact", "lwsandc2", "lwsandc", "lwphevap2", "lwphevap"}; 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); if (agentsCorrect > 0 && Pf.contains(pf)) { if (info.get(mode + "+" + popsize) == null) { info.put((mode + "+" + popsize), new ArrayList<Integer>()); } info.get(mode + "+" + popsize).add(bestRoundNumber); //System.out.println("add" + bestRoundNumber + ", mode" + mode); //list.add(new Double(averageExplored / (double) worldSize * 100)); } } } } } System.out.println("info init" + info); }
From source file:ee.ria.xroad.opmonitordaemon.HealthDataMetricsUtil.java
/** * @param metricName an metric name where the service ID part has been * escaped using escapeServiceId()./*from w ww .j a v a2 s . c o m*/ * @return the quoted metric name suitable for passing to a regular * expression matcher method */ static String formatMetricMatchRegexp(String metricName) { return String.format("^%s$", Pattern.quote(metricName)); }
From source file:com.moss.appsnap.keeper.freedesktop.FreeDesktopAppHandler.java
public static void removeFromApplicationsMenu(String fileName, File scriptLocation, FreeDesktopLayoutMap fsMap) throws IOException { final Log log = LogFactory.getLog(FreeDesktopAppHandler.class); String appsMenu;//from w ww .j a va 2s.c o m if (fsMap.customAppsMenuPath.exists()) { appsMenu = read(new FileReader(fsMap.customAppsMenuPath)).toString(); } else { appsMenu = read( new InputStreamReader(FreeDesktopAppHandler.class.getResourceAsStream("applications.menu"))) .toString(); } final File desktopFile = new File(fsMap.dotLocalShareAppsDir, fileName + ".desktop"); final String entry = applicationsFileEntry(desktopFile); final String pattern = Pattern.quote(entry); log.info("Searching for \n" + entry + "\n\n using \n" + pattern); appsMenu = appsMenu.replaceAll(pattern, ""); write(appsMenu, fsMap.customAppsMenuPath); }
From source file:com.mirth.connect.plugins.datatypes.hl7v2.HL7v2AutoResponder.java
private Response generateACK(Status status, String hl7Message, HL7v2ResponseGenerationProperties hl7v2Properties) throws Exception { boolean errorOnly = false; boolean always = false; boolean successOnly = false; hl7Message = hl7Message.trim();// w w w . j av a 2 s.c o m boolean isXML = StringUtils.isNotBlank(hl7Message) && hl7Message.charAt(0) == '<'; String ACK = null; String statusMessage = null; String error = null; try { if (serializationProperties.isConvertLineBreaks() && !isXML) { hl7Message = StringUtil.convertLineBreaks(hl7Message, serializationSegmentDelimiter); } // Check if we have to look at MSH15 if (hl7v2Properties.isMsh15ACKAccept()) { // MSH15 Dictionary: // AL: Always // NE: Never // ER: Error / Reject condition // SU: Successful completion only String msh15 = ""; // Check if the message is ER7 or XML if (isXML) { // XML form XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression msh15Query = xpath.compile("//MSH.15/text()"); DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = domFactory.newDocumentBuilder(); Reader reader = new CharArrayReader(hl7Message.toCharArray()); Document doc = builder.parse(new InputSource(reader)); msh15 = msh15Query.evaluate(doc); } else { // ER7 char fieldDelim = hl7Message.charAt(3); // Usually | char componentDelim = hl7Message.charAt(4); // Usually ^ Pattern fieldPattern = Pattern.compile(Pattern.quote(String.valueOf(fieldDelim))); Pattern componentPattern = Pattern.compile(Pattern.quote(String.valueOf(componentDelim))); String mshString = StringUtils.split(hl7Message, serializationSegmentDelimiter)[0]; String[] mshFields = fieldPattern.split(mshString); if (mshFields.length > 14) { msh15 = componentPattern.split(mshFields[14])[0]; // MSH.15.1 } } if (msh15 != null && !msh15.equals("")) { if (msh15.equalsIgnoreCase("AL")) { always = true; } else if (msh15.equalsIgnoreCase("NE")) { logger.debug("MSH15 is NE, Skipping ACK"); return null; } else if (msh15.equalsIgnoreCase("ER")) { errorOnly = true; } else if (msh15.equalsIgnoreCase("SU")) { successOnly = true; } } } String ackCode = "AA"; String ackMessage = ""; boolean nack = false; if (status == Status.ERROR) { if (successOnly) { // we only send an ACK on success return null; } ackCode = hl7v2Properties.getErrorACKCode(); ackMessage = hl7v2Properties.getErrorACKMessage(); nack = true; } else if (status == Status.FILTERED) { if (successOnly) { return null; } ackCode = hl7v2Properties.getRejectedACKCode(); ackMessage = hl7v2Properties.getRejectedACKMessage(); nack = true; } else { if (errorOnly) { return null; } ackCode = hl7v2Properties.getSuccessfulACKCode(); ackMessage = hl7v2Properties.getSuccessfulACKMessage(); } ACK = HL7v2ACKGenerator.generateAckResponse(hl7Message, isXML, ackCode, ackMessage, generationProperties.getDateFormat(), new String(), deserializationSegmentDelimiter); statusMessage = "HL7v2 " + (nack ? "N" : "") + "ACK successfully generated."; logger.debug("HL7v2 " + (nack ? "N" : "") + "ACK successfully generated: " + ACK); } catch (Exception e) { logger.warn("Error generating HL7v2 ACK.", e); throw new Exception("Error generating HL7v2 ACK.", e); } return new Response(status, ACK, statusMessage, error); }
From source file:br.com.diegosilva.jsfcomponents.util.Utils.java
public static String removeMacros(String string) { if (string == null) return null; String REGEX_MACRO = Pattern.quote("[") + "<=[a-z]{1}?[a-zA-Z0-9]+?" + Pattern.quote("]"); return string.replaceAll(REGEX_MACRO, ""); }
From source file:com.spotify.docker.client.CompressedDirectory.java
@VisibleForTesting static PathMatcher goPathMatcher(FileSystem fs, String pattern) { // Supposed to work the same way as Go's path.filepath.match.Match: // http://golang.org/src/path/filepath/match.go#L34 final String notSeparatorPattern = getNotSeparatorPattern(fs.getSeparator()); final String starPattern = String.format("%s*", notSeparatorPattern); final StringBuilder patternBuilder = new StringBuilder(); boolean inCharRange = false; boolean inEscape = false; // This is of course hugely inefficient, but it passes most of the test suite, TDD ftw... for (int i = 0; i < pattern.length(); i++) { final char c = pattern.charAt(i); if (inCharRange) { if (inEscape) { patternBuilder.append(c); inEscape = false;//from ww w . jav a 2 s . co m } else { switch (c) { case '\\': patternBuilder.append('\\'); inEscape = true; break; case ']': patternBuilder.append(']'); inCharRange = false; break; default: patternBuilder.append(c); } } } else { if (inEscape) { patternBuilder.append(Pattern.quote(Character.toString(c))); inEscape = false; } else { switch (c) { case '*': patternBuilder.append(starPattern); break; case '?': patternBuilder.append(notSeparatorPattern); break; case '[': patternBuilder.append("["); inCharRange = true; break; case '\\': inEscape = true; break; default: patternBuilder.append(Pattern.quote(Character.toString(c))); } } } } return fs.getPathMatcher("regex:" + patternBuilder.toString()); }
From source file:com.adobe.acs.commons.data.Spreadsheet.java
@SuppressWarnings("squid:S3776") private Optional<Map<String, CompositeVariant>> buildRow(Row row) { Map<String, CompositeVariant> out = new LinkedHashMap<>(); out.put(ROW_NUMBER, new CompositeVariant(row.getRowNum())); List<Variant> data = readRow(row); boolean empty = true; for (int i = 0; i < data.size() && i < getHeaderRow().size(); i++) { String colName = getHeaderRow().get(i); if (data.get(i) != null && !data.get(i).isEmpty()) { empty = false;/* w ww .j a v a2 s.c o m*/ if (!out.containsKey(colName)) { out.put(colName, new CompositeVariant(headerTypes.get(colName))); } if (headerTypes.get(colName).isArray()) { String[] values = data.get(i).toString() .split(Pattern.quote(delimiters.getOrDefault(colName, DEFAULT_DELIMITER))); for (String value : values) { if (value != null && !value.isEmpty()) { out.get(colName).addValue(value.trim()); } } } else { out.get(colName).addValue(data.get(i)); } } } if (empty || (!requiredColumns.isEmpty() && !out.keySet().containsAll(requiredColumns))) { return Optional.empty(); } else { return Optional.of(out); } }
From source file:com.bluexml.tools.miscellaneous.PrepareSIDEModulesMigration.java
private static void executeInpath(boolean inplace, String frameworkmodulesPath, String classifier_base, String version_base, String classifier_target, String version_target, String frameworkmodulesInplace, File workspaceFile, final String versionInProjectName, String versionInProjectName2) { File frameworkmodulesPathFile = new File(frameworkmodulesPath); if (inplace) { frameworkmodulesPathFile = new File(frameworkmodulesInplace); Collection<?> listFiles = FileUtils.listFiles(frameworkmodulesPathFile, TrueFileFilter.INSTANCE, new IOFileFilter() { public boolean accept(File dir, String name) { return !name.equals(".svn"); }/*from w w w . j a v a 2 s. c o m*/ public boolean accept(File file) { return !file.getName().equals(".svn"); } }); for (Object object : listFiles) { File f = (File) object; // System.out.println("PrepareSIDEModulesMigration.main() file :" + f); replaceVersionInFile(versionInProjectName, versionInProjectName2, version_base, classifier_base, version_target, classifier_target, f, true); } } else if (frameworkmodulesPathFile.exists()) { // copy resource // get project to copy File[] listFilesT = frameworkmodulesPathFile.listFiles(); System.out.println("PrepareSIDEModulesMigration.main() all :" + listFilesT.length); File[] listFiles = frameworkmodulesPathFile.listFiles(new FileFilter() { public boolean accept(File file) { if (file.isDirectory()) { String pat = versionInProjectName; pat = ".*" + Pattern.quote(pat) + ".*"; boolean matches = file.getName().matches(pat); System.out.println("accept() file" + file.getName() + " pattern :" + pat + " ?" + matches); return matches; } System.out .println("PrepareSIDEModulesMigration.main(...).new FileFilter() {...}.accept() FALSE"); return false; } }); System.out.println("PrepareSIDEModulesMigration.main() to copy : " + listFiles.length); for (File srcDir : listFiles) { System.out.println("PrepareSIDEModulesMigration.main() copy dir :" + srcDir); File copyDir = copyDir(workspaceFile, srcDir); reNameResources(versionInProjectName, copyDir, versionInProjectName2, version_base, classifier_base, version_target, classifier_target); } } else { System.err.println("frameworkmodulesPathFile do not exists :" + frameworkmodulesPathFile); } }