diff --git a/pom.xml b/pom.xml index 8762eb7..cd19900 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ dev.struchkov autoresponder - 3.1.0 + 3.2.0 jar Abstract Autoresponder diff --git a/src/main/java/dev/struchkov/autoresponder/Responder.java b/src/main/java/dev/struchkov/autoresponder/Responder.java index 010ed29..591a20d 100644 --- a/src/main/java/dev/struchkov/autoresponder/Responder.java +++ b/src/main/java/dev/struchkov/autoresponder/Responder.java @@ -48,11 +48,11 @@ public final class Responder { if (message != null && nextUnits != null) { for (U unit : nextUnits) { - final String unitPhrase = unit.getPhrase(); + final Set unitPhrases = unit.getPhrases(); if ( - unitPhrase != null - && !unitPhrase.isEmpty() - && unitPhrase.equalsIgnoreCase(message) + unitPhrases != null + && !unitPhrases.isEmpty() + && unitPhrases.contains(message) ) { searchUnit.add(unit); } @@ -79,7 +79,8 @@ public final class Responder { } private static > boolean isNotPhrase(U nextUnit) { - return nextUnit.getPhrase() == null; + final Set phrases = nextUnit.getPhrases(); + return phrases == null || phrases.isEmpty(); } private static > boolean isNotPattern(U nextUnit) { @@ -87,7 +88,8 @@ public final class Responder { } private static > boolean isNotKeyWords(U nextUnit) { - return nextUnit.getKeyWords() == null || nextUnit.getKeyWords().isEmpty(); + final Set keyWords = nextUnit.getKeyWords(); + return keyWords == null || keyWords.isEmpty(); } private static boolean patternReg(Pattern pattern, String message) { diff --git a/src/main/java/dev/struchkov/autoresponder/entity/Unit.java b/src/main/java/dev/struchkov/autoresponder/entity/Unit.java index 9c7df84..940ee47 100644 --- a/src/main/java/dev/struchkov/autoresponder/entity/Unit.java +++ b/src/main/java/dev/struchkov/autoresponder/entity/Unit.java @@ -1,5 +1,6 @@ package dev.struchkov.autoresponder.entity; +import java.util.Collection; import java.util.HashSet; import java.util.Objects; import java.util.Set; @@ -15,12 +16,12 @@ public abstract class Unit> { /** * Ключевые слова. */ - protected Set keyWords = new HashSet<>(); + protected Set keyWords; /** * Точная фраза. */ - protected String phrase; + protected Set phrases; /** * Регулярное выражение. @@ -40,18 +41,18 @@ public abstract class Unit> { /** * Множество следующих Unit в сценарии. */ - protected Set nextUnits = new HashSet<>(); + protected Set nextUnits; protected Unit( Set keyWords, - String phrase, + Set phrases, Pattern pattern, Integer matchThreshold, Integer priority, Set nextUnits ) { this.keyWords = keyWords; - this.phrase = phrase; + this.phrases = phrases; this.pattern = pattern; this.matchThreshold = matchThreshold == null ? 10 : matchThreshold; this.priority = priority == null ? 10 : priority; @@ -66,12 +67,16 @@ public abstract class Unit> { this.keyWords = keyWords; } - public String getPhrase() { - return phrase; + public Set getPhrases() { + return phrases; } - public void setPhrase(String phrase) { - this.phrase = phrase; + public void addPhrase(String phrase) { + phrases.add(phrase); + } + + public void addPhrases(Collection phrases) { + phrases.addAll(phrases); } public Pattern getPattern() { @@ -111,19 +116,19 @@ public abstract class Unit> { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Unit unit = (Unit) o; - return Objects.equals(keyWords, unit.keyWords) && Objects.equals(phrase, unit.phrase) && Objects.equals(pattern, unit.pattern) && Objects.equals(matchThreshold, unit.matchThreshold) && Objects.equals(priority, unit.priority); + return Objects.equals(keyWords, unit.keyWords) && Objects.equals(phrases, unit.phrases) && Objects.equals(pattern, unit.pattern) && Objects.equals(matchThreshold, unit.matchThreshold) && Objects.equals(priority, unit.priority); } @Override public int hashCode() { - return Objects.hash(keyWords, phrase, pattern, matchThreshold, priority); + return Objects.hash(keyWords, phrases, pattern, matchThreshold, priority); } @Override public String toString() { return "Unit{" + "keyWords=" + keyWords + - ", phrase='" + phrase + '\'' + + ", phrases='" + phrases + '\'' + ", pattern=" + pattern + ", matchThreshold=" + matchThreshold + ", priority=" + priority +