From e610c996f0107cf3c9dc489e67c1eaebfeb73551 Mon Sep 17 00:00:00 2001 From: Alexander Alexeev Date: Sun, 13 Nov 2016 23:49:29 +0700 Subject: using TagUtils class --- .../src/main/java/com/juick/server/TagQueries.java | 6 +----- .../com/juick/server/protocol/JuickProtocol.java | 3 ++- .../src/main/java/com/juick/util/TagUtils.java | 24 ++++++++++++++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 server-core/src/main/java/com/juick/util/TagUtils.java (limited to 'server-core') diff --git a/server-core/src/main/java/com/juick/server/TagQueries.java b/server-core/src/main/java/com/juick/server/TagQueries.java index 0e3c0c06..ee9a1e21 100644 --- a/server-core/src/main/java/com/juick/server/TagQueries.java +++ b/server-core/src/main/java/com/juick/server/TagQueries.java @@ -106,7 +106,7 @@ public class TagQueries { return stmt; }, holder); - return holder.getKey().intValue(); + return holder.getKey().intValue(); } public static List getUserTagsAll(JdbcTemplate sql, int uid) { @@ -157,8 +157,4 @@ public class TagQueries { } return Collections.emptyList(); } - public static String toString(List tags) { - return tags.stream().map(t -> " *" + t.getName()) - .collect(Collectors.joining()); - } } diff --git a/server-core/src/main/java/com/juick/server/protocol/JuickProtocol.java b/server-core/src/main/java/com/juick/server/protocol/JuickProtocol.java index 5faddd3a..e9e129a9 100644 --- a/server-core/src/main/java/com/juick/server/protocol/JuickProtocol.java +++ b/server-core/src/main/java/com/juick/server/protocol/JuickProtocol.java @@ -7,6 +7,7 @@ import com.juick.formatters.PlainTextFormatter; import com.juick.json.MessageSerializer; import com.juick.server.*; import com.juick.server.protocol.annotation.UserCommand; +import com.juick.util.TagUtils; import com.juick.xmpp.extensions.JuickMessage; import org.springframework.jdbc.core.JdbcTemplate; @@ -66,7 +67,7 @@ public class JuickProtocol { public ProtocolReply postMessage(User user, String input) { List tags = TagQueries.fromString(sql, input, false); - String body = input.substring(TagQueries.toString(tags).length()); + String body = input.substring(TagUtils.toString(tags).length()); int mid = MessagesQueries.createMessage(sql, user.getUID(), body, null, tags); SubscriptionsQueries.subscribeMessage(sql, mid, user.getUID()); //app.events().publishEvent(new JuickMessageEvent(app.messages().getMessage(mid))); diff --git a/server-core/src/main/java/com/juick/util/TagUtils.java b/server-core/src/main/java/com/juick/util/TagUtils.java new file mode 100644 index 00000000..157522ab --- /dev/null +++ b/server-core/src/main/java/com/juick/util/TagUtils.java @@ -0,0 +1,24 @@ +package com.juick.util; + +import com.juick.Tag; +import org.apache.commons.collections4.CollectionUtils; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * Created by aalexeev on 11/13/16. + */ +public class TagUtils { + private TagUtils() { + throw new IllegalStateException(); + } + + public static String toString(final List tags) { + if (CollectionUtils.isEmpty(tags)) + return ""; + + return tags.stream().map(t -> " *" + t.getName()) + .collect(Collectors.joining()); + } +} -- cgit v1.2.3