List of usage examples for java.util.regex Pattern quote
public static String quote(String s)
From source file:com.genentech.chemistry.openEye.apps.SDFCatsIndexer.java
private void run(String inFile, String outFile, EnumSet<CATSIndexer.Normalization> normMeth) { oemolithread ifs = new oemolithread(inFile); oemolothread ofs = new oemolothread(outFile); long start = System.currentTimeMillis(); int iCounter = 0; //Structures in the SD file. OEMolBase mol = new OEGraphMol(); while (oechem.OEReadMolecule(ifs, mol)) { iCounter++;/*from w w w . ja va 2 s. c o m*/ indexer.compute2DCats(mol, normMeth); oechem.OEWriteMolecule(ofs, 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(); ofs.close(); ifs.close(); ofs.delete(); ifs.delete(); 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:org.jtalks.common.security.acl.sids.UserGroupSid.java
private String parseGroupId(String sidId) { String[] splitted = sidId.split(Pattern.quote(":")); if (splitted.length != 2) { throw new WrongFormatException(sidId); }/*from www . j av a2s. com*/ return splitted[1]; }
From source file:com.itude.mobile.android.util.StringUtil.java
/** * Strip the given {@link String} with the given character * /* w w w.j ava2 s .c om*/ * @param inputString {@link String} to be stripped * @param stripCharacter strip character * @return Stripped {@link String} */ public static String stripCharacter(String inputString, char stripCharacter) { return inputString.replaceAll(Pattern.quote(Character.toString(stripCharacter)), ""); }
From source file:org.mycontroller.standalone.exernalserver.model.ExternalServer.java
@JsonIgnore public String getVariableKey(SensorVariable sensorVariable, String keyFormat) { if (keyFormat == null) { keyFormat = DEFAULT_KEY_FORMAT;//from w w w . j a v a 2 s . c o m } keyFormat = keyFormat.replaceAll("$gatewayName", sensorVariable.getSensor().getNode().getGatewayTable().getName()); keyFormat = keyFormat.replaceAll(Pattern.quote("$nodeName"), sensorVariable.getSensor().getNode().getName()); keyFormat = keyFormat.replaceAll(Pattern.quote("$nodeEui"), sensorVariable.getSensor().getNode().getEui()); keyFormat = keyFormat.replaceAll(Pattern.quote("$sensorName"), sensorVariable.getSensor().getName()); keyFormat = keyFormat.replaceAll(Pattern.quote("$sensorId"), sensorVariable.getSensor().getSensorId()); keyFormat = keyFormat.replaceAll(Pattern.quote("$variableType"), sensorVariable.getVariableType().getText()); return keyFormat.replaceAll(" ", "_"); }
From source file:com.sillelien.dollar.api.types.DollarString.java
@NotNull @Override//ww w .j a v a2s .c o m public var $divide(@NotNull var rhs) { var rhsFix = rhs._fixDeep(); if (rhsFix.string() && !rhsFix.toString().isEmpty()) { try { // final Pattern pattern = Pattern.compile(rhsFix.toString(),Pattern.LITERAL); final String quote = Pattern.quote(rhsFix.toString()); final String[] split = value.split(quote); if (split.length == 1) { return this; } return DollarFactory.fromValue(Arrays.asList(split), errors(), rhsFix.errors()); } catch (PatternSyntaxException pse) { return failure(BAD_REGEX, pse, false); } } else if (rhsFix.number()) { if (rhsFix.toDouble() == 0.0) { return DollarFactory.infinity(true, errors(), rhsFix.errors()); } if (rhsFix.toDouble() > 0.0 && rhsFix.toDouble() < 1.0) { return $multiply(DollarFactory.fromValue(1.0 / rhsFix.toDouble(), rhs.errors())); } if (rhsFix.toDouble() < 0) { return this; } return DollarFactory.fromStringValue( value.substring(0, (int) ((double) value.length() / rhsFix.toDouble())), errors(), rhsFix.errors()); } else { return this; } }
From source file:ac.simons.oembed.DefaultOembedProvider.java
public URI toApiUrl(final String url) throws URISyntaxException { String uri = null;//from w w w .ja v a 2 s .c o m final List<NameValuePair> query = new ArrayList<>(); if (this.getEndpoint().toLowerCase().contains("%{format}")) uri = this.getEndpoint().replaceAll(Pattern.quote("%{format}"), this.getFormat()); else { uri = this.getEndpoint(); query.add(new BasicNameValuePair("format", this.getFormat())); } query.add(new BasicNameValuePair("url", url)); if (this.getMaxWidth() != null) query.add(new BasicNameValuePair("maxwidth", this.getMaxWidth().toString())); if (this.getMaxHeight() != null) query.add(new BasicNameValuePair("maxheight", this.getMaxHeight().toString())); return new URIBuilder(uri).addParameters(query).build(); }
From source file:com.topekalabs.java.utils.ClassUtils.java
public static Collection<File> getClassAndInnerClassFiles(File srcDirectory, String className) { notClassNameException(className);//from w w w. j a v a 2 s . c o m return FileUtils.listFiles(srcDirectory, new IOFileFilterRegexName(Pattern.quote(className) + "(\\$.+)?" + CLASS_FILE_SUFFIX_REGEX), TrueFileFilter.INSTANCE); }
From source file:com.blackducksoftware.integration.hub.detect.DetectInfoUtility.java
public int parseMajorVersion(String detectVersionText) { return Integer.parseInt(detectVersionText.split(Pattern.quote("."))[0]); }
From source file:net.sf.jabref.logic.util.io.FileUtil.java
/** * Creates the minimal unique path substring for each file among multiple file paths. * * @param paths the file paths/*from ww w. java 2s. c o m*/ * @return the minimal unique path substring for each file path */ public static List<String> uniquePathSubstrings(List<String> paths) { List<Stack<String>> stackList = new ArrayList<>(paths.size()); // prepare data structures for (String path : paths) { List<String> directories = Arrays.asList(path.split(Pattern.quote(File.separator))); Stack<String> stack = new Stack<>(); stack.addAll(directories); stackList.add(stack); } List<String> pathSubstrings = new ArrayList<>(Collections.nCopies(paths.size(), "")); // compute shortest folder substrings while (!stackList.stream().allMatch(Vector::isEmpty)) { for (int i = 0; i < stackList.size(); i++) { String tempString = pathSubstrings.get(i); if (tempString.isEmpty() && !stackList.get(i).isEmpty()) { pathSubstrings.set(i, stackList.get(i).pop()); } else if (!stackList.get(i).isEmpty()) { pathSubstrings.set(i, stackList.get(i).pop() + File.separator + tempString); } } for (int i = 0; i < stackList.size(); i++) { String tempString = pathSubstrings.get(i); if (Collections.frequency(pathSubstrings, tempString) == 1) { stackList.get(i).clear(); } } } return pathSubstrings; }
From source file:pl.betoncraft.betonquest.editor.model.PackageSet.java
public static PackageSet loadFromZip(ZipFile file) throws IOException, PackageNotFoundException { HashMap<String, HashMap<String, InputStream>> setMap = new HashMap<>(); Enumeration<? extends ZipEntry> entries = file.entries(); String setName = file.getName().substring(file.getName().lastIndexOf(File.separatorChar) + 1) .replace(".zip", ""); // extract correct entries from the zip file while (true) { try {//from w ww . j av a 2s. c o m ZipEntry entry = entries.nextElement(); String entryName = entry.getName(); // get the correct path separator (both can be used) char separator = (entryName.contains("/") ? '/' : '\\'); // index of first separator used to get set name int index = entryName.indexOf(separator); // skip entry if there are no path separators (files in zip root like license, readme etc.) if (index < 0) { continue; } if (!entryName.endsWith(".yml")) { continue; } String[] parts = entryName.split(Pattern.quote(String.valueOf(separator))); String ymlName = parts[parts.length - 1].substring(0, parts[parts.length - 1].length() - 4); StringBuilder builder = new StringBuilder(); int length = parts.length - 1; boolean conversation = false; if (parts[length - 1].equals("conversations")) { length--; conversation = true; } for (int i = 0; i < length; i++) { builder.append(parts[i] + '-'); } String packName = builder.substring(0, builder.length() - 1); HashMap<String, InputStream> packMap = setMap.get(packName); if (packMap == null) { packMap = new HashMap<>(); setMap.put(packName, packMap); } List<String> allowedNames = Arrays .asList(new String[] { "main", "events", "conditions", "objectives", "journal", "items" }); if (conversation) { packMap.put("conversations." + ymlName, file.getInputStream(entry)); } else { if (allowedNames.contains(ymlName)) { packMap.put(ymlName, file.getInputStream(entry)); } } } catch (NoSuchElementException e) { break; } } PackageSet set = parseStreams(setName, setMap); BetonQuestEditor.getInstance().getSets().add(set); RootController.setPackages(BetonQuestEditor.getInstance().getSets()); return set; }