diff --git a/src/main/java/org/sadtech/autoresponder/Autoresponder.java b/src/main/java/org/sadtech/autoresponder/Autoresponder.java index 3723185..8c6e5e3 100644 --- a/src/main/java/org/sadtech/autoresponder/Autoresponder.java +++ b/src/main/java/org/sadtech/autoresponder/Autoresponder.java @@ -30,10 +30,10 @@ public class Autoresponder { if (person.getUnit() == null) { unit = nextUnit(unitService.menuUnit(), message); } else { - if (person.getUnit().getNextUnits() != null) { - unit = nextUnit(person.getUnit().getNextUnits(), message); - } else { + if (person.getUnit().getNextUnits() == null) { unit = nextUnit(unitService.menuUnit(), message); + } else { + unit = nextUnit(person.getUnit().getNextUnits(), message); } } if (unit!=null) { diff --git a/src/main/java/org/sadtech/autoresponder/entity/Unit.java b/src/main/java/org/sadtech/autoresponder/entity/Unit.java index f56602b..c2d3c7a 100644 --- a/src/main/java/org/sadtech/autoresponder/entity/Unit.java +++ b/src/main/java/org/sadtech/autoresponder/entity/Unit.java @@ -9,18 +9,17 @@ public abstract class Unit { private Set keyWords; private Integer matchThreshold; private Integer priority; - private Boolean level; private List nextUnits; public Unit() { - level = false; + priority = 10; + matchThreshold = 50; } public Unit(Set keyWords, Integer matchThreshold, Integer priority, Boolean level, List nextUnits) { this.keyWords = keyWords; this.matchThreshold = matchThreshold; this.priority = priority; - this.level = level; this.nextUnits = nextUnits; } @@ -48,14 +47,6 @@ public abstract class Unit { this.priority = priority; } - public Boolean getLevel() { - return level; - } - - public void setLevel(Boolean level) { - this.level = level; - } - public List getNextUnits() { return nextUnits; } @@ -72,12 +63,11 @@ public abstract class Unit { return Objects.equals(keyWords, unit.keyWords) && Objects.equals(matchThreshold, unit.matchThreshold) && Objects.equals(priority, unit.priority) && - Objects.equals(level, unit.level) && Objects.equals(nextUnits, unit.nextUnits); } @Override public int hashCode() { - return Objects.hash(keyWords, matchThreshold, priority, level, nextUnits); + return Objects.hash(keyWords, matchThreshold, priority, nextUnits); } } diff --git a/src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java b/src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java index 2c946bc..3528d4f 100644 --- a/src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java +++ b/src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java @@ -2,14 +2,13 @@ package org.sadtech.autoresponder.repository; import org.sadtech.autoresponder.entity.Unit; -import java.util.Collection; import java.util.List; public interface UnitRepository { void addUnit(T unit); - void addUnits(Collection units); + void addUnits(List units); List menuUnits(); diff --git a/src/main/java/org/sadtech/autoresponder/repository/impl/PersonRepositoryMap.java b/src/main/java/org/sadtech/autoresponder/repository/impl/PersonRepositoryMap.java index d831350..ea3806d 100644 --- a/src/main/java/org/sadtech/autoresponder/repository/impl/PersonRepositoryMap.java +++ b/src/main/java/org/sadtech/autoresponder/repository/impl/PersonRepositoryMap.java @@ -16,7 +16,7 @@ public class PersonRepositoryMap implements PersonRepository { @Override public void removePerson(Person person) { - people.remove(person); + people.remove(person.getId()); } @Override diff --git a/src/main/java/org/sadtech/autoresponder/submodule/insertwords/InsertWords.java b/src/main/java/org/sadtech/autoresponder/submodule/insertwords/InsertWords.java index cb9642b..9e4e0b7 100644 --- a/src/main/java/org/sadtech/autoresponder/submodule/insertwords/InsertWords.java +++ b/src/main/java/org/sadtech/autoresponder/submodule/insertwords/InsertWords.java @@ -1,33 +1,33 @@ -package org.sadtech.autoresponder.submodule.insertwords; - -import lombok.Getter; -import lombok.Setter; - -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class InsertWords { - - @Setter - private String inText; - @Getter - private String outText; - - public void insert(List words) { - Pattern pattern = Pattern.compile("\\{(\\d+)}"); // Задаем шаблон - Matcher m = pattern.matcher(inText); // Инициализация Matcher - StringBuffer result = new StringBuffer(); // Буфер для конечного значения - while (m.find()) { // Проверка на совпадение - if (Integer.parseInt(m.group(1)) < words.size()) { - m.appendReplacement(result, words.get(Integer.parseInt(m.group(1)))); // Подставляем значение из HashMap - } else { - m.appendReplacement(result, m.group(0)); - } - } - m.appendTail(result); // Добавить остаток строки - outText = result.toString(); - } - -} +//package org.sadtech.autoresponder.submodule.insertwords; +// +//import lombok.Getter; +//import lombok.Setter; +// +//import java.util.List; +//import java.util.regex.Matcher; +//import java.util.regex.Pattern; +// +//public class InsertWords { +// +// @Setter +// private String inText; +// @Getter +// private String outText; +// +// public void insert(List words) { +// Pattern pattern = Pattern.compile("\\{(\\d+)}"); // Задаем шаблон +// Matcher m = pattern.matcher(inText); // Инициализация Matcher +// StringBuffer result = new StringBuffer(); // Буфер для конечного значения +// while (m.find()) { // Проверка на совпадение +// if (Integer.parseInt(m.group(1)) < words.size()) { +// m.appendReplacement(result, words.get(Integer.parseInt(m.group(1)))); // Подставляем значение из HashMap +// } else { +// m.appendReplacement(result, m.group(0)); +// } +// } +// m.appendTail(result); // Добавить остаток строки +// outText = result.toString(); +// } +// +//} diff --git a/src/test/java/org/sadtech/autoresponder/submodule/insertwords/InsertWordsTest.java b/src/test/java/org/sadtech/autoresponder/submodule/insertwords/InsertWordsTest.java index 763bd68..e0a60a7 100644 --- a/src/test/java/org/sadtech/autoresponder/submodule/insertwords/InsertWordsTest.java +++ b/src/test/java/org/sadtech/autoresponder/submodule/insertwords/InsertWordsTest.java @@ -1,45 +1,45 @@ -package org.sadtech.autoresponder.submodule.insertwords; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Test; -import org.sadtech.autoresponder.submodule.insertwords.InsertWords; - -import java.util.ArrayList; - -public class InsertWordsTest { - - private ArrayList arrayList = new ArrayList<>(); - private InsertWords insertWords = new InsertWords(); - - @After - public void setUp() { - - } - - @Test - public void insert() { - insertWords.setInText("Проверка {0} теста"); - arrayList.add("первого"); - insertWords.insert(arrayList); - Assert.assertEquals(insertWords.getOutText(),"Проверка первого теста"); - } - - @Test - public void insert2() { - insertWords.setInText("Проверка {0} теста и {1} {теста}"); - arrayList.add("первого"); - arrayList.add("второго"); - insertWords.insert(arrayList); - Assert.assertEquals(insertWords.getOutText(),"Проверка первого теста и второго {теста}"); - } - - @Test - public void insert3() { - insertWords.setInText("Проверка {1} теста и {0} {теста}"); - arrayList.add("первого"); - arrayList.add("второго"); - insertWords.insert(arrayList); - Assert.assertEquals(insertWords.getOutText(),"Проверка второго теста и первого {теста}"); - } -} \ No newline at end of file +//package org.sadtech.autoresponder.submodule.insertwords; +// +//import org.junit.After; +//import org.junit.Assert; +//import org.junit.Test; +//import org.sadtech.autoresponder.submodule.insertwords.InsertWords; +// +//import java.util.ArrayList; +// +//public class InsertWordsTest { +// +// private ArrayList arrayList = new ArrayList<>(); +// private InsertWords insertWords = new InsertWords(); +// +// @After +// public void setUp() { +// +// } +// +// @Test +// public void insert() { +// insertWords.setInText("Проверка {0} теста"); +// arrayList.add("первого"); +// insertWords.insert(arrayList); +// Assert.assertEquals(insertWords.getOutText(),"Проверка первого теста"); +// } +// +// @Test +// public void insert2() { +// insertWords.setInText("Проверка {0} теста и {1} {теста}"); +// arrayList.add("первого"); +// arrayList.add("второго"); +// insertWords.insert(arrayList); +// Assert.assertEquals(insertWords.getOutText(),"Проверка первого теста и второго {теста}"); +// } +// +// @Test +// public void insert3() { +// insertWords.setInText("Проверка {1} теста и {0} {теста}"); +// arrayList.add("первого"); +// arrayList.add("второго"); +// insertWords.insert(arrayList); +// Assert.assertEquals(insertWords.getOutText(),"Проверка второго теста и первого {теста}"); +// } +//} \ No newline at end of file