From 85abc3e201539f81500754a7fb0e4f3a9d148fc4 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 25 Sep 2018 10:28:54 +0300 Subject: fix new message tags extracting --- .../src/main/java/com/juick/service/TagServiceImpl.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'juick-server/src/main/java/com/juick') diff --git a/juick-server/src/main/java/com/juick/service/TagServiceImpl.java b/juick-server/src/main/java/com/juick/service/TagServiceImpl.java index 3ee21aec..aa6c3713 100644 --- a/juick-server/src/main/java/com/juick/service/TagServiceImpl.java +++ b/juick-server/src/main/java/com/juick/service/TagServiceImpl.java @@ -23,6 +23,7 @@ import com.juick.server.helpers.TagStats; import com.juick.util.StreamUtils; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.Pair; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.support.GeneratedKeyHolder; @@ -38,8 +39,8 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Objects; +import java.util.function.Supplier; import java.util.stream.Collectors; -import java.util.stream.IntStream; import java.util.stream.Stream; /** @@ -209,12 +210,15 @@ public class TagServiceImpl extends BaseJdbcService implements TagService { } @Override - public List fromString(final String txt) { + public Pair> fromString(final String txt) { String firstLine = txt.split("\\n", 2)[0]; - return StreamUtils.takeWhile(Arrays.stream(firstLine.split("\\ ")), - t -> !t.equals("*") && t.startsWith("*")) - .map(t -> getTag(t.substring(1), true)) + Supplier> tagsStream = () -> StreamUtils.takeWhile(Arrays.stream(firstLine.split("\\ ")), + t -> !t.equals("*") && t.startsWith("*")); + 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()); + return Pair.of(body, tags); } @Transactional(readOnly = true) -- cgit v1.2.3