diff options
author | Vitaly Takmazov | 2019-03-01 19:17:40 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2019-03-01 19:17:40 +0300 |
commit | aabad2347aaf52e225541cb954e98ab509e9aa2f (patch) | |
tree | 1b7dbc1c59b76dfb9a7a05899f3227d924f6e8cb /src/main/java/com/juick/util | |
parent | 95f489a6f2e6504177ce7b33f29f9bf53344566e (diff) |
Tags refactoring
Diffstat (limited to 'src/main/java/com/juick/util')
-rw-r--r-- | src/main/java/com/juick/util/MessageUtils.java | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/src/main/java/com/juick/util/MessageUtils.java b/src/main/java/com/juick/util/MessageUtils.java index 78899ca2..fa94e978 100644 --- a/src/main/java/com/juick/util/MessageUtils.java +++ b/src/main/java/com/juick/util/MessageUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2017, Juick + * Copyright (C) 2008-2019, Juick * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -28,7 +28,13 @@ import org.springframework.web.util.UriComponentsBuilder; import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URLEncoder; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -299,23 +305,15 @@ public class MessageUtils { public static boolean replyStartsWithQuote(Message msg) { return msg.getRid() > 0 && StringUtils.defaultString(msg.getText()).startsWith(">"); } - public static List<Tag> parseTags(String strTags) { - List<Tag> tags = new ArrayList<>(); - if (StringUtils.isNotEmpty(strTags)) { - Set<Tag> tagSet = new TreeSet<>(tags); - for (String str : strTags.split(" ")) { - Tag tag = new Tag(str); - if (!tagSet.contains(tag)) { - tags.add(tag); - tagSet.add(tag); - } - } - } - return tags; + public static Set<Tag> parseTags(String strTags) { + return StringUtils.isEmpty(strTags) ? Collections.emptySet() + : Arrays.stream(strTags.split(" ")).map(Tag::new) + .collect(Collectors.toCollection(LinkedHashSet::new)); } public static String getTagsString(Message msg) { StringBuilder builder = new StringBuilder(); - List<Tag> tags = msg.getTags(); + Set<Tag> tags = msg.getTags(); + if (!tags.isEmpty()) { for (Tag Tag : tags) builder.append(" *").append(Tag.getName()); |