From c5d03ea70ce732e0eabc7ea90b13b8ab95601c07 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 3 Mar 2022 15:15:39 +0300 Subject: Fix *readonly tag --- src/main/java/com/juick/service/TagServiceImpl.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/main/java/com/juick/service/TagServiceImpl.java') diff --git a/src/main/java/com/juick/service/TagServiceImpl.java b/src/main/java/com/juick/service/TagServiceImpl.java index 0bd6bb0c..a5f3241a 100644 --- a/src/main/java/com/juick/service/TagServiceImpl.java +++ b/src/main/java/com/juick/service/TagServiceImpl.java @@ -40,6 +40,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Objects; +import java.util.Set; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -180,9 +181,9 @@ public class TagServiceImpl extends BaseJdbcService implements TagService { @Transactional @Override - public List updateTags(final int mid, final Collection newTags) { - List currentTags = getMessageTags(mid).stream() - .map(TagStats::getTag).collect(Collectors.toList()); + public Set updateTags(final int mid, final Collection newTags) { + Set currentTags = getMessageTags(mid).stream() + .map(TagStats::getTag).collect(Collectors.toSet()); if (CollectionUtils.isEmpty(newTags)) return currentTags; @@ -214,18 +215,18 @@ public class TagServiceImpl extends BaseJdbcService implements TagService { }); return getMessageTags(mid).stream() - .map(TagStats::getTag).collect(Collectors.toList()); + .map(TagStats::getTag).collect(Collectors.toSet()); } @Override - public Pair> fromString(final String txt) { + public Pair> fromString(final String txt) { String firstLine = txt.split("\\n", 2)[0]; Supplier> tagsStream = () -> Arrays.stream(firstLine.split("\\ ")) .takeWhile(t -> t.matches("\\*[^\\s]+|#[^\\s]*[^\\d][^\\s]*")); int tagsLength = tagsStream.get().collect(Collectors.joining(" ")).length(); String body = txt.substring(tagsLength); - List tags = tagsStream.get().map(t -> getTag(t.substring(1), true)) - .distinct().collect(Collectors.toList()); + Set tags = tagsStream.get().map(t -> getTag(t.substring(1), true)) + .distinct().collect(Collectors.toSet()); return Pair.of(body, tags); } -- cgit v1.2.3