diff options
author | Anatoliy Sablin | 2017-10-18 23:52:10 +0300 |
---|---|---|
committer | Anatoliy Sablin | 2017-10-18 23:52:10 +0300 |
commit | 0f2dce2a50b5868f17ccd35e6c5da74da7e4f808 (patch) | |
tree | d9d2b748281036faa24a944854b779b18a7fd2f5 /juick-server-jdbc | |
parent | 89fccaa90b823ea924eb6d2b54fcaf40a0e3bc34 (diff) |
Simplified the code.
Diffstat (limited to 'juick-server-jdbc')
-rw-r--r-- | juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java index 79163d1cd..9b89bca31 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java @@ -41,9 +41,11 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * Created by aalexeev on 11/13/16. @@ -108,22 +110,9 @@ public class TagServiceImpl extends BaseJdbcService implements TagService { } @Override - public List<Tag> getTags(final String[] tags, final boolean autoCreate) { - if (ArrayUtils.isEmpty(tags)) - return Collections.emptyList(); - - List<Tag> ret = new ArrayList<>(); - - for (String tag : tags) { - if (!tag.isEmpty()) { - Tag t = getTag(tag, autoCreate); - - if (t != null) - ret.add(t); - } - } - - return ret.stream().distinct().collect(Collectors.toList()); + public List<Tag> getTags(Stream<String> tags, final boolean autoCreate) { + return tags.filter(StringUtils::isNotBlank).map(tag -> getTag(tag, autoCreate)).filter(Objects::nonNull).distinct() + .collect(Collectors.toList()); } @Transactional(readOnly = true) |