Example usage for java.lang String contains

List of usage examples for java.lang String contains

Introduction

In this page you can find the example usage for java.lang String contains.

Prototype

public boolean contains(CharSequence s) 

Source Link

Document

Returns true if and only if this string contains the specified sequence of char values.

Usage

From source file:Main.java

public static String getQueryPageUrl(String url, int inc) {
    if (url == null) {
        return null;
    }/*from  www .j  a  v  a  2 s  . c  o m*/
    if (!url.contains("nicovideo.jp/search/")) {
        return null;
    }
    String ret = null;
    Matcher matcher = pagePattern.matcher(url);
    if (matcher.find()) {
        String _u1 = matcher.group(1);
        String _p = matcher.group(2);
        String _u2 = matcher.group(3);
        int page = 1;
        try {
            page = Integer.parseInt(_p) + inc;
        } catch (NumberFormatException e) {
        }
        if (0 < page) {
            ret = _u1 + page + _u2;
        }
    } else {
        int page = 1 + inc;
        if (0 < page) {
            if (url.contains("?")) {
                ret = url + "&page=" + page;
            } else {
                ret = url + "?page=" + page;
            }
        }
    }
    return ret;
}

From source file:Main.java

/**
 * Extracts dynamic namespaces that are inline inside a XPath expression. Example:
 * <code>/{http://sample.org/foo}foo/{http://sample.org/bar}bar</code>
 * @param expression//from  ww  w. j a va 2  s  .co  m
 * @return
 */
public static Map<String, String> getDynamicNamespaces(String expression) {
    Map<String, String> namespaces = new HashMap<String, String>();

    if (expression.contains(DYNAMIC_NS_START) && expression.contains(DYNAMIC_NS_END)) {
        String[] tokens = expression.split("\\" + DYNAMIC_NS_START);

        for (int i = 1; i < tokens.length; i++) {
            String namespace = tokens[i].substring(0, tokens[i].indexOf(DYNAMIC_NS_END));

            if (!namespaces.containsValue(namespace)) {
                namespaces.put(DYNAMIC_NS_PREFIX + i, namespace);
            }
        }
    }

    return namespaces;
}

From source file:Main.java

