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:nl.architolk.ldt.processors.HttpClientProperties.java

public static void setProxy(HttpGet httpRequest, String hostname) throws Exception {
    if (notInitialized) {
        initialize();//from www  .  ja v  a 2 s. c o  m
    }
    if ((requestConfig != null) && ((proxyExclude == null) || !hostname.matches(proxyExclude))) {
        httpRequest.setConfig(requestConfig);
    }
}

From source file:com.bangz.smartmute.content.LocationCondition.java

public static boolean checkStringFormat(String strcondition) {
    return strcondition.matches(strMatch);
}

From source file:org.apache.servicemix.platform.testing.support.AbstractIntegrationTest.java

protected static boolean isSnapshot(String version) {
    return version.matches(".+-SNAPSHOT");
}

From source file:com.knewton.mapreduce.io.sstable.BackwardsCompatibleDescriptor.java

/**
 * Implementation of {@link Descriptor#fromFilename(File, String)} that is backwards compatible
 * with older sstables//from   w  ww .jav  a 2  s.  c o  m
 *
 * @param directory
 * @param name
 * @return A descriptor for the sstable
 */
public static Pair<Descriptor, String> fromFilename(File directory, String name) {
    Iterator<String> iterator = Splitter.on(separator).split(name).iterator();
    iterator.next();
    String tempFlagMaybe = iterator.next();
    String versionMaybe = iterator.next();
    String generationMaybe = iterator.next();
    Pair<Descriptor, String> dsPair;
    if (tempFlagMaybe.equals(SSTable.TEMPFILE_MARKER) && generationMaybe.matches("\\d+")
            && !new Version(versionMaybe).hasAncestors) {
        // old sstable file with temp flag.
        dsPair = Descriptor.fromFilename(directory, directory.getName() + separator + name);
    } else if (versionMaybe.equals(SSTable.TEMPFILE_MARKER)) {
        // new sstable file with temp flag.
        dsPair = Descriptor.fromFilename(directory, name);
    } else if (StringUtils.countMatches(name, String.valueOf(separator)) < NUM_SEPARATORS) {
        // old sstable file with no temp flag.
        dsPair = Descriptor.fromFilename(directory, directory.getName() + separator + name);
    } else {
        // new sstable file with no temp flag.
        dsPair = Descriptor.fromFilename(directory, name);
    }
    // cast so that Pair doens't complain.
    return Pair.create((Descriptor) new BackwardsCompatibleDescriptor(dsPair.left), dsPair.right);
}

From source file:automaticdatabaseupdate.FileHandler.java

private static ArrayList<String> ParseLogFile(String strRawString) {
    ArrayList<String> strList = new ArrayList<>();
    strList.clear();// ww  w. j a  v  a2s.  co m

    if (strRawString.matches(".*\\[.*\\].*")) {
        String[] tokens = strRawString.split("\\s*-\\s*");
        strList.add(tokens[0]);
        strList.add(tokens[1]);
    } else {
        strList.add("");
        strList.add(strRawString);
    }

    return strList;
}

From source file:cn.sixlab.sixutil.StrUtil.java

/**
 * ??//  ww w .  j a  v a  2 s. c  o m
 *
 * @param str ?
 * @return {@code str}?true {@code str}??false
 */
public static Boolean isEmail(String str) {
    String regex = "w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*";
    return str.matches(regex);
}

From source file:de.tudarmstadt.ukp.dkpro.c4corpus.license.evaluation.LicenseDetectionEvaluation.java

public static void evaluate(String inputFile) throws IOException {

    List<String> lines = FileUtils.readLines(new File(inputFile));

    String licenseType = "(by|by-sa|by-nd|by-nc|by-nc-sa|by-nc-nd|publicdomain)";
    String noLicense = "none";

    int tp = 0;//from w w w  .j a  v a2s.  com
    int tn = 0;
    int fp = 0;
    int fn = 0;

    for (String line : lines) {

        String fileID = line.split("\t")[0];
        String goldLicense = line.split("\t")[1];
        String predictedLicense = line.split("\t")[2];

        if (goldLicense.equalsIgnoreCase(predictedLicense)) {
            if (goldLicense.matches(licenseType)) {
                tp++;
            } else if (goldLicense.matches(noLicense)) {
                tn++;
            }
        } else {
            if (goldLicense.matches(noLicense) && predictedLicense.matches(licenseType)) {
                fp++;
                System.out.println("False positive detected: " + fileID);
            } else if (goldLicense.matches(licenseType) && predictedLicense.matches(noLicense)) {
                fn++;
                System.out.println("False negative detected: " + fileID);
            }
        }
    }

    float precision = tp / (float) (tp + fp);
    float recall = tp / (float) (tp + fn);
    float fScore = (2 * precision * recall) / (precision + recall);

    System.out.println("The page is licensed and predicted as licensed => True Positive: " + tp);
    System.out.println("The page is not licensed and not predicted as licensed => True Negative: " + tn);
    System.out.println(
            "The page has a CC link but not licensed, however predicted as licensed => False Positive: " + fp);
    System.out.println("The page is licensed but not predicted as licensed => False Negative: " + fn);
    System.out.println("=====================================");
    System.out.println("Precision: " + precision);
    System.out.println("Recall: " + recall);
    System.out.println("F-Score: " + fScore);
}

