Hush/src/main/java/com/zerohighdef/hush/WatchCategory.java

52 lines
1.3 KiB
Java

package com.zerohighdef.hush;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
public class WatchCategory {
private final String categoryName;
private final List<Pattern> patterns;
private final List<String> commands;
private final boolean cancelMsg;
public WatchCategory(String categoryName, List<String> patterns, List<String> commands, boolean cancelMsg) {
this.categoryName = categoryName;
this.patterns = buildPattern(patterns);
this.commands = commands;
this.cancelMsg = cancelMsg;
}
private static List<Pattern> buildPattern(List<String> patternList) {
return patternList
.stream()
.map(p -> Pattern.compile(String.format("(%s)", p)))
.collect(Collectors.toList());
}
public Matcher checkPatterns(String string) {
for (Pattern p: patterns) {
Matcher matcher = p.matcher(string);
if (matcher.find()) {
return matcher;
}
}
return null;
}
public String getCategoryName() {
return categoryName;
}
public List<String> getCommands() {
return commands;
}
public boolean getCancelMsg() {
return cancelMsg;
}
}