From: David ‘Bombe’ Roden Date: Sun, 7 Sep 2014 13:12:13 +0000 (+0200) Subject: Move parsing the profile to its own method. X-Git-Tag: 0.9-rc1^2~3^2~145 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=791ae7c17d02857541e10a5dd97af65f6f532056 Move parsing the profile to its own method. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 5564c37..ec59c92 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -1108,24 +1108,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, String lastInsertFingerprint = configuration.getStringValue(sonePrefix + "/LastInsertFingerprint").getValue(""); /* load profile. */ - Profile profile = new Profile(sone); - profile.setFirstName(configuration.getStringValue(sonePrefix + "/Profile/FirstName").getValue(null)); - profile.setMiddleName(configuration.getStringValue(sonePrefix + "/Profile/MiddleName").getValue(null)); - profile.setLastName(configuration.getStringValue(sonePrefix + "/Profile/LastName").getValue(null)); - profile.setBirthDay(configuration.getIntValue(sonePrefix + "/Profile/BirthDay").getValue(null)); - profile.setBirthMonth(configuration.getIntValue(sonePrefix + "/Profile/BirthMonth").getValue(null)); - profile.setBirthYear(configuration.getIntValue(sonePrefix + "/Profile/BirthYear").getValue(null)); - - /* load profile fields. */ - while (true) { - String fieldPrefix = sonePrefix + "/Profile/Fields/" + profile.getFields().size(); - String fieldName = configuration.getStringValue(fieldPrefix + "/Name").getValue(null); - if (fieldName == null) { - break; - } - String fieldValue = configuration.getStringValue(fieldPrefix + "/Value").getValue(""); - profile.addField(fieldName).setValue(fieldValue); - } + Profile profile = parseProfileFromConfiguration(configuration, sone, sonePrefix); /* load posts. */ Set posts = new HashSet(); @@ -1308,6 +1291,29 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, logger.info(String.format("Sone loaded successfully: %s", sone)); } + private static Profile parseProfileFromConfiguration(Configuration configuration, Sone sone, String sonePrefix) { + Profile profile = new Profile(sone); + profile.setFirstName(configuration.getStringValue(sonePrefix + "/Profile/FirstName").getValue(null)); + profile.setMiddleName(configuration.getStringValue(sonePrefix + "/Profile/MiddleName").getValue(null)); + profile.setLastName(configuration.getStringValue(sonePrefix + "/Profile/LastName").getValue(null)); + profile.setBirthDay(configuration.getIntValue(sonePrefix + "/Profile/BirthDay").getValue(null)); + profile.setBirthMonth(configuration.getIntValue(sonePrefix + "/Profile/BirthMonth").getValue(null)); + profile.setBirthYear(configuration.getIntValue(sonePrefix + "/Profile/BirthYear").getValue(null)); + + /* load profile fields. */ + while (true) { + String fieldPrefix = sonePrefix + "/Profile/Fields/" + profile.getFields().size(); + String fieldName = configuration.getStringValue(fieldPrefix + "/Name").getValue(null); + if (fieldName == null) { + break; + } + String fieldValue = configuration.getStringValue(fieldPrefix + "/Value").getValue(""); + profile.addField(fieldName).setValue(fieldValue); + } + + return profile; + } + /** * Creates a new post. *