Рефакторинг SwitchUnit
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Struchkov Mark 2023-04-15 12:56:15 +03:00
parent b98fa02f17
commit 420c700581
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6

View File

@ -3,19 +3,12 @@ package dev.struchkov.godfather.quarkus.domain.unit;
import dev.struchkov.godfather.main.domain.content.Message; import dev.struchkov.godfather.main.domain.content.Message;
import dev.struchkov.godfather.main.domain.unit.KeyWord; import dev.struchkov.godfather.main.domain.unit.KeyWord;
import dev.struchkov.godfather.main.domain.unit.UnitActiveType; import dev.struchkov.godfather.main.domain.unit.UnitActiveType;
import dev.struchkov.godfather.quarkus.domain.BoxAnswer;
import dev.struchkov.godfather.quarkus.domain.unit.func.CallBackConsumer;
import dev.struchkov.godfather.quarkus.domain.unit.func.ProcessingData;
import dev.struchkov.godfather.quarkus.domain.unit.func.UniPredicate; import dev.struchkov.godfather.quarkus.domain.unit.func.UniPredicate;
import io.smallrye.mutiny.Uni;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -36,7 +29,7 @@ public class SwitchUnit<M extends Message> extends MainUnit<M> {
builder.description, builder.description,
TYPE, TYPE,
builder.activeType, builder.activeType,
builder.notSaveHistory true
); );
} }
@ -59,10 +52,6 @@ public class SwitchUnit<M extends Message> extends MainUnit<M> {
private Integer priority; private Integer priority;
private UnitActiveType activeType; private UnitActiveType activeType;
private boolean notSaveHistory;
private ProcessingData<M> boxAnswer;
private CallBackConsumer callBack;
private Builder() { private Builder() {
} }
@ -77,29 +66,6 @@ public class SwitchUnit<M extends Message> extends MainUnit<M> {
return this; return this;
} }
public SwitchUnit.Builder<M> answer(Consumer<M> answer) {
this.boxAnswer = message -> {
answer.accept(message);
return Uni.createFrom().nullItem();
};
return this;
}
public SwitchUnit.Builder<M> answer(Function<M, Uni<BoxAnswer>> answer) {
this.boxAnswer = answer::apply;
return this;
}
public SwitchUnit.Builder<M> answer(Supplier<BoxAnswer> answer) {
this.boxAnswer = message -> Uni.createFrom().item(answer.get());
return this;
}
public SwitchUnit.Builder<M> callBack(CallBackConsumer callBack) {
this.callBack = callBack;
return this;
}
public SwitchUnit.Builder<M> triggerWords(Set<KeyWord> val) { public SwitchUnit.Builder<M> triggerWords(Set<KeyWord> val) {
if (triggerWords == null) { if (triggerWords == null) {
triggerWords = new HashSet<>(); triggerWords = new HashSet<>();
@ -181,11 +147,6 @@ public class SwitchUnit<M extends Message> extends MainUnit<M> {
return this; return this;
} }
public SwitchUnit.Builder<M> notSaveHistory() {
notSaveHistory = true;
return this;
}
public SwitchUnit.Builder<M> activeType(UnitActiveType val) { public SwitchUnit.Builder<M> activeType(UnitActiveType val) {
activeType = val; activeType = val;
return this; return this;