Example usage for java.lang String matches

List of usage examples for java.lang String matches

Introduction

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

Prototype

public boolean matches(String regex) 

Source Link

Document

Tells whether or not this string matches the given regular expression.

Usage

From source file:net.sourceforge.fenixedu.webServices.jersey.api.FenixJerseyAPIConfig.java

public static boolean endpointMatches(String endpoint, String jerseyEndpoint) {
    String regexpEndpoint = jerseyEndpoint.replaceAll("\\{[a-z]+\\}", ".+");
    if (endpoint.matches(regexpEndpoint)) {
        return true;
    }/* w  w w. j av a2 s  .co m*/
    return false;
}

From source file:io.appium.uiautomator2.utils.AlertHelpers.java

/**
 * @return The actual text of the on-screen dialog. An empty
 * string is going to be returned if the dialog contains no text.
 * @throws NoAlertOpenException if no dialog is present on the screen
 *//*from w w w  .  j  a  v a  2s.  c om*/
public static String getText() {
    final AlertType alertType = getAlertType();

    final List<UiObject2> alertRoots = getUiDevice().findObjects(By.res(alertContentResId));
    if (alertRoots.isEmpty()) {
        Log.w(TAG, "Alert content container is missing");
        throw new NoAlertOpenException();
    }

    final List<String> result = new ArrayList<>();
    final List<UiObject2> alertElements = alertRoots.get(0).findObjects(By.res(alertElementsResIdPattern));
    Log.d(TAG, String.format("Detected %d alert elements", alertElements.size()));
    final String alertButtonsResIdPattern = alertType == AlertType.REGULAR
            ? regularAlertButtonResIdPattern.toString()
            : permissionAlertButtonResIdPattern.toString();
    for (final UiObject2 element : alertElements) {
        final String resName = element.getResourceName();
        if (resName == null || resName.matches(alertButtonsResIdPattern)) {
            continue;
        }

        final String text = element.getText();
        if (isBlank(text)) {
            continue;
        }

        result.add(text);
    }
    return join("\n", result);
}

From source file:Main.java

public static String getTablesFolder(String appName, String tableId) {
    String path;/*from  w w w  .  j a  v  a2 s. c o m*/
    if (tableId == null || tableId.length() == 0) {
        throw new IllegalArgumentException("getTablesFolder: tableId is null or the empty string!");
    } else {
        if (!tableId.matches("^\\p{L}\\p{M}*(\\p{L}\\p{M}*|\\p{Nd}|_)+$")) {
            throw new IllegalArgumentException(
                    "getFormFolder: tableId does not begin with a letter and contain only letters, digits or underscores!");
        }
        path = getTablesFolder(appName) + File.separator + tableId;
    }
    File f = new File(path);
    f.mkdirs();
    return f.getAbsolutePath();
}

From source file:com.aliyun.openservices.odps.console.utils.QueryUtil.java

/**
 * sql?insert?partition//from   w  w  w. j  av  a2 s .c o  m
 * */
public static boolean isOperatorDisabled(String sql) {

    String upSql = sql.toUpperCase();

    if (upSql.matches("^INSERT\\s+INTO.*")) {
        return true;
    }

    //dy patition
    if (upSql.indexOf("INSERT ") >= 0 && upSql.indexOf(" PARTITION") >= 0) {

        //split partition
        String[] partitions = upSql.split(" PARTITION");

        for (int i = 0; i < partitions.length; i++) {
            String temp = partitions[i].trim();

            if (temp.startsWith("(") && temp.indexOf(")") > 0) {

                //get partition spec
                String partitionStr = temp.substring(0, temp.indexOf(")"));
                String[] partitionSpcs = partitionStr.split(",");
                String lastPartitionSpc = partitionSpcs[partitionSpcs.length - 1];
                if (lastPartitionSpc.indexOf("=") == -1) {
                    //?????
                    return true;
                }
            }
        }
    }

    return false;
}

From source file:com.screenslicer.core.nlp.NlpUtil.java

