Замена List на Set
В Unit заменил с List на Set поле хранящее следующие юниты
This commit is contained in:
parent
5a8cdef9d9
commit
ec0049d602
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>org.sadtech.autoresponder</groupId>
|
||||
<artifactId>autoresponder</artifactId>
|
||||
<version>1.3.0-RELEASE</version>
|
||||
<version>1.4.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<build>
|
||||
<plugins>
|
||||
|
@ -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,17 +62,20 @@ public class Autoresponder {
|
||||
return person;
|
||||
}
|
||||
|
||||
private Unit nextUnit(List<Unit> nextUnits, String message) {
|
||||
private Unit nextUnit(Set<Unit> nextUnits, String message) {
|
||||
if (nextUnits.size() > 0) {
|
||||
UnitPriorityComparator unitPriorityComparator = new UnitPriorityComparator();
|
||||
Optional<Unit> 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);
|
||||
}
|
||||
}
|
||||
|
||||
if (!patternUnits.isPresent()) {
|
||||
patternUnits = nextUnits.stream().filter(nextUnit -> (nextUnit.getPattern() == null && nextUnit.getKeyWords() == null)).max(unitPriorityComparator);
|
||||
|
@ -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;
|
||||
|
@ -9,14 +9,14 @@ public abstract class Unit {
|
||||
private Pattern pattern;
|
||||
private Integer matchThreshold;
|
||||
private Integer priority;
|
||||
private List<Unit> nextUnits;
|
||||
private Set<Unit> nextUnits;
|
||||
|
||||
public Unit() {
|
||||
priority = 10;
|
||||
matchThreshold = 10;
|
||||
}
|
||||
|
||||
public Unit(Set<String> keyWords, Pattern pattern, Integer matchThreshold, Integer priority, List<Unit> nextUnits) {
|
||||
public Unit(Set<String> keyWords, Pattern pattern, Integer matchThreshold, Integer priority, Set<Unit> 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<Unit> getNextUnits() {
|
||||
public Set<Unit> getNextUnits() {
|
||||
return nextUnits;
|
||||
}
|
||||
|
||||
public void setNextUnits(List<Unit> nextUnits) {
|
||||
public void setNextUnits(Set<Unit> nextUnits) {
|
||||
this.nextUnits = nextUnits;
|
||||
}
|
||||
|
||||
|
@ -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<Unit> units);
|
||||
|
||||
List<Unit> menuUnits();
|
||||
Set<Unit> menuUnits();
|
||||
|
||||
}
|
||||
|
@ -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<Unit> menuUnit();
|
||||
Set<Unit> menuUnit();
|
||||
|
||||
void addUnit(Unit unit);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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<Unit> menuUnit() {
|
||||
public Set<Unit> menuUnit() {
|
||||
return unitRepository.menuUnits();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user