Move JSON object creation into its own method.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 15 Nov 2010 05:49:23 +0000 (06:49 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 15 Nov 2010 05:49:23 +0000 (06:49 +0100)
src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.java

index de2f8f8..f46351c 100644 (file)
@@ -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;
+       }
+
 }