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 boolean copyAssetFolder2(AssetManager assetManager, String fromAssetPath, String toPath) {
    try {/*from  w  ww.j  a va  2 s  . c  om*/
        String[] files = assetManager.list(fromAssetPath);
        new File(toPath).mkdirs();
        boolean res = true;
        for (String file : files)
            if (file.contains("."))
                res &= copyAsset(assetManager, fromAssetPath + File.separator + file,
                        toPath + File.separator + file);
            else
                res &= copyAssetFolder2(assetManager, fromAssetPath + File.separator + file,
                        toPath + File.separator + file);
        return res;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:Main.java

/**
 * When doing a web search, there are two situations.
 *
 * If user type in a url or something similar to a url, we need to
 * open the url directly for user. Otherwise, we just search the
 * content user type in with default search engine.
 *
 * @param str content user want to search or url user want to visit
 * @return intent/*  w ww.j  a  v  a2  s . c o m*/
 */
public static Intent getWebSearchIntent(String str) {
    Intent intent;
    // if search content contain ".", we think it's a url
    if (str.contains(".")) {
        if (!str.startsWith("http://") && !str.startsWith("https://"))
            str = "http://" + str;
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse(str));
    } else {
        intent = new Intent(Intent.ACTION_WEB_SEARCH);
        intent.putExtra(SearchManager.QUERY, str);
    }
    return intent;
}

From source file:Main.java

public static String changeImageParam(String url, String param) {
    if (url != null) {
        StringBuilder sb = new StringBuilder();
        if (url.contains("?")) {
            sb.append(url.substring(0, url.indexOf("?")));
        } else {/*from   w  w w  .  j a  v a 2 s.c  om*/
            sb.append(url);
        }
        if (param != null) {
            sb.append(param);
        }
        return sb.toString();
    }
    return null;
}

From source file:com.cloud.utils.ssh.SSHKeysHelper.java

public static String getPublicKeyFromKeyMaterial(String keyMaterial) {
    if (!keyMaterial.contains(" "))
        keyMaterial = new String(Base64.decodeBase64(keyMaterial.getBytes()));

    if (!keyMaterial.startsWith("ssh-rsa") || !keyMaterial.contains(" "))
        return null;

    String[] key = keyMaterial.split(" ");
    if (key.length < 2)
        return null;

    return key[0].concat(" ").concat(key[1]);
}

From source file:com.haulmont.cuba.gui.components.sys.ValuePathHelper.java

public static String[] parse(String path) {
    if (!path.contains(".") && !path.contains("[")) {
        return new String[] { path };
    }//from   www.  ja v  a  2 s  .com

    if (!path.contains("[")) {
        return path.split("\\.");
    }

    List<String> elements = new ArrayList<>();

    int bracketCount = 0;

    StringBuilder buffer = new StringBuilder();

    for (int i = 0; i < path.length(); i++) {
        char c = path.charAt(i);
        if (c == '[') {
            bracketCount++;
            continue;
        }

        if (c == ']') {
            bracketCount--;
            continue;
        }

        if ('.' != c || bracketCount > 0)
            buffer.append(c);

        if ('.' == c && bracketCount == 0) {
            String element = buffer.toString();
            if (!StringUtils.isEmpty(element)) {
                elements.add(element);
            } else {
                throw new IllegalStateException("Wrong value path format");
            }
            buffer = new StringBuilder();
        }
    }
    elements.add(buffer.toString());

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

From source file:Main.java

/**
 * @brief      get charset value from one full html buffer
 * /*from   w  ww . ja va2 s.com*/
 * @param      buffer   [IN]  html buffer
 * 
 * @return     Return charset value
 */
public static String getCharSet(byte[] buffer) {
    final int MAX_HEADER_LENGTH = 512;
    String tmpStr = new String(buffer, 0, MAX_HEADER_LENGTH);
    boolean bHasCharSet = false;
    if (tmpStr.contains("charset")) {
        int start = tmpStr.indexOf("charset");
        int end1 = tmpStr.indexOf(";", start);
        int end2 = tmpStr.indexOf("\"", start);
        int end = end1 < end2 && end1 != -1 ? end1 : end2;
        tmpStr = (String) tmpStr.subSequence(start + 7, end);
        tmpStr = tmpStr.replace("=", "");
        tmpStr = tmpStr.trim();
        bHasCharSet = true;
    }

    if (!bHasCharSet) {
        tmpStr = "utf-8";
    }
    return tmpStr;
}

From source file:Main.java

/**
 * Convenience method for retrieving a subset of the UIDefaults pertaining
 * to a particular class.//w w w. j a  v  a  2s. com
 *
 * @param className fully qualified name of the class of interest
 * @return the UIDefaults of the class named
 */
public static UIDefaults getUIDefaultsOfClass(String className) {
    UIDefaults retVal = new UIDefaults();
    UIDefaults defaults = UIManager.getLookAndFeelDefaults();
    List<?> listKeys = Collections.list(defaults.keys());
    for (Object key : listKeys) {
        if (key instanceof String && ((String) key).startsWith(className)) {
            String stringKey = (String) key;
            String property = stringKey;
            if (stringKey.contains(".")) {
                property = stringKey.substring(stringKey.indexOf(".") + 1);
            }
            retVal.put(property, defaults.get(key));
        }
    }
    return retVal;
}

From source file:Main.java

private static boolean checkPIN(Context context, String PIN1, String PIN2) {
    boolean isOK = true;
    if (PIN1.length() != 4 && PIN2.length() != 4 || PIN1.contains(" ")) {
        String message = "Only 4 digits allowed";
        showErrorDialog(context, message);
        isOK = false;//from   w w  w  . jav a 2  s  . c  o  m
    } else {
        if (!PIN1.equals(PIN2)) {
            isOK = false;
            String message = "Both Values should be same";
            showErrorDialog(context, message);
        }
    }
    return isOK;

}

From source file:Main.java

/** 
 * Uses the value returned via the component's getText() method to set a Mnemonic key.
 * The character following the first '&' charcater is used as Mnemonic key,
 * but this only works for characters in the range a..Z
 * If a Mnemonic key is found, the '&' character is removed from the text.
 * @param textComponent/* w w  w .  j a  v a  2s.co m*/
 */
public static void setMnemonic(AbstractButton textComponent) {

    String label = textComponent.getText();
    if (label == null || label.isEmpty() || !label.contains("&") || label.indexOf('&') == label.length() - 1) {

        return;
    }
    char ch = label.charAt(label.indexOf('&') + 1);
    if (!Character.isLetter(ch)) {
        return;
    }
    int ke = getKeyEvent(ch);
    if (ke != Integer.MIN_VALUE) {
        label = label.substring(0, label.indexOf('&'))
                + label.substring(label.indexOf('&') + 1, label.length());
        textComponent.setText(label);
        textComponent.setMnemonic(ke);
    }
}

From source file:it.f2informatica.pagination.services.PageableFactoryImpl.java

private static String suppressUniquePrefixIfAny(String sortColumn) {
    final String separator = "_";
    if (sortColumn.contains(UNIQUE_PREFIX)) {
        List<String> realComposedField = Lists.newArrayList();
        for (String fakeField : sortColumn.split(separator)) {
            if (fakeField.startsWith(UNIQUE_PREFIX)) {
                realComposedField.add(fakeField.substring(UNIQUE_PREFIX.length()).toLowerCase());
                continue;
            }//from w  ww. j  a  v  a2 s .  c  om
            realComposedField.add(fakeField);
        }
        return org.apache.commons.lang3.StringUtils.join(realComposedField, separator).replace(separator, ".");
    }
    return sortColumn.replace(separator, ".");
}