Example usage for java.util.regex Pattern quote

List of usage examples for java.util.regex Pattern quote

Introduction

In this page you can find the example usage for java.util.regex Pattern quote.

Prototype

public static String quote(String s) 

Source Link

Document

Returns a literal pattern String for the specified String .

Usage

From source file:de.tarent.maven.plugins.pkg.AbstractMvnPkgPluginTestCase.java

protected boolean rpmDependsOn(String s) throws MojoExecutionException, IOException {
    final Pattern p = Pattern.compile(Pattern.quote(s) + ".*");
    return rpmContains(p, "-R");
}

From source file:com.thinkbiganalytics.nifi.rest.support.NifiProcessUtil.java

/**
 * Filters the specified list of process groups for ones matching the specified feed name, including versioned process groups.
 *
 * @param processGroups the list of process groups to filter
 * @param feedName      the feed system name to match, case-insensitive
 * @return the matching process groups/*  w w w. j  a  v a  2  s.  c om*/
 */
@Nonnull
public static Set<ProcessGroupDTO> findProcessGroupsByFeedName(
        @Nonnull final Collection<ProcessGroupDTO> processGroups, @Nonnull final String feedName) {
    Pattern pattern = Pattern.compile("^" + Pattern.quote(feedName) + "( - \\d+)?$", Pattern.CASE_INSENSITIVE);
    return processGroups.stream().filter(processGroup -> pattern.matcher(processGroup.getName()).matches())
            .collect(Collectors.toSet());
}

From source file:com.cloudbees.jenkins.plugins.gogs.GogsSCMSource.java

/**
 * Returns the pattern corresponding to the branches containing wildcards. 
 * /*from w w  w  .  j a v  a  2 s  .  co m*/
 * @param branches space separated list of expressions. 
 *        For example "*" which would match all branches and branch* would match branch1, branch2, etc.
 * @return pattern corresponding to the branches containing wildcards (ready to be used by {@link Pattern})
 */
private String getPattern(String branches) {
    StringBuilder quotedBranches = new StringBuilder();
    for (String wildcard : branches.split(" ")) {
        StringBuilder quotedBranch = new StringBuilder();
        for (String branch : wildcard.split("\\*")) {
            if (wildcard.startsWith("*") || quotedBranches.length() > 0) {
                quotedBranch.append(".*");
            }
            quotedBranch.append(Pattern.quote(branch));
        }
        if (wildcard.endsWith("*")) {
            quotedBranch.append(".*");
        }
        if (quotedBranches.length() > 0) {
            quotedBranches.append("|");
        }
        quotedBranches.append(quotedBranch);
    }
    return quotedBranches.toString();
}

From source file:eu.optimis.mi.monitoring_manager.resources.MonitorManagerQueryResourceHome.java

/**
 * Run getLatestComplete*Resource methods on multiple IPs.
 * /*w  ww .  j  a v a  2  s . c o  m*/
 * @param serviceId
 * @param methodName
 * @param parameters
 * @return MonitoringResourceDatasets
 */
@GET
@Path("/MultipleIPs/complete/{serviceId}/{methodName}/{parameters}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public MonitoringResourceDatasets getCompleteMultipleIPs(@PathParam("serviceId") String serviceId,
        @PathParam("methodName") String methodName, @PathParam("parameters") String parameters) {

    CloudOptimizerRESTClient co = new CloudOptimizerRESTClient();
    // Get list of VMs.
    List<String> vmsList = co.getVMsIdsOfService(serviceId);
    // Get list of physical node ids and list of IP addresses needed to call
    // the endpoints.
    HashMap<String, List<String>> map = getMultipleIpMap(vmsList);
    List<String> ipAddresses = map.get("ipAddresses");
    List<String> physicalIds = map.get("nodes");

    // Debug
    printList(vmsList, "vmsList");
    printList(ipAddresses, "ipAddresses");
    printList(physicalIds, "physicalIds");

    Client client = Client.create();

    MonitoringResourceDatasets returnedDataset = new MonitoringResourceDatasets();
    MonitoringResourceDatasets tempMRD = new MonitoringResourceDatasets();
    List<MonitoringResourceDataset> mrList = new ArrayList<MonitoringResourceDataset>();

    String paramArray[] = parameters.split(Pattern.quote("."));

    for (String ip : ipAddresses) {
        String url = this.getAddress(ip, methodName) + "/" + paramArray[0];
        WebResource service = client.resource(url);
        tempMRD = service.get(MonitoringResourceDatasets.class);
        mrList.addAll(tempMRD.getMonitoring_resource());
    }

    returnedDataset.setMonitoring_resource(mrList);
    return returnedDataset;
}

