diff options
author | Vitaly Takmazov | 2017-01-12 16:27:01 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-01-12 16:27:01 +0300 |
commit | 49aed3106645dba29d2e6802a706a288d937f1d6 (patch) | |
tree | 95c8a75591395773cb057bf78015433acde26c84 /juick-www/src/main/java/com/juick/www/WebApp.java | |
parent | 14dee26c8785fd23075b6dc884d42d5d3f0176f6 (diff) |
juick-www: fix parsing tags with duplicates
Diffstat (limited to 'juick-www/src/main/java/com/juick/www/WebApp.java')
-rw-r--r-- | juick-www/src/main/java/com/juick/www/WebApp.java | 20 |
1 files changed, 11 insertions, 9 deletions
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<Tag> parseTags(String tagsStr) { List<Tag> 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<String> 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); } |