From a92d71ef3ee8b2db6c33443e9cb27830959f3a9a Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Thu, 31 Jan 2019 08:50:39 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=85=D0=BE=D0=B4=20?= =?UTF-8?q?=D0=BD=D0=B0=20Gson=20=D0=B2=D0=BC=D0=B5=D1=81=D1=82=D0=BE=20?= =?UTF-8?q?=D0=BD=D0=B5=D0=BF=D0=BE=D0=BD=D1=8F=D1=82=D0=BD=D0=BE=D0=B9=20?= =?UTF-8?q?Json=20=D0=B1=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE=D1=82=D0=B5=D0=BA?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 ------ .../distribution/impl/MailSubscriber.java | 2 +- .../distribution/impl/TerminalSubscriber.java | 6 +++--- .../vkbot/core/keyboard/ButtonKeyBoard.java | 20 +++++++++---------- .../sadtech/vkbot/core/keyboard/KeyBoard.java | 16 +++++++-------- .../vkbot/core/keyboard/LineKeyBoard.java | 8 ++++---- 6 files changed, 26 insertions(+), 32 deletions(-) diff --git a/pom.xml b/pom.xml index 69c1e4f..89e23b0 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,6 @@ 2.8.5 0.5.13-SNAPSHOT 1.2.17 - 20180813 @@ -51,11 +50,6 @@ log4j ${log4j.ver} - - org.json - json - ${json.ver} - junit junit diff --git a/src/main/java/org/sadtech/vkbot/core/distribution/impl/MailSubscriber.java b/src/main/java/org/sadtech/vkbot/core/distribution/impl/MailSubscriber.java index 0d2dcee..debb99d 100644 --- a/src/main/java/org/sadtech/vkbot/core/distribution/impl/MailSubscriber.java +++ b/src/main/java/org/sadtech/vkbot/core/distribution/impl/MailSubscriber.java @@ -20,7 +20,7 @@ public class MailSubscriber implements EventSubscribe, EventDistribu private MailService mailService; private Set admins = new HashSet<>(); - private Map eventDistributionMap = new HashMap<>(); + private Map> eventDistributionMap = new HashMap<>(); public MailSubscriber(EventDistributable eventDistributable, MailService mailService) { this.mailService = mailService; diff --git a/src/main/java/org/sadtech/vkbot/core/distribution/impl/TerminalSubscriber.java b/src/main/java/org/sadtech/vkbot/core/distribution/impl/TerminalSubscriber.java index d0ce956..2ef8efb 100644 --- a/src/main/java/org/sadtech/vkbot/core/distribution/impl/TerminalSubscriber.java +++ b/src/main/java/org/sadtech/vkbot/core/distribution/impl/TerminalSubscriber.java @@ -1,11 +1,11 @@ package org.sadtech.vkbot.core.distribution.impl; +import com.vk.api.sdk.objects.messages.Message; import org.apache.log4j.Logger; import org.sadtech.vkbot.core.distribution.EventSubscribe; -import org.sadtech.vkbot.core.entity.Mail; import org.sadtech.vkbot.core.service.handlers.MailService; -public class TerminalSubscriber implements EventSubscribe { +public class TerminalSubscriber implements EventSubscribe { public static final Logger log = Logger.getLogger(TerminalSubscriber.class); @@ -25,7 +25,7 @@ public class TerminalSubscriber implements EventSubscribe { } @Override - public void update(Mail object) { + public void update(Message object) { log.info("Сообщение отправленно на добавление в репозиторий команд"); mailService.add(object); } diff --git a/src/main/java/org/sadtech/vkbot/core/keyboard/ButtonKeyBoard.java b/src/main/java/org/sadtech/vkbot/core/keyboard/ButtonKeyBoard.java index d33d139..fa9612f 100644 --- a/src/main/java/org/sadtech/vkbot/core/keyboard/ButtonKeyBoard.java +++ b/src/main/java/org/sadtech/vkbot/core/keyboard/ButtonKeyBoard.java @@ -1,6 +1,6 @@ package org.sadtech.vkbot.core.keyboard; -import org.json.JSONObject; +import com.google.gson.JsonObject; public class ButtonKeyBoard { @@ -20,18 +20,18 @@ public class ButtonKeyBoard { this.color = color; } - public JSONObject getButton() { - JSONObject newButton = new JSONObject(); - newButton.put("color", color.toString().toLowerCase()); - newButton.put("action", generateAction()); + public JsonObject getButton() { + JsonObject newButton = new JsonObject(); + newButton.addProperty("color", color.toString().toLowerCase()); + newButton.add("action", generateAction()); return newButton; } - private JSONObject generateAction() { - JSONObject action = new JSONObject(); - action.put("type", type); - action.put("payload", payload); - action.put("label", label); + private JsonObject generateAction() { + JsonObject action = new JsonObject(); + action.addProperty("type", type); + action.addProperty("payload", payload); + action.addProperty("label", label); return action; } diff --git a/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoard.java b/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoard.java index 4037f3d..08cdf86 100644 --- a/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoard.java +++ b/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoard.java @@ -1,7 +1,7 @@ package org.sadtech.vkbot.core.keyboard; -import org.json.JSONArray; -import org.json.JSONObject; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; import java.util.ArrayList; import java.util.List; @@ -24,16 +24,16 @@ public class KeyBoard { this.oneTime = oneTime; } - public JSONObject getKeyboard() { - JSONObject keyboard = new JSONObject(); - keyboard.put("one_time", oneTime); + public JsonObject getKeyboard() { + JsonObject keyboard = new JsonObject(); + keyboard.addProperty("one_time", oneTime); - JSONArray menuLine = new JSONArray(); + JsonArray menuLine = new JsonArray(); for (LineKeyBoard lineKeyboard : lineKeyBoards) { - menuLine.put(lineKeyboard.getLine()); + menuLine.add(lineKeyboard.getLine()); } - keyboard.put("buttons", menuLine); + keyboard.add("buttons", menuLine); return keyboard; } diff --git a/src/main/java/org/sadtech/vkbot/core/keyboard/LineKeyBoard.java b/src/main/java/org/sadtech/vkbot/core/keyboard/LineKeyBoard.java index 0f8cdc1..6b28849 100644 --- a/src/main/java/org/sadtech/vkbot/core/keyboard/LineKeyBoard.java +++ b/src/main/java/org/sadtech/vkbot/core/keyboard/LineKeyBoard.java @@ -1,6 +1,6 @@ package org.sadtech.vkbot.core.keyboard; -import org.json.JSONArray; +import com.google.gson.JsonArray; import java.util.ArrayList; import java.util.List; @@ -17,10 +17,10 @@ public class LineKeyBoard { this.buttonKeyBoards = buttonKeyBoards; } - public JSONArray getLine() { - JSONArray line = new JSONArray(); + public JsonArray getLine() { + JsonArray line = new JsonArray(); for (ButtonKeyBoard buttonKeyBoard : buttonKeyBoards) { - line.put(buttonKeyBoard.getButton()); + line.add(buttonKeyBoard.getButton()); } return line; }