Move parsing of boolean options into its own method. refactoring
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 26 Mar 2014 18:45:28 +0000 (19:45 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 26 Mar 2014 18:45:28 +0000 (19:45 +0100)
src/main/java/net/pterodactylus/sone/web/OptionsPage.java

index 53c5977..008a1ce 100644 (file)
@@ -61,16 +61,11 @@ public class OptionsPage extends SoneTemplatePage {
                if (request.getMethod() == Method.POST) {
                        List<String> fieldErrors = new ArrayList<String>();
                        if (currentSone != null) {
-                               boolean autoFollow = request.getHttpRequest().isPartSet("auto-follow");
-                               currentSone.getOptions().getBooleanOption("AutoFollow").set(autoFollow);
-                               boolean enableSoneInsertNotifications = request.getHttpRequest().isPartSet("enable-sone-insert-notifications");
-                               currentSone.getOptions().getBooleanOption("EnableSoneInsertNotifications").set(enableSoneInsertNotifications);
-                               boolean showNotificationNewSones = request.getHttpRequest().isPartSet("show-notification-new-sones");
-                               currentSone.getOptions().getBooleanOption("ShowNotification/NewSones").set(showNotificationNewSones);
-                               boolean showNotificationNewPosts = request.getHttpRequest().isPartSet("show-notification-new-posts");
-                               currentSone.getOptions().getBooleanOption("ShowNotification/NewPosts").set(showNotificationNewPosts);
-                               boolean showNotificationNewReplies = request.getHttpRequest().isPartSet("show-notification-new-replies");
-                               currentSone.getOptions().getBooleanOption("ShowNotification/NewReplies").set(showNotificationNewReplies);
+                               setBooleanOption(request, currentSone, "auto-follow", "AutoFollow");
+                               setBooleanOption(request, currentSone, "enable-sone-insert-notifications", "EnableSoneInsertNotifications");
+                               setBooleanOption(request, currentSone, "show-notification-new-sones", "ShowNotification/NewSones");
+                               setBooleanOption(request, currentSone, "show-notification-new-posts", "ShowNotification/NewPosts");
+                               setBooleanOption(request, currentSone, "show-notification-new-replies", "ShowNotification/NewReplies");
                                String showCustomAvatars = request.getHttpRequest().getPartAsStringFailsafe("show-custom-avatars", 32);
                                currentSone.getOptions().<ShowCustomAvatars> getEnumOption("ShowCustomAvatars").set(ShowCustomAvatars.valueOf(showCustomAvatars));
                                webInterface.getCore().touchConfiguration();
@@ -156,4 +151,9 @@ public class OptionsPage extends SoneTemplatePage {
                templateContext.set("fcp-full-access-required", preferences.getFcpFullAccessRequired().ordinal());
        }
 
+       private void setBooleanOption(FreenetRequest request, Sone currentSone, String requestPartName, String optionName) {
+               boolean autoFollow = request.getHttpRequest().isPartSet(requestPartName);
+               currentSone.getOptions().getBooleanOption(optionName).set(autoFollow);
+       }
+
 }