From 2015cbe8ae41dc85b796c4cba9bee75b8d44f636 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 15 Nov 2010 06:49:23 +0100 Subject: [PATCH] Move JSON object creation into its own method. --- .../sone/web/ajax/GetNotificationsAjaxPage.java | 29 ++++++++++++++++------ 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.java index de2f8f8..f46351c 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.java @@ -56,13 +56,7 @@ public class GetNotificationsAjaxPage extends JsonPage { JsonObject result = createSuccessJsonObject(); JsonArray jsonNotifications = new JsonArray(); for (Notification notification : notifications) { - JsonObject jsonNotification = new JsonObject(); - jsonNotification.put("id", notification.getId()); - jsonNotification.put("text", notification.toString()); - jsonNotification.put("createdTime", notification.getCreatedTime()); - jsonNotification.put("lastUpdatedTime", notification.getLastUpdatedTime()); - jsonNotification.put("dismissable", notification.isDismissable()); - jsonNotifications.add(jsonNotification); + jsonNotifications.add(createJsonNotification(notification)); } return result.put("notifications", jsonNotifications); } @@ -75,4 +69,25 @@ public class GetNotificationsAjaxPage extends JsonPage { return false; } + // + // PRIVATE METHODS + // + + /** + * Creates a JSON object from the given notification. + * + * @param notification + * The notification to create a JSON object + * @return The JSON object + */ + private static JsonObject createJsonNotification(Notification notification) { + JsonObject jsonNotification = new JsonObject(); + jsonNotification.put("id", notification.getId()); + jsonNotification.put("text", notification.toString()); + jsonNotification.put("createdTime", notification.getCreatedTime()); + jsonNotification.put("lastUpdatedTime", notification.getLastUpdatedTime()); + jsonNotification.put("dismissable", notification.isDismissable()); + return jsonNotification; + } + } -- 2.7.4