From source file:com.polytech4A.cuttingstock.core.resolution.util.context.ContextLoaderUtils.java

/**
 * Load a box form the file.//from  w w w.  j a  va2  s  .  co m
 *
 * @param line line in the file.
 * @return Box loaded of the line
 * @throws MalformedContextFileException if the Context file don't have the right structure.
 */
private static Box loadBox(String line) throws MalformedContextFileException {
    MalformedContextFileException mctx = new MalformedContextFileException();
    if (line.matches("[0-9]{1,13}(\\.[0-9]*)?\\t[0-9]{1,13}(\\.[0-9]*)?\\t\\d{1,5}")) {
        String[] array = line.split("\\t");
        double x = Double.parseDouble(array[0]);
        double y = Double.parseDouble(array[1]);
        if (x <= y) {
            double buf = x;
            x = y;
            y = buf;
        }
        return new Box(new Vector(x, y), Integer.parseInt(array[2]));
    } else
        throw mctx;
}

From source file:cz.muni.fi.webmias.TeXConverter.java

/**
 * Converts TeX formula to MathML using LaTeXML through a web service.
 *
 * @param query String containing one or more keywords and TeX formulae
 * (formulae enclosed in $ or $$).//from  ww  w.  j a  va 2s.c o m
 * @return String containing formulae converted to MathML that replaced
 * original TeX forms. Non math tokens are connected at the end.
 */
public static String convertTexLatexML(String query) {
    query = query.replaceAll("\\$\\$", "\\$");
    if (query.matches(".*\\$.+\\$.*")) {
        try {
            HttpClient httpclient = HttpClients.createDefault();
            HttpPost httppost = new HttpPost(LATEX_TO_XHTML_CONVERSION_WS_URL);

            // Request parameters and other properties.
            List<NameValuePair> params = new ArrayList<>(1);
            params.add(new BasicNameValuePair("code", query));
            httppost.setEntity(new UrlEncodedFormEntity(params, StandardCharsets.UTF_8));

            // Execute and get the response.
            HttpResponse response = httpclient.execute(httppost);
            if (response.getStatusLine().getStatusCode() == 200) {
                HttpEntity resEntity = response.getEntity();
                if (resEntity != null) {
                    try (InputStream responseContents = resEntity.getContent()) {
                        DocumentBuilder dBuilder = MIaSUtils.prepareDocumentBuilder();
                        org.w3c.dom.Document doc = dBuilder.parse(responseContents);
                        NodeList ps = doc.getElementsByTagName("p");
                        String convertedMath = "";
                        for (int k = 0; k < ps.getLength(); k++) {
                            Node p = ps.item(k);
                            NodeList pContents = p.getChildNodes();
                            for (int j = 0; j < pContents.getLength(); j++) {
                                Node pContent = pContents.item(j);
                                if (pContent instanceof Text) {
                                    convertedMath += pContent.getNodeValue() + "\n";
                                } else {
                                    TransformerFactory transFactory = TransformerFactory.newInstance();
                                    Transformer transformer = transFactory.newTransformer();
                                    StringWriter buffer = new StringWriter();
                                    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                                    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
                                    transformer.transform(new DOMSource(pContent), new StreamResult(buffer));
                                    convertedMath += buffer.toString() + "\n";
                                }
                            }
                        }
                        return convertedMath;
                    }
                }
            }

        } catch (TransformerException | SAXException | ParserConfigurationException | IOException ex) {
            Logger.getLogger(ProcessServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    return query;
}

From source file:com.varaneckas.hawkscope.util.PathUtils.java

/**
 * Interprets the location/*  w ww. ja  v a 2 s  .  co  m*/
 * 
 * It can either be a full path, a java property, 
 * like ${user.home} (default) or environmental variable like ${$JAVA_HOME}.
 * 
 * @param location
 * @return
 */
public static String interpret(final String location) {
    if (!location.matches(".*" + INTERPRET_REGEX + ".*")) {
        return location;
    } else {
        String newLocation = location;
        try {
            final Pattern grep = Pattern.compile(INTERPRET_REGEX);
            final Matcher matcher = grep.matcher(location);
            while (matcher.find()) {
                log.debug("Parsing: " + matcher.group(1));
                String replacement;
                if (matcher.group(1).startsWith("$")) {
                    replacement = System.getenv(matcher.group(1).substring(1));
                } else {
                    replacement = System.getProperty(matcher.group(1));
                }
                newLocation = newLocation.replaceFirst(quote(matcher.group()),
                        replacement.replaceAll(Constants.REGEX_BACKSLASH, Constants.REGEX_SLASH));
            }
        } catch (final Exception e) {
            log.warn("Failed parsing location: " + location, e);
        }

        return newLocation;
    }
}