From 49aed3106645dba29d2e6802a706a288d937f1d6 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 12 Jan 2017 16:27:01 +0300 Subject: juick-www: fix parsing tags with duplicates --- juick-www/src/main/java/com/juick/www/WebApp.java | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'juick-www/src/main/java') diff --git a/juick-www/src/main/java/com/juick/www/WebApp.java b/juick-www/src/main/java/com/juick/www/WebApp.java index 85ae64d4..2f73229e 100644 --- a/juick-www/src/main/java/com/juick/www/WebApp.java +++ b/juick-www/src/main/java/com/juick/www/WebApp.java @@ -40,8 +40,10 @@ import ru.sape.Sape; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Objects; +import java.util.stream.Stream; /** * @@ -133,18 +135,18 @@ public class WebApp implements AutoCloseable { public List parseTags(String tagsStr) { List tags = new ArrayList<>(); - String tagsArr[]; if (tagsStr != null && !tagsStr.isEmpty()) { - tagsArr = tagsStr.split("[ \\,]"); - for (int i = 0; i < tagsArr.length; i++) { - if (tagsArr[i].startsWith("*")) { - tagsArr[i] = tagsArr[i].substring(1); + Stream tagsList = Arrays.stream(tagsStr.split("[ \\,]")) + .distinct().map( t -> { + if (t.startsWith("*")) { + t = t.substring(1); } - if (tagsArr[i].length() > 64) { - tagsArr[i] = tagsArr[i].substring(0, 64); + if (t.length() > 64) { + t = t.substring(0, 64); } - } - tags = tagService.getTags(tagsArr, true); + return t; + }); + tags = tagService.getTags(tagsList.toArray(String[]::new), true); while (tags.size() > 5) { tags.remove(5); } -- cgit v1.2.3