From source file:com.adobe.acs.commons.mcp.impl.processes.asset.UrlAssetImport.java

private Folder extractFolder(Map<String, CompositeVariant> assetData) {
    String folderPath = getTargetFolder(assetData);
    if (!folders.containsKey(folderPath)) {
        String rootFolder = folderPath.replace(jcrBasePath, "");
        String[] parts = rootFolder.split(Pattern.quote("/"));
        Folder parent = null;/*from  w w w  .j ava2s  .  com*/
        String currentPath = jcrBasePath;
        for (int i = 1; i < parts.length; i++) {
            String treePath = currentPath + "/" + parts[i];
            if (!folders.containsKey(treePath)) {
                Folder folder = parent == null ? new Folder(parts[i], jcrBasePath)
                        : new Folder(parts[i], parent);
                folders.put(treePath, folder);
                parent = folder;
            } else {
                parent = folders.get(treePath);
            }
            currentPath = treePath;
        }
    }
    return folders.get(folderPath);
}

From source file:com.googlecode.jmapper.util.GeneralUtility.java

/**
 * Replaces the variables present in the text and returns the result.<br>
 * @param text text to edit/*from w  w  w  . j av  a  2  s  .c  om*/
 * @param vars map with the string to replace as key and the respective value as value
 * @param prefix prefix
 * @return the text resultant
 */
private static String replace(String text, Map<String, String> vars, String prefix) {
    for (Entry<String, String> var : vars.entrySet())
        text = text.replaceAll(Pattern.quote(prefix + var.getKey()), Matcher.quoteReplacement(var.getValue()));

    return text;
}

From source file:de.tarent.maven.plugins.pkg.AbstractMvnPkgPluginTestCase.java

protected boolean rpmReleaseIs(String s) throws MojoExecutionException, IOException {
    final Pattern p = Pattern.compile("Release.*" + Pattern.quote(s) + ".*");
    return rpmContains(p, "-i");
}

From source file:com.ngdata.hbaseindexer.cli.AddOrUpdateIndexerCli.java

private Map<String, String> getConnectionParams(OptionSet options, Map<String, String> oldParams) {
    Map<String, String> connectionParams = Maps.newHashMap();
    if (oldParams != null) {
        connectionParams = Maps.newHashMap(oldParams);
    }// ww  w . j  a  va 2  s .c  o  m

    String oldSolrMode = connectionParams.get(SolrConnectionParams.MODE);
    if (oldSolrMode == null) {
        oldSolrMode = "cloud";
    }
    List<String> explicit = Lists.newArrayList();

    for (Pair<String, String> param : connectionParamOption.values(options)) {
        // An empty value indicates a request to remove the key
        if (param.getSecond().length() == 0) {
            connectionParams.remove(param.getFirst());
        } else {
            explicit.add(param.getFirst());
            if (!isValidConnectionParam(param.getFirst())) {
                System.err.println("WARNING: the following is not a recognized Solr connection parameter: "
                        + param.getFirst());
            }
            connectionParams.put(param.getFirst(), param.getSecond());
        }
    }

    String newSolrMode = connectionParams.get(SolrConnectionParams.MODE);
    if (newSolrMode == null) {
        newSolrMode = "cloud";
    }
    if (oldSolrMode.equals("cloud") && newSolrMode.equals("classic")) {
        // Switch from cloud to classic -- remove any cloud specific parameters
        removeUnlessExplicit(explicit, connectionParams, SolrConnectionParams.COLLECTION);
        removeUnlessExplicit(explicit, connectionParams, SolrConnectionParams.ZOOKEEPER);
    } else if (oldSolrMode.equals("classic") && newSolrMode.equals("cloud")) {
        // Switch from classic to cloud -- remove any cloud specific parameters
        removeUnlessExplicit(explicit, connectionParams, SolrConnectionParams.SHARDER_TYPE);
        removeUnlessExplicit(explicit, connectionParams, SolrConnectionParams.MAX_CONNECTIONS);
        removeUnlessExplicit(explicit, connectionParams, SolrConnectionParams.MAX_CONNECTIONS_PER_HOST);

        // remove any solr.shard.* parameter that wasn't set explicitly
        List<String> shardParams = Lists.newArrayList();
        Pattern pattern = Pattern.compile(Pattern.quote(SolrConnectionParams.SOLR_SHARD_PREFIX) + "\\d+");
        for (String param : connectionParams.keySet()) {
            if (pattern.matcher(param).matches()) {
                shardParams.add(param);
            }
        }
        for (String shardParam : shardParams) {
            removeUnlessExplicit(explicit, connectionParams, shardParam);
        }
    }

    //TODO
    // if we detect a switch from classic to cloud,
    // automatically clear solr zk param and solr collection param

    // Validate that the minimum required connection params are present
    if (!connectionParams.containsKey(SolrConnectionParams.MODE)
            || connectionParams.get(SolrConnectionParams.MODE).equals("cloud")) {
        // handle cloud params

        if (!connectionParams.containsKey(SolrConnectionParams.ZOOKEEPER)) {
            String solrZk = getZkConnectionString() + "/solr";
            System.err.println("WARNING: no -cp solr.zk specified, will use " + solrZk);
            connectionParams.put("solr.zk", solrZk);
        }

        if (!connectionParams.containsKey(SolrConnectionParams.COLLECTION)) {
            throw new CliException(
                    "ERROR: no -cp solr.collection=collectionName specified (this is required when solr.mode=cloud)");
        }

        // TODO: throw error if sharder type is specified or if shards are listed

    } else if (connectionParams.get(SolrConnectionParams.MODE).equals("classic")) {
        // handle classic params

        // Check that there is at least one shard, and that the shards are valid
        if (SolrConnectionParamUtil.getShards(connectionParams).size() == 0) {
            throw new CliException("ERROR: You need at least one shard when using solr classic");
        }

    } else {
        throw new CliException("ERROR: solr.mode should be 'cloud' or 'classic'. Invalid value: "
                + connectionParams.get(SolrConnectionParams.MODE));
    }

    return connectionParams;
}

