package com.jay.monitor.data.server.report.alert.rule.config;

import com.jay.monitor.data.server.enums.MatchRuleEnums;
import com.jay.monitor.data.server.report.alert.rule.MatchValueCondition;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author liukaixiong
 * @Email liukx@elab-plus.com
 * @date 2021/9/6 - 19:28
 */
@Component
public class InValueCondition implements MatchValueCondition {

    @Override
    public MatchRuleEnums matchRule() {
        return MatchRuleEnums.in;
    }

    @Override
    public boolean match(Object value, String matchValue) {
        String[] numArray = matchValue.split(",");
        Set<String> collect = Arrays.stream(numArray).collect(Collectors.toSet());
        return collect.contains(value);
    }
}
