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:com.izforge.izpack.util.LogUtils.java

private static void mergeLoggingConfiguration(Properties to, Properties from) {
    for (String fromName : from.stringPropertyNames()) {
        String fromValue = from.getProperty(fromName);
        if (fromName.matches("\\.?handlers") && to.containsKey(fromName)) {
            String oldValue = to.getProperty(fromName);
            if (!fromValue.equals(oldValue)) {
                to.setProperty(fromName, oldValue + ", " + fromValue);
            }//  w  ww .  j a va2 s .co m
            continue;
        }
        if (!to.containsKey(fromName)) {
            to.setProperty(fromName, fromValue);
        }
    }
}

From source file:org.cloudfoundry.maven.common.CommonUtils.java

/**
 * @param emailAddress/*w  ww.j a  v a2  s. c o m*/
 * @return
 */
public static boolean isValidEmail(String emailAddress) {
    final String regex = "^[_A-Za-z0-9-+]+(\\.[_A-Za-z0-9-+]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,})$";
    return emailAddress.matches(regex);
}

From source file:com.jernejerin.traffic.helper.TripOperations.java

/**
 * Checks if the passed string is a valid MD5 checksum string. If it is valid it returns
 * passed in string, otherwise null./*from ww w .j  a va 2  s . co m*/
 *
 * @param md5 the MD5 checksum string
 * @param defaultValue the default value to return if parse fails
 * @return MD5 checksum or null if invalid
 */
public static String tryParseMD5(String md5, String defaultValue) {
    if (md5 != null && md5.matches("[a-fA-F0-9]{32}"))
        return md5;
    else
        return defaultValue;
}

From source file:Main.java

/**
 *
 * @param tagName/*  www  .jav a2s .c om*/
 * @param matches
 * @return
 */
private static boolean matches(String tagName, String... matches) {

    if (matches == null || matches.length == 0) {
        return true;
    }

    for (String matche : matches) {
        if (tagName.matches(matche)) {
            return true;
        }
    }

    return false;
}

From source file:com.tools.image.IMagicHelper.java

/**
 * ?()/*from  ww w  .  j a  va 2s .com*/
 * 
 * @param filePath
 *            ?
 * @param toImg
 *            
 * @param text
 *            ??(??)
 * @throws MagickException
 */
public static void initTextToImg(String filePath, String toImg, String text) throws MagickException {
    ImageInfo info = new ImageInfo(filePath);
    if (filePath.toUpperCase().endsWith("JPG") || filePath.toUpperCase().endsWith("JPEG")) {
        info.setCompression(CompressionType.JPEGCompression); // JPEG?
        info.setPreviewType(PreviewType.JPEGPreview); // ?JPEG?
        info.setQuality(95);
    }
    MagickImage aImage = new MagickImage(info);
    Dimension imageDim = aImage.getDimension();
    int wideth = imageDim.width;
    int height = imageDim.height;
    if (wideth > 660) {
        height = 660 * height / wideth;
        wideth = 660;
    }
    int a = 0;
    int b = 0;
    String[] as = text.split("");
    for (String string : as) {
        if (string.matches("[\u4E00-\u9FA5]")) {
            a++;
        }
        if (string.matches("[a-zA-Z0-9]")) {
            b++;
        }
    }
    int tl = a * 12 + b * 6 + 300;
    MagickImage scaled = aImage.scaleImage(wideth, height);
    if (wideth > tl && height > 5) {
        DrawInfo aInfo = new DrawInfo(info);
        aInfo.setFill(PixelPacket.queryColorDatabase("white"));
        aInfo.setUnderColor(new PixelPacket(0, 0, 0, 100));
        aInfo.setPointsize(12);
        // ?,???
        String fontPath = "C:/WINDOWS/Fonts/MSYH.TTF";
        // String fontPath = "/usr/maindata/MSYH.TTF";
        aInfo.setFont(fontPath);
        aInfo.setTextAntialias(true);
        aInfo.setOpacity(0);
        aInfo.setText(text);
        aInfo.setGeometry("+" + (wideth - tl) + "+" + (height - 5));
        scaled.annotateImage(aInfo);
    }
    scaled.setFileName(toImg);
    scaled.writeImage(info);
    scaled.destroyImages();
}

From source file:eu.crisis_economics.configuration.NameDeclarationExpression.java