From source file:unalcol.termites.boxplots.BestAgentsPercentageInfoCollected.java

private void AddDataFailingExperiments(String sDirectorio, ArrayList<Double> Pf, Hashtable<String, List> info) {
    File f = new File(sDirectorio);
    String extension;/*w w  w .  ja  v  a  2s.c om*/
    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) {
        List list = new ArrayList();
        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("failInfo")
                && 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 popsizef = Integer.valueOf(filenamep[3]);
            double pff = Double.valueOf(filenamep[5]);
            String modef = filenamep[7];

            int worldSize = Integer.valueOf(filenamep[11]) * Integer.valueOf(filenamep[13]);
            /*System.out.println("psizef:" + popsizef);
             System.out.println("pff:" + pff);
             System.out.println("modef:" + modef);
             */
            //              String[] aMode = {"turnoncontact", "lwsandc2", "lwsandc", "lwphevap2", "lwphevap"};
            try {
                sc = new Scanner(file);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(DataCollectedLatexConsolidatorSASOMessagesSend1.class.getName())
                        .log(Level.SEVERE, null, ex);
            }

            int agentId = -1;
            int countLines = 0;
            int roundNumber = -1;
            int infoCollected = -1;

            String[] data = null;
            while (sc.hasNext()) {
                String line = sc.nextLine();
                //System.out.println("line:" + line);
                data = line.split(",");
                agentId = Integer.valueOf(data[0]);
                roundNumber = Integer.valueOf(data[1]);

                if (infoCollected < Integer.valueOf(data[2])) {
                    infoCollected = Integer.valueOf(data[2]);
                }
                countLines++;
            }
            //System.out.println("lines" + countLines);
            if (countLines == popsizef && infoCollected != -1 && (Pf.contains(pff))) {
                double datas = ((infoCollected * 1.0) / worldSize) * 100.0;
                if (info.get(modef + "+" + popsizef) == null) {
                    info.put((modef + "+" + popsizef), new ArrayList<Integer>());
                }
                info.get(modef + "+" + popsizef).add(datas);
            }

            LOGGER.debug("Adding series " + i);
            LOGGER.debug(list.toString());
        }
    }

    System.out.println("info" + info);
}

From source file:cc.arduino.mvd.services.XivelyService.java

private String[] parsePayload(String json) throws JSONException {
    int start = json.indexOf("{");
    String jsonFixed = json.substring(start);
    JSONObject root = new JSONObject(jsonFixed);

    JSONArray datastreams = root.getJSONArray("datastreams");

    for (int i = 0; i < datastreams.length(); i++) {
        JSONObject datastream = datastreams.getJSONObject(i);
        String id = datastream.getString("id");
        final String re = Pattern.quote("+");
        String[] codepin = id.split(re);
        String code = codepin[0];
        String pin = codepin[1];//from  w  ww. jav a 2 s  . c o  m
        String value = datastream.getString("current_value");

        handleKeyValFromXively(code, pin, value);
    }

    return new String[] {};
}