+++ /dev/null
-package net.pterodactylus.sone.core;
-
-import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired;
-import net.pterodactylus.util.config.Configuration;
-import net.pterodactylus.util.config.ConfigurationException;
-
-/**
- * Loads preferences stored in a {@link Configuration} into a {@link
- * Preferences} object.
- */
-public class PreferencesLoader {
-
- private final Preferences preferences;
-
- public PreferencesLoader(Preferences preferences) {
- this.preferences = preferences;
- }
-
- public void loadFrom(Configuration configuration) {
- loadInsertionDelay(configuration);
- loadPostsPerPage(configuration);
- loadImagesPerPage(configuration);
- loadCharactersPerPost(configuration);
- loadPostCutOffLength(configuration);
- loadRequireFullAccess(configuration);
- loadFcpInterfaceActive(configuration);
- loadFcpFullAccessRequired(configuration);
- }
-
- private void loadInsertionDelay(Configuration configuration) {
- preferences.setNewInsertionDelay(configuration.getIntValue(
- "Option/InsertionDelay").getValue(null));
- }
-
- private void loadPostsPerPage(Configuration configuration) {
- preferences.setNewPostsPerPage(
- configuration.getIntValue("Option/PostsPerPage")
- .getValue(null));
- }
-
- private void loadImagesPerPage(Configuration configuration) {
- preferences.setNewImagesPerPage(
- configuration.getIntValue("Option/ImagesPerPage")
- .getValue(null));
- }
-
- private void loadCharactersPerPost(Configuration configuration) {
- preferences.setNewCharactersPerPost(
- configuration.getIntValue("Option/CharactersPerPost")
- .getValue(null));
- }
-
- private void loadPostCutOffLength(Configuration configuration) {
- try {
- preferences.setNewPostCutOffLength(
- configuration.getIntValue("Option/PostCutOffLength")
- .getValue(null));
- } catch (IllegalArgumentException iae1) {
- /* previous versions allowed -1, ignore and use default. */
- }
- }
-
- private void loadRequireFullAccess(Configuration configuration) {
- preferences.setNewRequireFullAccess(
- configuration.getBooleanValue("Option/RequireFullAccess")
- .getValue(null));
- }
-
- private void loadFcpInterfaceActive(Configuration configuration) {
- preferences.setNewFcpInterfaceActive(configuration.getBooleanValue(
- "Option/ActivateFcpInterface").getValue(null));
- }
-
- private void loadFcpFullAccessRequired(Configuration configuration) {
- Integer fullAccessRequiredInteger = configuration
- .getIntValue("Option/FcpFullAccessRequired").getValue(null);
- preferences.setNewFcpFullAccessRequired(
- (fullAccessRequiredInteger == null) ? null :
- FullAccessRequired.values()[fullAccessRequiredInteger]);
- }
-
-}
--- /dev/null
+package net.pterodactylus.sone.core
+
+import net.pterodactylus.sone.fcp.FcpInterface.*
+import net.pterodactylus.util.config.*
+
+/**
+ * Loads preferences stored in a [Configuration] into a [Preferences] object.
+ */
+class PreferencesLoader(private val preferences: Preferences) {
+
+ fun loadFrom(configuration: Configuration) {
+ loadInsertionDelay(configuration)
+ loadPostsPerPage(configuration)
+ loadImagesPerPage(configuration)
+ loadCharactersPerPost(configuration)
+ loadPostCutOffLength(configuration)
+ loadRequireFullAccess(configuration)
+ loadFcpInterfaceActive(configuration)
+ loadFcpFullAccessRequired(configuration)
+ }
+
+ private fun loadInsertionDelay(configuration: Configuration) {
+ preferences.newInsertionDelay = configuration.getIntValue("Option/InsertionDelay").getValue(null)
+ }
+
+ private fun loadPostsPerPage(configuration: Configuration) {
+ preferences.newPostsPerPage = configuration.getIntValue("Option/PostsPerPage").getValue(null)
+ }
+
+ private fun loadImagesPerPage(configuration: Configuration) {
+ preferences.newImagesPerPage = configuration.getIntValue("Option/ImagesPerPage").getValue(null)
+ }
+
+ private fun loadCharactersPerPost(configuration: Configuration) {
+ preferences.newCharactersPerPost = configuration.getIntValue("Option/CharactersPerPost").getValue(null)
+ }
+
+ private fun loadPostCutOffLength(configuration: Configuration) {
+ try {
+ preferences.newPostCutOffLength = configuration.getIntValue("Option/PostCutOffLength").getValue(null)
+ } catch (iae1: IllegalArgumentException) { /* previous versions allowed -1, ignore and use default. */
+ }
+ }
+
+ private fun loadRequireFullAccess(configuration: Configuration) {
+ preferences.newRequireFullAccess = configuration.getBooleanValue("Option/RequireFullAccess").getValue(null)
+ }
+
+ private fun loadFcpInterfaceActive(configuration: Configuration) {
+ preferences.newFcpInterfaceActive = configuration.getBooleanValue("Option/ActivateFcpInterface").getValue(null)
+ }
+
+ private fun loadFcpFullAccessRequired(configuration: Configuration) {
+ val fullAccessRequiredInteger = configuration.getIntValue("Option/FcpFullAccessRequired").getValue(null)
+ preferences.newFcpFullAccessRequired = fullAccessRequiredInteger?.let { FullAccessRequired.values()[it] }
+ }
+
+}