From 0f2dce2a50b5868f17ccd35e6c5da74da7e4f808 Mon Sep 17 00:00:00 2001 From: Anatoliy Sablin Date: Wed, 18 Oct 2017 23:52:10 +0300 Subject: Simplified the code. --- .../main/java/com/juick/service/TagServiceImpl.java | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'juick-server-jdbc/src/main/java/com') 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 79163d1c..9b89bca3 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 getTags(final String[] tags, final boolean autoCreate) { - if (ArrayUtils.isEmpty(tags)) - return Collections.emptyList(); - - List 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 getTags(Stream tags, final boolean autoCreate) { + return tags.filter(StringUtils::isNotBlank).map(tag -> getTag(tag, autoCreate)).filter(Objects::nonNull).distinct() + .collect(Collectors.toList()); } @Transactional(readOnly = true) -- cgit v1.2.3