Example usage for java.util.regex Pattern matches

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

Introduction

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

Prototype

public static boolean matches(String regex, CharSequence input) 

Source Link

Document

Compiles the given regular expression and attempts to match the given input against it.

Usage

From source file:Main.java

/** 
 * Gets the number of cores available in this device, across all processors. 
 * Requires: Ability to peruse the filesystem at "/sys/devices/system/cpu" 
 * @return The number of cores, or 1 if failed to get result 
 *//*from w  ww .j  av a2  s. co  m*/
public static int getNumCores() {
    try {
        //Get directory containing CPU info 
        File dir = new File("/sys/devices/system/cpu/");
        //Filter to only list the devices we care about 
        File[] files = dir.listFiles(new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                //Check if filename is "cpu", followed by a single digit number 
                if (Pattern.matches("cpu[0-9]", pathname.getName())) {
                    return true;
                }
                return false;
            }

        });
        //Return the number of cores (virtual CPU devices) 
        return files.length;
    } catch (Exception e) {
        e.printStackTrace();
        return 1;
    }
}

From source file:Main.java

/**
 * Gets the number of cores available in this device, across all processors.
 * Requires: Ability to peruse the filesystem at "/sys/devices/system/cpu"
 *
 * @return The number of cores, or 1 if failed to get result
 *//*from w w w  . j av  a  2 s  . com*/
public static int getNumCores() {
    try {
        //Get directory containing CPU info 
        File dir = new File("/sys/devices/system/cpu/");
        //Filter to only list the devices we care about 
        File[] files = dir.listFiles(new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                //Check if filename is "cpu", followed by a single digit number 
                return Pattern.matches("cpu[0-9]", pathname.getName());
            }

        });
        //Return the number of cores (virtual CPU devices) 
        if (files != null)
            return files.length;
        return 1;
    } catch (Exception e) {
        e.printStackTrace();
        return 1;
    }
}

From source file:iddb.core.util.Validator.java

public static boolean isValidIp(String value) {
    return Pattern.matches(IP_RE, value);
}

From source file:io.selendroid.standalone.android.impl.AbstractDeviceTest.java

private static final Matcher<CommandLine> matchesCmdLine(final String cmdString) {
    return new BaseMatcher<CommandLine>() {
        @Override//from  ww w.ja  va  2  s  .c  o  m
        public boolean matches(Object cmdLine) {
            if (!(cmdLine instanceof CommandLine)) {
                return false;
            }
            return Pattern.matches(cmdString, cmdLine.toString());
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("command was not " + cmdString);
        }
    };
}

From source file:com.wyb.utils.util.PatternUtil.java

/**
 * ?Email/*from  ww  w .j  a  v a  2s  .  c  o m*/
 *
 * @param email email??zhangsan@sina.comzhangsan@xxx.com.cnxxx?
 * @return ??true?false
 */
public static boolean isEmail(String email) {
    if (StringUtils.isBlank(email)) {
        return false;
    }
    String regex = "\\w+@\\w+\\.[a-z]+(\\.[a-z]+)?";
    return Pattern.matches(regex, email);
}

From source file:iddb.core.util.Validator.java

public static boolean isValidSearchIp(String value) {
    return Pattern.matches(IP_RE_MASK, value);
}

From source file:iddb.core.util.Validator.java

public static boolean isValidClientId(String value) {
    return Pattern.matches(CLIENT_ID_RE, value);
}

From source file:org.apache.atlas.authorize.simple.FileReaderUtil.java

public static List<String> readFile(InputStream policyStoreStream) throws IOException {
    if (isDebugEnabled) {
        LOG.debug("==> FileReaderUtil readFile()");
    }/*  w  w w  . j a  va  2  s.c  o  m*/
    List<String> list = new ArrayList<>();
    List<String> fileLines = IOUtils.readLines(policyStoreStream, StandardCharsets.UTF_8);
    if (fileLines != null) {
        for (String line : fileLines) {
            if ((!line.startsWith("#")) && Pattern.matches(".+;;.*;;.*;;.+", line))
                list.add(line);
        }
    }

    if (isDebugEnabled) {
        LOG.debug("<== FileReaderUtil readFile()");
        LOG.debug("Policies read :: " + list);
    }

    return list;
}

From source file:org.akaza.openclinica.core.form.StringUtil.java

public static boolean isNumber(String s) {
    // To Do: whether we consider a blank string is still a number?
    return Pattern.matches("[0-9]*", s) ? true : false;

}

From source file:iddb.core.util.Validator.java

public static boolean isValidEmail(String value) {
    return Pattern.matches(MAIL_RE, value);
}