public static long getNetSpeed() {
    ProcessBuilder cmd;//  w  w w.j  a  va  2  s .com
    long readBytes = 0;
    BufferedReader rd = null;
    try {
        String[] args = { "/system/bin/cat", "/proc/net/dev" };
        cmd = new ProcessBuilder(args);
        Process process = cmd.start();
        rd = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String line;
        while ((line = rd.readLine()) != null) {
            if (line.contains("lan0") || line.contains("eth0")) {
                String[] delim = line.split(":");
                if (delim.length >= 2) {
                    readBytes = parserNumber(delim[1].trim());
                    break;
                }
            }
        }
        rd.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        if (rd != null) {
            try {
                rd.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return readBytes;
}

From source file:Main.java

private static String propReader(String filter) {
    Process process = null;//from w  w  w  . java  2 s .c  o  m
    try {
        process = new ProcessBuilder().command("/system/bin/getprop").redirectErrorStream(true).start();
    } catch (IOException e) {
        e.printStackTrace();
    }

    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));

    StringBuilder log = new StringBuilder();
    String line;
    try {
        while ((line = bufferedReader.readLine()) != null) {
            if (line.contains(filter))
                log.append(line + "\n");
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    process.destroy();
    return log.toString();
}

From source file:com.tyro.oss.pact.spring4.pact.consumer.PactPublisher.java

private static void publishPactFile(String provider, String consumer, String version, String pactFile,
        String brokerBaseUrl) throws IOException {
    if (version.contains("-SNAPSHOT")) {
        version = version.replace("-SNAPSHOT", "");
    }/*w  w  w.  j  av a  2s  . c o  m*/

    String url = brokerBaseUrl + "/pacts/provider/" + provider + "/consumer/" + consumer + "/version/"
            + version;

    String pactJson = FileUtils.readFileToString(new File(pactFile));

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    HttpEntity<String> httpEntity = new HttpEntity<>(pactJson, headers);

    try {
        RestTemplate restTemplate = new RestTemplate();
        restTemplate.put(url, httpEntity);
    } catch (ResourceAccessException e) {
        throw new NoPactBrokerException(String.format("Could not reach Pact broker: %s.", brokerBaseUrl), e);
    } catch (HttpClientErrorException e) {
        throw e;
    }
}

From source file:Main.java

/**
 * @param string/*www  . jav a  2 s  .co m*/
 * @return string without the before [
 */
private static String stripEndSquareBrackets(String string) {
    if (string.contains("[")) {
        return string.substring(0, string.indexOf('['));
    } else {
        return string;
    }
}

From source file:com.mtag.traffic.util.JsonTools.java

public static Object requestPath(JSONObject root, String path) {
    String[] ids = path.split("\\.");
    Object obj = root;/*from   w w  w .ja  v  a  2  s  . c o  m*/
    for (String id : ids) {
        if (id.contains(":")) {
            String[] idIndex = id.split("\\:");
            if (obj != null && obj instanceof JSONObject && ((JSONObject) obj).containsKey(idIndex[0])) {
                obj = ((JSONObject) obj).get(idIndex[0]);
                if (obj != null && obj instanceof JSONArray) {
                    obj = ((JSONArray) obj).get(Integer.decode(idIndex[1]));
                } else {
                    return null;
                }
            } else {
                return null;
            }
        } else {
            if (obj != null && obj instanceof JSONObject && ((JSONObject) obj).containsKey(id)) {
                obj = ((JSONObject) obj).get(id);
            } else {
                return null;
            }
        }
    }
    return obj;
}

From source file:Main.java

public static String makeFile(Context context, String filePath) {
    String fileName;// w ww  .  j a  v  a 2 s.  c om
    if (!filePath.startsWith("/")) {
        if (filePath.contains("/")) {
            fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
        } else {
            fileName = filePath;
        }
        return assetToSd(context, filePath, fileName);
    }
    return null;
}

From source file:ch.epfl.eagle.daemon.util.Resources.java

public static int getSystemMemoryMb(Configuration conf) {
    int systemMemory = -1;
    try {/*from w ww.  ja  v a2s. c  o  m*/
        Process p = Runtime.getRuntime().exec("cat /proc/meminfo");
        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line = in.readLine();
        while (line != null) {
            if (line.contains("MemTotal")) {
                String[] parts = line.split("\\s+");
                if (parts.length > 1) {
                    int memory = Integer.parseInt(parts[1]) / 1000;
                    systemMemory = memory;
                }
            }
            line = in.readLine();
        }
    } catch (IOException e) {
    }
    if (conf.containsKey(EagleConf.SYSTEM_MEMORY)) {
        return conf.getInt(EagleConf.SYSTEM_MEMORY);
    } else {
        if (systemMemory != -1) {
            return systemMemory;
        } else {
            return EagleConf.DEFAULT_SYSTEM_MEMORY;
        }
    }
}

From source file:com.sic.bb.jenkins.plugins.sicci_for_xcode.io.XcodebuildOutputParser.java

public static String[] getAvailableSdks(FilePath workspace) {
    ArrayList<String> sdks = new ArrayList<String>();

    String sdksString = XcodebuildCommandCaller.getInstance().getOutput(workspace, "-list");

    if (StringUtils.isBlank(sdksString))
        return new String[0];

    for (String sdk : sdksString.split("\n")) {
        if (!sdk.contains("-sdk"))
            continue;

        sdks.add(availableSdksPattern.matcher(sdk).replaceAll("$1"));
    }/*from   ww  w. j a  va 2 s  .co m*/

    return (String[]) sdks.toArray(new String[sdks.size()]);
}