public static List<String> isExpressionOfType(String rawExpression, FromFileConfigurationContext context) {
    String expression = rawExpression.trim();
    if (expression.length() == 0)
        return null;
    boolean beginsWithLowercase = Character.isLowerCase(expression.charAt(0));
    if (!beginsWithLowercase)
        return null;
    boolean containsSyntaxTokens = expression.matches(".*[\\s-/=,\\$\\[\\]\\{\\(\\)\\}].*");
    if (containsSyntaxTokens)
        return null;
    return Arrays.asList(expression);
}

From source file:Main.java

public static boolean isValidDayTimeDuration(String value) {

    // regex for checking valid xsd:dayTimeDuration string. See
    // http://www.schemacentral.com/sc/xsd/t-xsd_dayTimeDuration.html
    String regex = "-?P((\\d)+D)?((T(\\d)+H((\\d)+M)?((\\d)+(\\.(\\d)+)?S)?)|(T(\\d)+M((\\d)+(\\.(\\d)+)?S)?)|(T(\\d)+(\\.(\\d)+)?S))?";
    return value.length() > 1 && value.matches(regex);
}

From source file:com.google.cloud.hadoop.util.HttpTransportFactory.java

/**
 * Parse an HTTP proxy from a String address.
 * @param proxyAddress The address of the proxy of the form (https?://)HOST:PORT.
 * @return The URI of the proxy.//from w w  w  .j  a v  a 2 s . co  m
 * @throws IllegalArgumentException If the address is invalid.
 */
@VisibleForTesting
static URI parseProxyAddress(@Nullable String proxyAddress) {
    if (Strings.isNullOrEmpty(proxyAddress)) {
        return null;
    }
    String uriString = proxyAddress;
    if (!uriString.contains("//")) {
        uriString = "//" + uriString;
    }
    try {
        URI uri = new URI(uriString);
        String scheme = uri.getScheme();
        String host = uri.getHost();
        int port = uri.getPort();
        if (!Strings.isNullOrEmpty(scheme) && !scheme.matches("https?")) {
            throw new IllegalArgumentException(
                    String.format("HTTP proxy address '%s' has invalid scheme '%s'.", proxyAddress, scheme));
        } else if (Strings.isNullOrEmpty(host)) {
            throw new IllegalArgumentException(String.format("Proxy address '%s' has no host.", proxyAddress));
        } else if (port == -1) {
            throw new IllegalArgumentException(String.format("Proxy address '%s' has no port.", proxyAddress));
        } else if (!uri.equals(new URI(scheme, null, host, port, null, null, null))) {
            throw new IllegalArgumentException(String.format("Invalid proxy address '%s'.", proxyAddress));
        }
        return uri;
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(String.format("Invalid proxy address '%s'.", proxyAddress), e);
    }
}

From source file:ByteUtils.java

/**
 * Converts a portion of a byte array to String value.
 * Cleans up non-word characters along the way.
 *
 * @param paRawBytes the byte array, non-UNICODE
 * @param piOffset offset in the original array to start reading bytes from
 * @param piLength how many bytes of the array paramter to interpret as String
 *
 * @return UNICODE String representation of the bytes with trailing garbage stripped;
 *         "" if array length is less than piOffset + piLength;
 *         "" if the generatied string begins with garbage
 *//*from  w w w  . j  a v  a  2  s.  com*/
public static String byteArrayToString(byte[] paRawBytes, int piOffset, int piLength) {
    if (paRawBytes.length < piOffset + piLength)
        return "";

    String oBeautifulString = new String(paRawBytes, piOffset, piLength);
    int i = 0;

    if (oBeautifulString.matches("^\\W") == true)
        oBeautifulString = "";
    else {
        for (i = piOffset; i < piOffset + piLength; i++) {
            if (paRawBytes[i] < 32 || paRawBytes[i] > 128)
                break;
        }

        oBeautifulString = oBeautifulString.substring(0, i - piOffset);
    }

    return oBeautifulString;
}

From source file:eu.eubrazilcc.lvl.storage.security.IdentityProviderHelper.java

public static String assertValidResourceOwnerId(final String ownerid) {
    final String ownerid2 = trimToEmpty(ownerid);
    checkArgument(isNotBlank(ownerid2), "Uninitialized or invalid resource owner Id");
    checkArgument(open(0, ownerid2.length()).contains(ownerid2.indexOf(IDENTITY_SEPARATOR))
            && !ownerid2.matches(".*\\s+.*"), "Invalid resource owner Id: " + ownerid);
    return ownerid2;
}