From ec0049d6027d91c655992c38288b6873cefcd197 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Tue, 5 Feb 2019 21:50:49 +0300 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=BC=D0=B5=D0=BD=D0=B0=20List=20?= =?UTF-8?q?=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(); }