Java 8 Pattern - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Pattern class.

This code example shows how to use the following methods:matcher
    if (status != 200) {
      return; 
    } 
 
    String content = consume(response.getEntity());
    Matcher matcher = PRODUCT_NAME_PRICE_PATTERN.matcher(content);
    if (matcher.find()) {
      append(matcher.group(1));
      append(matcher.group(2));
    } 
    setLink(uri);
  } 
 
  private static String consume(HttpEntity entity) {
    Log.d(TAG, "Consuming entity");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    InputStream in = null;
    try { 
      in = entity.getContent();
      byte[] buffer = new byte[1024];
10
CodeRank
This code example shows how to use the following methods:matcher
    public boolean isSatisfied(Object validatedObject, Object value, OValContext context, Validator validator) {
        value = Validation.willBeValidated(value);
        if (value == null || value.toString().length() == 0) {
            return true; 
        } 
        return emailPattern.matcher(value.toString()).matches();
    } 
    
} 
10
CodeRank
This code example shows how to use the following methods:matcher
 
    public boolean isSatisfied(Object validatedObject, Object value, OValContext context, Validator validator) {
        if (value == null || value.toString().length() == 0) {
            return true; 
        } 
        return urlPattern.matcher(value.toString()).matches();
    } 
 
} 
9
CodeRank
This code example shows how to use the following methods:matcher
        this.pattern = Pattern.compile(regex, flag);
    } 
 
    @Override 
    protected boolean matchesSafely(String item) {
        return pattern.matcher(item).find();
    } 
 
    @Override 
    public void describeTo(Description description) {
        description.appendText(regex);
    } 
 
    public static RegexMatcher matches(String regex) {
        return new RegexMatcher(regex);
    } 
 
    public static RegexMatcher matches(String regex, int flag) {
        return new RegexMatcher(regex, flag);
    } 
8
CodeRank
This code example shows how to use the following methods:matcher, pattern
  } 
 
  @Override 
  protected String parse(String str) throws Exception {
    if (pattern != null) {
      if (!pattern.matcher(str).matches()) {
        throw new IllegalArgumentException("Invalid value");
      } 
    } 
    return str;
  } 
 
  @Override 
  protected String getDomain() {
    return (pattern == null) ? "a string" : pattern.pattern();
  } 
} 
8
CodeRank
This code example shows how to use the following methods:matcher
    public boolean isSatisfied(Object validatedObject, Object value, OValContext context, Validator validator)
    throws OValException { 
        if (value == null || value.toString().length() == 0) {
            return true; 
        } 
        return phonePattern.matcher(value.toString()).matches();
    } 
 
} 
9
CodeRank
This code example shows how to use the following methods:split
     * 
     * @param cidr 
     * @return 
     */ 
    static long[] cidrMaskToMinMax(String cidr) {
        String[] parts = MASK_PATTERN.split(cidr);
        if (parts.length != 5) {
            return null; 
        } 
        int addr = (( Integer.parseInt(parts[0]) << 24 ) & 0xFF000000)
                | (( Integer.parseInt(parts[1]) << 16 ) & 0xFF0000)
                | (( Integer.parseInt(parts[2]) << 8 ) & 0xFF00)
                |  ( Integer.parseInt(parts[3]) & 0xFF);
 
        int mask = (-1) << (32 - Integer.parseInt(parts[4]));
 
        int from = addr & mask;
        long longFrom = intIpToLongIp(from);
        if (longFrom == 0) {
            longFrom = -1;
8
CodeRank
This code example shows how to use the following methods:matcher, pattern
    public Class<?> type() {
        return type;
    } 
 
    public String replaceMatchesWithGroups(String name) {
        return replaceMatchWith(name, pattern.pattern());
    } 
 
    public String replaceMatchesWithSpace(String name) {
        return replaceMatchWith(name, " ");
    } 
 
    private String replaceMatchWith(String name, String replacement) {
        Matcher matcher = pattern.matcher(name);
        String quotedReplacement = Matcher.quoteReplacement(replacement);
        return matcher.replaceAll(quotedReplacement);
    } 
} 
7
CodeRank
This code example shows how to use the following methods:matcher
    public boolean isSatisfied(Object validatedObject, Object value, OValContext context, Validator validator) {
        requireMessageVariablesRecreation(); 
        if (value == null || value.toString().length() == 0) {
            return true; 
        } 
        return pattern.matcher(value.toString()).matches();
    } 
 
    @Override 
    public Map<String, String> createMessageVariables() {
        Map<String, String> messageVariables = new HashMap<String, String>();
        messageVariables.put("pattern", pattern.toString());
        return messageVariables;
    } 
 
} 
9
CodeRank
This code example shows how to use the following methods:matcher
	} 
 
 
	@Override 
	protected boolean match(ClassMetadata metadata) {
		return this.pattern.matcher(metadata.getClassName()).matches();
	} 
 
} 
8
CodeRank

Related Java 8 Pattern Questions & Answers:

See Code Examples for Java 8 Pattern Methods: