All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.daiyc.extension.adaptive.matcher.PatternMatcher Maven / Gradle / Ivy

There is a newer version: 1.3.2
Show newest version
package com.daiyc.extension.adaptive.matcher;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * @author daiyc
 * @since 2024/9/17
 */
@RequiredArgsConstructor
public class PatternMatcher implements Predicate {
    private final List patterns;

    @Getter
    private final String name;

    @Override
    public boolean test(String s) {
        return patterns.stream().anyMatch(p -> p.matcher(s).matches());
    }

    public static PatternMatcher as(String name, String... patterns) {
        return new PatternMatcher(Arrays.stream(patterns).map(Pattern::compile).collect(Collectors.toList()), name);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy