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

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

package com.daiyc.extension.adaptive.matcher;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * @author daiyc
 * @since 2024/12/14
 */
public class ChainMatcher> implements Matcher {
    private final List matchers = new ArrayList<>();

    @SafeVarargs
    public static > Matcher as(M... matchers) {
        return new ChainMatcher<>(matchers);
    }

    @SafeVarargs
    public ChainMatcher(M... matchers) {
        this.matchers.addAll(Arrays.asList(matchers));
    }

    @Override
    public R match(T t) {
        return matchers.stream()
                .map(matcher -> matcher.match(t))
                .filter(Objects::nonNull)
                .findFirst()
                .orElse(null);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy