From ec0049d6027d91c655992c38288b6873cefcd197 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Tue, 5 Feb 2019 21:50:49 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=97=D0=B0=D0=BC=D0=B5=D0=BD=D0=B0=20List?= =?UTF-8?q?=20=D0=BD=D0=B0=20Set?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit В Unit заменил с List на Set поле хранящее следующие юниты --- pom.xml | 2 +- .../sadtech/autoresponder/Autoresponder.java | 27 ++++++++++++------- .../sadtech/autoresponder/entity/Person.java | 10 +++++++ .../sadtech/autoresponder/entity/Unit.java | 10 +++---- .../repository/UnitRepository.java | 3 ++- .../autoresponder/service/UnitService.java | 3 ++- .../service/impl/PersonServiceImpl.java | 5 ++++ .../service/impl/UnitServiceImpl.java | 3 ++- 8 files changed, 45 insertions(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index dfd0910..a27ee2b 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.sadtech.autoresponder autoresponder - 1.3.0-RELEASE + 1.4.0-SNAPSHOT jar diff --git a/src/main/java/org/sadtech/autoresponder/Autoresponder.java b/src/main/java/org/sadtech/autoresponder/Autoresponder.java index 05d54a2..c737fd8 100644 --- a/src/main/java/org/sadtech/autoresponder/Autoresponder.java +++ b/src/main/java/org/sadtech/autoresponder/Autoresponder.java @@ -8,10 +8,7 @@ import org.sadtech.autoresponder.service.PersonService; import org.sadtech.autoresponder.service.UnitService; import org.sadtech.autoresponder.submodule.parser.Parser; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; -import java.util.Set; +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -20,6 +17,15 @@ public class Autoresponder { public static final Logger log = Logger.getLogger(Autoresponder.class); private UnitService unitService; + + public PersonService getPersonService() { + return personService; + } + + public void setPersonService(PersonService personService) { + this.personService = personService; + } + private PersonService personService; public Autoresponder(UnitService unitService, PersonService personService) { @@ -56,16 +62,19 @@ public class Autoresponder { return person; } - private Unit nextUnit(List nextUnits, String message) { + private Unit nextUnit(Set nextUnits, String message) { if (nextUnits.size() > 0) { UnitPriorityComparator unitPriorityComparator = new UnitPriorityComparator(); Optional patternUnits = nextUnits.stream().filter(nextUnit -> nextUnit.getPattern() != null).filter(nextUnit -> patternReg(nextUnit, message)).max(unitPriorityComparator); if (!patternUnits.isPresent()) { - Parser parser = new Parser(); - parser.setText(message); - parser.parse(); - patternUnits = nextUnits.stream().filter(nextUnit -> textPercentageMatch(nextUnit, parser.getWords()) >= nextUnit.getMatchThreshold()).max(unitPriorityComparator); + patternUnits = nextUnits.stream().filter(nextUnit -> (textPercentageMatch(nextUnit, new HashSet<>(Collections.singleton(message))) == 100.0)).max(unitPriorityComparator); + if (!patternUnits.isPresent()) { + Parser parser = new Parser(); + parser.setText(message); + parser.parse(); + patternUnits = nextUnits.stream().filter(nextUnit -> textPercentageMatch(nextUnit, parser.getWords()) >= nextUnit.getMatchThreshold()).max(unitPriorityComparator); + } } if (!patternUnits.isPresent()) { diff --git a/src/main/java/org/sadtech/autoresponder/entity/Person.java b/src/main/java/org/sadtech/autoresponder/entity/Person.java index 86fb8d1..92f5a4e 100644 --- a/src/main/java/org/sadtech/autoresponder/entity/Person.java +++ b/src/main/java/org/sadtech/autoresponder/entity/Person.java @@ -6,10 +6,12 @@ public class Person { private Integer id; private Unit unit; + private Boolean replyStatus; public Person(Integer id, Unit unit) { this.id = id; this.unit = unit; + replyStatus = true; } public Person(Integer id) { @@ -32,6 +34,14 @@ public class Person { this.unit = unit; } + public Boolean getReplyStatus() { + return replyStatus; + } + + public void setReplyStatus(Boolean replyStatus) { + this.replyStatus = replyStatus; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/src/main/java/org/sadtech/autoresponder/entity/Unit.java b/src/main/java/org/sadtech/autoresponder/entity/Unit.java index e4df06c..690e008 100644 --- a/src/main/java/org/sadtech/autoresponder/entity/Unit.java +++ b/src/main/java/org/sadtech/autoresponder/entity/Unit.java @@ -9,14 +9,14 @@ public abstract class Unit { private Pattern pattern; private Integer matchThreshold; private Integer priority; - private List nextUnits; + private Set nextUnits; public Unit() { priority = 10; matchThreshold = 10; } - public Unit(Set keyWords, Pattern pattern, Integer matchThreshold, Integer priority, List nextUnits) { + public Unit(Set keyWords, Pattern pattern, Integer matchThreshold, Integer priority, Set nextUnits) { this.keyWords = keyWords; this.pattern = pattern; this.matchThreshold = matchThreshold; @@ -33,7 +33,7 @@ public abstract class Unit { public void setNextUnit(Unit unit) { if (nextUnits == null) { - nextUnits = new ArrayList<>(); + nextUnits = new HashSet<>(); } nextUnits.add(unit); } @@ -62,11 +62,11 @@ public abstract class Unit { this.priority = priority; } - public List getNextUnits() { + public Set getNextUnits() { return nextUnits; } - public void setNextUnits(List nextUnits) { + public void setNextUnits(Set nextUnits) { this.nextUnits = nextUnits; } diff --git a/src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java b/src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java index 74d8040..380bd34 100644 --- a/src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java +++ b/src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java @@ -3,6 +3,7 @@ package org.sadtech.autoresponder.repository; import org.sadtech.autoresponder.entity.Unit; import java.util.List; +import java.util.Set; public interface UnitRepository { @@ -10,6 +11,6 @@ public interface UnitRepository { void addUnits(List units); - List menuUnits(); + Set menuUnits(); } diff --git a/src/main/java/org/sadtech/autoresponder/service/UnitService.java b/src/main/java/org/sadtech/autoresponder/service/UnitService.java index 0b44574..7729011 100644 --- a/src/main/java/org/sadtech/autoresponder/service/UnitService.java +++ b/src/main/java/org/sadtech/autoresponder/service/UnitService.java @@ -4,10 +4,11 @@ import org.sadtech.autoresponder.entity.Unit; import org.sadtech.autoresponder.repository.UnitRepository; import java.util.List; +import java.util.Set; public interface UnitService { - List menuUnit(); + Set menuUnit(); void addUnit(Unit unit); diff --git a/src/main/java/org/sadtech/autoresponder/service/impl/PersonServiceImpl.java b/src/main/java/org/sadtech/autoresponder/service/impl/PersonServiceImpl.java index 4162ec7..53d1ad3 100644 --- a/src/main/java/org/sadtech/autoresponder/service/impl/PersonServiceImpl.java +++ b/src/main/java/org/sadtech/autoresponder/service/impl/PersonServiceImpl.java @@ -2,6 +2,7 @@ package org.sadtech.autoresponder.service.impl; import org.sadtech.autoresponder.entity.Person; import org.sadtech.autoresponder.repository.PersonRepository; +import org.sadtech.autoresponder.repository.impl.PersonRepositoryMap; import org.sadtech.autoresponder.service.PersonService; import org.apache.log4j.Logger; @@ -12,6 +13,10 @@ public class PersonServiceImpl implements PersonService { private PersonRepository personRepository; + public PersonServiceImpl() { + this.personRepository = new PersonRepositoryMap(); + } + public PersonServiceImpl(PersonRepository personRepository) { this.personRepository = personRepository; } diff --git a/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java b/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java index d3bd53e..5cb2fff 100644 --- a/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java +++ b/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java @@ -7,6 +7,7 @@ import org.sadtech.autoresponder.service.UnitService; import java.util.ArrayList; import java.util.List; +import java.util.Set; public class UnitServiceImpl implements UnitService { @@ -19,7 +20,7 @@ public class UnitServiceImpl implements UnitService { } @Override - public List menuUnit() { + public Set menuUnit() { return unitRepository.menuUnits(); } From dc1e6be1bccdb026bc16b4b87bfe24db6adf8e2e Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Thu, 7 Feb 2019 18:00:40 +0300 Subject: [PATCH 2/2] Release 1.3.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Заменил List на Set у NextUnit у класса Unit * CodeStyle --- pom.xml | 2 +- .../org/sadtech/autoresponder/Autoresponder.java | 15 ++++++--------- .../autoresponder/service/UnitService.java | 2 -- .../service/impl/UnitServiceImpl.java | 2 -- 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index a27ee2b..3a0ef96 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.sadtech.autoresponder autoresponder - 1.4.0-SNAPSHOT + 1.3.1-RELEASE jar diff --git a/src/main/java/org/sadtech/autoresponder/Autoresponder.java b/src/main/java/org/sadtech/autoresponder/Autoresponder.java index c737fd8..180567d 100644 --- a/src/main/java/org/sadtech/autoresponder/Autoresponder.java +++ b/src/main/java/org/sadtech/autoresponder/Autoresponder.java @@ -17,6 +17,7 @@ public class Autoresponder { public static final Logger log = Logger.getLogger(Autoresponder.class); private UnitService unitService; + private PersonService personService; public PersonService getPersonService() { return personService; @@ -26,8 +27,6 @@ public class Autoresponder { this.personService = personService; } - private PersonService personService; - public Autoresponder(UnitService unitService, PersonService personService) { this.unitService = unitService; this.personService = personService; @@ -68,13 +67,10 @@ public class Autoresponder { Optional patternUnits = nextUnits.stream().filter(nextUnit -> nextUnit.getPattern() != null).filter(nextUnit -> patternReg(nextUnit, message)).max(unitPriorityComparator); if (!patternUnits.isPresent()) { - patternUnits = nextUnits.stream().filter(nextUnit -> (textPercentageMatch(nextUnit, new HashSet<>(Collections.singleton(message))) == 100.0)).max(unitPriorityComparator); - if (!patternUnits.isPresent()) { - Parser parser = new Parser(); - parser.setText(message); - parser.parse(); - patternUnits = nextUnits.stream().filter(nextUnit -> textPercentageMatch(nextUnit, parser.getWords()) >= nextUnit.getMatchThreshold()).max(unitPriorityComparator); - } + Parser parser = new Parser(); + parser.setText(message); + parser.parse(); + patternUnits = nextUnits.stream().filter(nextUnit -> textPercentageMatch(nextUnit, parser.getWords()) >= nextUnit.getMatchThreshold()).max(unitPriorityComparator); } if (!patternUnits.isPresent()) { @@ -100,6 +96,7 @@ public class Autoresponder { if (unit.getKeyWords() != null) { Set temp = new HashSet<>(unit.getKeyWords()); temp.retainAll(words); + log.info("Юнит: " + unit.getClass().getSimpleName()); log.info("Ключевые слова юнита: " + unit.getKeyWords() + " (" + unit.getKeyWords().size() + ")"); log.info("Ключевые слова от пользователя: " + words); log.info("Пересечение: " + temp + " (" + temp.size() + ")"); diff --git a/src/main/java/org/sadtech/autoresponder/service/UnitService.java b/src/main/java/org/sadtech/autoresponder/service/UnitService.java index 7729011..903fe99 100644 --- a/src/main/java/org/sadtech/autoresponder/service/UnitService.java +++ b/src/main/java/org/sadtech/autoresponder/service/UnitService.java @@ -1,9 +1,7 @@ package org.sadtech.autoresponder.service; import org.sadtech.autoresponder.entity.Unit; -import org.sadtech.autoresponder.repository.UnitRepository; -import java.util.List; import java.util.Set; public interface UnitService { diff --git a/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java b/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java index 5cb2fff..499e5db 100644 --- a/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java +++ b/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java @@ -5,8 +5,6 @@ import org.sadtech.autoresponder.entity.Unit; import org.sadtech.autoresponder.repository.UnitRepository; import org.sadtech.autoresponder.service.UnitService; -import java.util.ArrayList; -import java.util.List; import java.util.Set; public class UnitServiceImpl implements UnitService {