public static Collection<String> stems(String src, boolean ignoreCommonWords, boolean oneStemOnly) {
    if (stemsCache.size() > MAX_CACHE) {
        stemsCache.clear();// www  . j av a  2 s .  c o  m
    }
    String cacheKey = src + "<<>>" + Boolean.toString(ignoreCommonWords) + "<<>>"
            + Boolean.toString(oneStemOnly);
    if (stemsCache.containsKey(cacheKey)) {
        return stemsCache.get(cacheKey);
    }
    ignoreCommonWords = false;
    Collection<String> tokens = tokens(src, true);
    Collection<String> stems = new LinkedHashSet<String>();
    for (String word : tokens) {
        List<String> curStems = null;
        try {
            curStems = stemmer.findStems(word, null);
        } catch (Throwable t) {
        }
        if (curStems != null) {
            if (curStems.isEmpty()) {
                String cleanWord = word.toLowerCase().trim();
                if (cleanWord.matches(".*?[^\\p{Punct}].*") && (!ignoreCommonWords
                        || !ignoredTerms.contains(cleanWord) || validTermsByCase.contains(word.trim()))) {
                    stems.add(cleanWord);
                }
            } else {
                if (!ignoreCommonWords) {
                    if (oneStemOnly) {
                        stems.add(curStems.get(0));
                    } else {
                        stems.addAll(curStems);
                    }
                } else {
                    for (String curStem : curStems) {
                        if (!ignoredTerms.contains(curStem) || validTermsByCase.contains(word.trim())) {
                            stems.add(curStem);
                            if (oneStemOnly) {
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    stemsCache.put(cacheKey, stems);
    return stems;
}

From source file:com.esofthead.mycollab.core.utils.StringUtils.java

public static boolean isValidPhoneNumber(String value) {
    if (value != null && !value.trim().equals("")) {

        // validate phone numbers of format "1234567890"
        if (value.matches("\\d{10}"))
            return true;
        // validating phone number with -, . or spaces
        else if (value.matches("\\d{3}[-\\.\\s]\\d{3}[-\\.\\s]\\d{4}"))
            return true;
        // validating phone number with extension length from 3 to 5
        else if (value.matches("\\d{3}-\\d{3}-\\d{4}\\s(x|(ext))\\d{3,5}"))
            return true;
        // validating phone number where area code is in braces ()
        else if (value.matches("\\(\\d{3}\\)-\\d{3}-\\d{4}"))
            return true;
        // return false if nothing matches the input
        else/*from   ww w .j a v  a 2s. c  o  m*/
            return false;
    } else {
        return true;
    }
}

From source file:com.jms.notify.utils.StringUtil.java

/**
 * ???false./*from  w w w.j a v a 2  s .  c om*/
 * 
 * @author WuShuicheng .
 * @param str
 *            ? .
 * @return true or false .
 */
public static boolean isNumeric(String str) {
    if (StringUtils.isBlank(str)) {
        return false;
    } else {
        return str.matches("\\d*");
    }
}

From source file:com.microsoftopentechnologies.windowsazurestorage.helper.Utils.java

/**
 * Checks for validity of container name after converting the input into
 * lowercase. Rules for container name 1.Container names must start with a
 * letter or number, and can contain only letters, numbers, and the dash (-)
 * character. 2.Every dash (-) character must be immediately preceded and
 * followed by a letter or number; consecutive dashes are not permitted in
 * container names. 3.All letters in a container name must be lowercase.
 * 4.Container names must be from 3 through 63 characters long.
 *
 * @param containerName Name of the Windows Azure storage container
 * @return true if container name is valid else returns false
 *///w w  w  .ja v  a 2  s .  c  o  m
public static boolean validateContainerName(final String containerName) {
    if (containerName != null) {
        String lcContainerName = containerName.trim().toLowerCase(Locale.ENGLISH);
        if (lcContainerName.matches(Constants.VAL_CNT_NAME)) {
            return true;
        }
    }
    return false;
}

From source file:dk.netarkivet.common.utils.DomainUtils.java

/** Helper method for reading TLDs from settings.
 * Will read all settings, validate them as legal TLDs and
 * warn and ignore them if any are invalid.
 * Settings may be with or without prefix "."
 * @return a List of TLDs as Strings //ww w  . ja  va 2 s.c o m
 */
private static List<String> readTlds() {
    List<String> tlds = new ArrayList<String>();
    for (String tld : Settings.getAll(CommonSettings.TLDS)) {
        if (tld.startsWith(".")) {
            tld = tld.substring(1);
        }
        if (!tld.matches(DOMAINNAME_CHAR_REGEX_STRING + "(" + DOMAINNAME_CHAR_REGEX_STRING + "|\\.)*")) {
            log.warn("Invalid tld '" + tld + "', ignoring");
            continue;
        }
        tlds.add(Pattern.quote(tld));
    }
    return tlds;
}

From source file:com.github.tomakehurst.wiremock.common.ContentTypes.java

public static boolean determineIsTextFromMimeType(final String mimeType) {
    return any(TEXT_MIME_TYPE_PATTERNS, new Predicate<String>() {
        @Override/*  w w w .j  a  v a2s  .co  m*/
        public boolean apply(String pattern) {
            return mimeType != null && mimeType.matches(pattern);
        }
    });
}