diff --git a/pom.xml b/pom.xml index ade279e..2dac002 100644 --- a/pom.xml +++ b/pom.xml @@ -42,18 +42,12 @@ - 1.7.26 4.12 - 1.18.6 + 1.18.12 + 1.7.30 - - org.slf4j - slf4j-api - ${slf4j.ver} - - junit junit @@ -65,6 +59,12 @@ lombok ${lombok.ver} + + + org.slf4j + slf4j-api + ${slf4j.ver} + diff --git a/src/main/java/org/sadtech/autoresponder/AutoResponder.java b/src/main/java/org/sadtech/autoresponder/AutoResponder.java index 7292c0c..e309b74 100644 --- a/src/main/java/org/sadtech/autoresponder/AutoResponder.java +++ b/src/main/java/org/sadtech/autoresponder/AutoResponder.java @@ -9,6 +9,7 @@ import org.sadtech.autoresponder.entity.Unit; import org.sadtech.autoresponder.entity.UnitPointer; import org.sadtech.autoresponder.service.UnitPointerService; import org.sadtech.autoresponder.util.Description; +import org.sadtech.autoresponder.util.Message; import org.sadtech.autoresponder.util.Parser; import java.util.HashSet; @@ -115,10 +116,10 @@ public class AutoResponder { if (keyWords != null && !keyWords.isEmpty()) { Set temp = new HashSet<>(keyWords); temp.retainAll(words); - log.info("Ключевые слова юнита: {} ({})", keyWords, keyWords.size()); - log.info("Ключевые слова от пользователя: {}", words); - log.info("Пересечение: {} ({})", temp, temp.size()); - log.info("Процент: {} Необходимо: {}", (double) temp.size() / (double) keyWords.size() * 100.0, unit.getMatchThreshold()); + log.trace(Message.UNIT_KEYWORDS, keyWords, keyWords.size()); + log.trace(Message.USER_MESSAGE_KEYWORDS, words); + log.trace(Message.INTERSECTION, temp, temp.size()); + log.trace(Message.CROSSING_PERCENTAGE, (double) temp.size() / (double) keyWords.size() * 100.0, unit.getMatchThreshold()); return (double) temp.size() / (double) keyWords.size() * 100.0; } else { return 0.0; diff --git a/src/main/java/org/sadtech/autoresponder/compare/UnitPriorityComparator.java b/src/main/java/org/sadtech/autoresponder/compare/UnitPriorityComparator.java index 7b13c47..dc8785e 100644 --- a/src/main/java/org/sadtech/autoresponder/compare/UnitPriorityComparator.java +++ b/src/main/java/org/sadtech/autoresponder/compare/UnitPriorityComparator.java @@ -12,13 +12,8 @@ import java.util.Comparator; public class UnitPriorityComparator implements Comparator { @Override - public int compare(Unit o1, Unit o2) { - if (o1.getPriority() < o2.getPriority()) { - return -1; - } else if (o1.getPriority().equals(o2.getPriority())) { - return 0; - } - return 1; + public int compare(Unit unit1, Unit unit2) { + return Integer.compare(unit1.getPriority(), unit2.getPriority()); } } diff --git a/src/main/java/org/sadtech/autoresponder/entity/Unit.java b/src/main/java/org/sadtech/autoresponder/entity/Unit.java index fffbb84..34f3788 100644 --- a/src/main/java/org/sadtech/autoresponder/entity/Unit.java +++ b/src/main/java/org/sadtech/autoresponder/entity/Unit.java @@ -6,7 +6,6 @@ import lombok.Setter; import lombok.ToString; import org.sadtech.autoresponder.util.Description; -import java.util.Optional; import java.util.Set; import java.util.regex.Pattern; @@ -48,8 +47,8 @@ public abstract class Unit { this.keyWords = keyWords; this.phrase = phrase; this.pattern = pattern; - this.matchThreshold = Optional.ofNullable(matchThreshold).orElse(10); - this.priority = Optional.ofNullable(priority).orElse(10); + this.matchThreshold = matchThreshold == null ? 10 : matchThreshold; + this.priority = priority == null ? 10 : matchThreshold; this.nextUnits = nextUnits; } diff --git a/src/main/java/org/sadtech/autoresponder/service/UnitPointerService.java b/src/main/java/org/sadtech/autoresponder/service/UnitPointerService.java index 3c114fd..3089bd4 100644 --- a/src/main/java/org/sadtech/autoresponder/service/UnitPointerService.java +++ b/src/main/java/org/sadtech/autoresponder/service/UnitPointerService.java @@ -15,14 +15,6 @@ public interface UnitPointerService { void save(@NonNull UnitPointer unitPointer); - /** - * Проверка наличия {@link UnitPointer} для пользователя - * - * @param entityId Идентификатор пользователя - * @return true - если найдено - */ - boolean existsByEntityId(@NonNull Long entityId); - Optional> getByEntityId(@NonNull Long entityId); void removeByEntityId(@NonNull Long entityId); diff --git a/src/main/java/org/sadtech/autoresponder/service/UnitPointerServiceImpl.java b/src/main/java/org/sadtech/autoresponder/service/UnitPointerServiceImpl.java index b42c053..3248556 100644 --- a/src/main/java/org/sadtech/autoresponder/service/UnitPointerServiceImpl.java +++ b/src/main/java/org/sadtech/autoresponder/service/UnitPointerServiceImpl.java @@ -31,9 +31,4 @@ public class UnitPointerServiceImpl implements UnitPointerServic log.trace("Пользователь отправлен в репозиторий"); } - @Override - public boolean existsByEntityId(@NonNull Long entityId) { - return unitPointerRepository.findByEntityId(entityId).isPresent(); - } - } diff --git a/src/main/java/org/sadtech/autoresponder/util/Message.java b/src/main/java/org/sadtech/autoresponder/util/Message.java index 28e764b..a36fa8d 100644 --- a/src/main/java/org/sadtech/autoresponder/util/Message.java +++ b/src/main/java/org/sadtech/autoresponder/util/Message.java @@ -5,9 +5,13 @@ package org.sadtech.autoresponder.util; * * @author upagge [22.08.2019] */ -final class Message { +public final class Message { static final String UTILITY_CLASS = "Клас утилита"; + public static final String UNIT_KEYWORDS = "Ключевые слова юнита: {} ({})"; + public static final String USER_MESSAGE_KEYWORDS = "Ключевые слова от пользователя: {}"; + public static final String INTERSECTION = "Пересечение: {} ({})"; + public static final String CROSSING_PERCENTAGE = "Процент: {} Необходимо: {}"; private Message() { throw new IllegalStateException(UTILITY_CLASS); diff --git a/src/main/java/org/sadtech/autoresponder/util/Parser.java b/src/main/java/org/sadtech/autoresponder/util/Parser.java index f11c9fd..260da36 100644 --- a/src/main/java/org/sadtech/autoresponder/util/Parser.java +++ b/src/main/java/org/sadtech/autoresponder/util/Parser.java @@ -16,15 +16,18 @@ import static org.sadtech.autoresponder.util.Message.UTILITY_CLASS; public class Parser { @Description("Множество предлогов") - private static final Set pretexts = Collections.unmodifiableSet(new HashSet<>(Arrays.asList("в", "без", "до", "из", "к", "на", "по", "о", "от", "перед", "при", "с", "у", "за", "над", "об", - "под", "про", "для"))); + private static final Set pretexts = Collections.unmodifiableSet( + new HashSet<>(Arrays.asList( + "в", "без", "до", "из", "к", "на", "по", "о", "от", "перед", "при", "с", "у", "за", "над", "об", + "под", "про", "для" + ))); private Parser() { throw new IllegalStateException(UTILITY_CLASS); } /** - * Метод по разбиению строки на множество слов + * Метод по разбиению строки на множество слов. * * @param text Строка * @return Множество слов