aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--juick-server-core/src/main/java/com/juick/service/TagService.java3
-rw-r--r--juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java21
-rw-r--r--juick-www/src/main/java/com/juick/www/WebApp.java2
3 files changed, 8 insertions, 18 deletions
diff --git a/juick-server-core/src/main/java/com/juick/service/TagService.java b/juick-server-core/src/main/java/com/juick/service/TagService.java
index e24cf928..78e8f563 100644
--- a/juick-server-core/src/main/java/com/juick/service/TagService.java
+++ b/juick-server-core/src/main/java/com/juick/service/TagService.java
@@ -23,6 +23,7 @@ import com.juick.server.helpers.TagStats;
import java.util.Collection;
import java.util.List;
+import java.util.stream.Stream;
/**
* Created by aalexeev on 11/13/16.
@@ -32,7 +33,7 @@ public interface TagService {
com.juick.Tag getTag(String tag, boolean autoCreate);
- List<Tag> getTags(String[] tags, boolean autoCreate);
+ List<Tag> getTags(Stream<String> tags, boolean autoCreate);
boolean getTagNoIndex(int tagId);
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<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)
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 a0819ad6..4c706426 100644
--- a/juick-www/src/main/java/com/juick/www/WebApp.java
+++ b/juick-www/src/main/java/com/juick/www/WebApp.java
@@ -125,7 +125,7 @@ public class WebApp implements DisposableBean {
}
return t;
});
- tags = tagService.getTags(tagsList.toArray(String[]::new), true);
+ tags = tagService.getTags(tagsList, true);
while (tags.size() > 5) {
tags.remove(5);
}