package com.atlassian.stash.internal.user;

import com.atlassian.bitbucket.util.UserUtils;

import java.util.function.Predicate;
import java.util.regex.Pattern;

public class GroupPageFilter implements Predicate<String> {

    private final Pattern pattern;

    public GroupPageFilter(String groupPattern) {
        if (groupPattern == null) {
            pattern = null;
        } else {
            pattern = UserUtils.createNameMatchingPattern(groupPattern);
        }
    }

    @Override
    public boolean test(String groupName) {
        return pattern == null || pattern.matcher(groupName).find();
    }

}
