diff --git a/src/main/java/com/github/agadar/nationstates/domain/worldassembly/Resolution.java b/src/main/java/com/github/agadar/nationstates/domain/worldassembly/Resolution.java index a0beb43..b471f77 100644 --- a/src/main/java/com/github/agadar/nationstates/domain/worldassembly/Resolution.java +++ b/src/main/java/com/github/agadar/nationstates/domain/worldassembly/Resolution.java @@ -27,8 +27,8 @@ public class Resolution { public String category; /** - * Which council this resolution was send to. Has no value if this resolution - * is currently at vote. + * Which council this resolution was send to. Has no value if this + * resolution is currently at vote. */ @XmlElement(name = "COUNCIL") @XmlJavaTypeAdapter(Council.Adapter.class) diff --git a/src/main/java/com/github/agadar/nationstates/enumerator/Authority.java b/src/main/java/com/github/agadar/nationstates/enumerator/Authority.java index f177c59..f56c419 100644 --- a/src/main/java/com/github/agadar/nationstates/enumerator/Authority.java +++ b/src/main/java/com/github/agadar/nationstates/enumerator/Authority.java @@ -25,12 +25,13 @@ public enum Authority { /** * Reverse mapping. */ - private final static Map CHARS_TO_ENUMS = new HashMap<>(); + private final static Map CHARS_TO_ENUMS; /** * Static init for filling the reverse mapping. */ static { + CHARS_TO_ENUMS = new HashMap<>(); for (Authority auth : values()) { CHARS_TO_ENUMS.put(auth.toChar(), auth); } diff --git a/src/main/java/com/github/agadar/nationstates/enumerator/CensusId.java b/src/main/java/com/github/agadar/nationstates/enumerator/CensusId.java index 260b525..509800b 100644 --- a/src/main/java/com/github/agadar/nationstates/enumerator/CensusId.java +++ b/src/main/java/com/github/agadar/nationstates/enumerator/CensusId.java @@ -100,12 +100,13 @@ public enum CensusId { /** * Map for reverse look-up via id. */ - private final static Map INTS_TO_ENUMS = new HashMap<>(); + private final static Map INTS_TO_ENUMS; /** * Static 'constructor' for filling the reverse map. */ static { + INTS_TO_ENUMS = new HashMap<>(); for (CensusId censusId : values()) { INTS_TO_ENUMS.put(censusId.id, censusId); } diff --git a/src/main/java/com/github/agadar/nationstates/enumerator/DelegateAction.java b/src/main/java/com/github/agadar/nationstates/enumerator/DelegateAction.java index 86b0378..a1bdb83 100644 --- a/src/main/java/com/github/agadar/nationstates/enumerator/DelegateAction.java +++ b/src/main/java/com/github/agadar/nationstates/enumerator/DelegateAction.java @@ -25,12 +25,13 @@ public enum DelegateAction { /** * Map for reverse look-up. */ - private final static Map STRINGS_TO_ENUMS = new HashMap<>(); + private final static Map STRINGS_TO_ENUMS; /** * Static 'constructor' for filling the reverse map. */ static { + STRINGS_TO_ENUMS = new HashMap<>(); for (DelegateAction delegateAction : values()) { STRINGS_TO_ENUMS.put(delegateAction.stringValue, delegateAction); } diff --git a/src/main/java/com/github/agadar/nationstates/enumerator/DispatchCategory.java b/src/main/java/com/github/agadar/nationstates/enumerator/DispatchCategory.java index b13acc6..8fe48b4 100644 --- a/src/main/java/com/github/agadar/nationstates/enumerator/DispatchCategory.java +++ b/src/main/java/com/github/agadar/nationstates/enumerator/DispatchCategory.java @@ -24,12 +24,13 @@ public enum DispatchCategory { /** * Map for reverse look-up. */ - private final static Map STRINGS_TO_ENUMS = new HashMap<>(); + private final static Map STRINGS_TO_ENUMS; /** * Static 'constructor' for filling the reverse map. */ static { + STRINGS_TO_ENUMS = new HashMap<>(); for (DispatchCategory dispatchCategory : values()) { STRINGS_TO_ENUMS.put(dispatchCategory.stringValue, dispatchCategory); } diff --git a/src/main/java/com/github/agadar/nationstates/enumerator/DispatchSubCategory.java b/src/main/java/com/github/agadar/nationstates/enumerator/DispatchSubCategory.java index 0323abb..987a754 100644 --- a/src/main/java/com/github/agadar/nationstates/enumerator/DispatchSubCategory.java +++ b/src/main/java/com/github/agadar/nationstates/enumerator/DispatchSubCategory.java @@ -50,12 +50,13 @@ public enum DispatchSubCategory { /** * Map for reverse look-up. */ - private final static Map STRINGS_TO_ENUMS = new HashMap<>(); + private final static Map STRINGS_TO_ENUMS; /** * Static 'constructor' for filling the reverse map. */ static { + STRINGS_TO_ENUMS = new HashMap<>(); for (DispatchSubCategory dispatchSubCategory : values()) { STRINGS_TO_ENUMS.put(dispatchSubCategory.stringValue, dispatchSubCategory); } diff --git a/src/main/java/com/github/agadar/nationstates/enumerator/EmbassiesRmbPermissions.java b/src/main/java/com/github/agadar/nationstates/enumerator/EmbassiesRmbPermissions.java index d36ca68..da2c6b2 100644 --- a/src/main/java/com/github/agadar/nationstates/enumerator/EmbassiesRmbPermissions.java +++ b/src/main/java/com/github/agadar/nationstates/enumerator/EmbassiesRmbPermissions.java @@ -22,12 +22,13 @@ public enum EmbassiesRmbPermissions { /** * Reverse mapping. */ - private final static Map STRINGS_TO_ENUMS = new HashMap<>(); + private final static Map STRINGS_TO_ENUMS; /** * Static init for filling the reverse mapping. */ static { + STRINGS_TO_ENUMS = new HashMap<>(); for (EmbassiesRmbPermissions status : values()) { STRINGS_TO_ENUMS.put(status.toString(), status); } diff --git a/src/main/java/com/github/agadar/nationstates/enumerator/EmbassyStatus.java b/src/main/java/com/github/agadar/nationstates/enumerator/EmbassyStatus.java index 67a8f5e..ccb0f14 100644 --- a/src/main/java/com/github/agadar/nationstates/enumerator/EmbassyStatus.java +++ b/src/main/java/com/github/agadar/nationstates/enumerator/EmbassyStatus.java @@ -23,12 +23,13 @@ public enum EmbassyStatus { /** * Reverse mapping. */ - private final static Map STRINGS_TO_ENUMS = new HashMap<>(); + private final static Map STRINGS_TO_ENUMS; /** * Static init for filling the reverse mapping. */ static { + STRINGS_TO_ENUMS = new HashMap<>(); for (EmbassyStatus status : values()) { STRINGS_TO_ENUMS.put(status.toString(), status); } diff --git a/src/main/java/com/github/agadar/nationstates/enumerator/RegionTag.java b/src/main/java/com/github/agadar/nationstates/enumerator/RegionTag.java index 7806128..71b5c30 100644 --- a/src/main/java/com/github/agadar/nationstates/enumerator/RegionTag.java +++ b/src/main/java/com/github/agadar/nationstates/enumerator/RegionTag.java @@ -112,12 +112,13 @@ public enum RegionTag { /** * Map for reverse look-up. */ - private final static Map STRINGS_TO_ENUMS = new HashMap<>(); + private final static Map STRINGS_TO_ENUMS; /** * Static 'constructor' for filling the reverse map. */ static { + STRINGS_TO_ENUMS = new HashMap<>(); for (RegionTag regionTag : values()) { STRINGS_TO_ENUMS.put(regionTag.stringValue, regionTag); } @@ -130,13 +131,14 @@ public String toString() { /** * Returns the RegionTag represented by the supplied string. - * Case-insensitive, and whitespaces are interpreted as underscores. + * Case-insensitive, and whitespaces are interpreted as underscores. Colons + * (':') are ignored. * * @param stringValue the supplied string. * @return the RegionTag represented by the supplied string. */ public static RegionTag fromString(String stringValue) { - stringValue = stringValue.toLowerCase().replace(' ', '_'); + stringValue = stringValue.toLowerCase().replace(' ', '_').replace(":", ""); if (!STRINGS_TO_ENUMS.containsKey(stringValue)) { throw new IllegalArgumentException("'" + stringValue + "' cannot be parsed to this enum"); diff --git a/src/main/java/com/github/agadar/nationstates/enumerator/RegionalMessageStatus.java b/src/main/java/com/github/agadar/nationstates/enumerator/RegionalMessageStatus.java index 8a99f44..e023c06 100644 --- a/src/main/java/com/github/agadar/nationstates/enumerator/RegionalMessageStatus.java +++ b/src/main/java/com/github/agadar/nationstates/enumerator/RegionalMessageStatus.java @@ -25,12 +25,13 @@ public enum RegionalMessageStatus { /** * Map for reverse look-up. */ - private final static Map INTS_TO_ENUMS = new HashMap<>(); + private final static Map INTS_TO_ENUMS; /** * Static 'constructor' for filling the reverse map. */ static { + INTS_TO_ENUMS = new HashMap<>(); for (RegionalMessageStatus regionalMessageStatus : values()) { INTS_TO_ENUMS.put(regionalMessageStatus.intValue, regionalMessageStatus); } diff --git a/src/main/java/com/github/agadar/nationstates/enumerator/WorldAssemblyStatus.java b/src/main/java/com/github/agadar/nationstates/enumerator/WorldAssemblyStatus.java index 7e856dc..9fa088a 100644 --- a/src/main/java/com/github/agadar/nationstates/enumerator/WorldAssemblyStatus.java +++ b/src/main/java/com/github/agadar/nationstates/enumerator/WorldAssemblyStatus.java @@ -19,12 +19,13 @@ public enum WorldAssemblyStatus { /** * Reverse mapping. */ - private final static Map STRINGS_TO_ENUMS = new HashMap<>(); + private final static Map STRINGS_TO_ENUMS; /** * Static init for filling the reverse mapping. */ static { + STRINGS_TO_ENUMS = new HashMap<>(); for (WorldAssemblyStatus status : values()) { STRINGS_TO_ENUMS.put(status.toString(), status); } diff --git a/src/main/java/com/github/agadar/nationstates/query/APIQuery.java b/src/main/java/com/github/agadar/nationstates/query/APIQuery.java index 91b78b9..3a65d0f 100644 --- a/src/main/java/com/github/agadar/nationstates/query/APIQuery.java +++ b/src/main/java/com/github/agadar/nationstates/query/APIQuery.java @@ -21,14 +21,19 @@ public abstract class APIQuery extends AbstractQuery { /** * The logger for this object. */ - protected static final Logger LOGGER = Logger.getLogger(AbstractQuery.class.getName()); + protected static final Logger LOGGER; /** * Base URL to NationStates. */ - private static final String BASE_URL = "https://www.nationstates.net/"; + private static final String BASE_URL; + + // Lazily initialize fields. + static { + LOGGER = Logger.getLogger(AbstractQuery.class.getName()); + BASE_URL = "https://www.nationstates.net/"; + } /** * The return type of this Query's execute()-method. diff --git a/src/main/java/com/github/agadar/nationstates/query/TelegramQuery.java b/src/main/java/com/github/agadar/nationstates/query/TelegramQuery.java index 6261ef2..b812ab2 100644 --- a/src/main/java/com/github/agadar/nationstates/query/TelegramQuery.java +++ b/src/main/java/com/github/agadar/nationstates/query/TelegramQuery.java @@ -31,16 +31,20 @@ public final class TelegramQuery extends APIQuery { * telegram per 30 seconds. To make sure we're on the safe side, we reduce * this to 1 telegram per 30.05 seconds. */ - private static final DependantRateLimiter TELEGRAM_RATE_LIMITER - = new DependantRateLimiter(1, TIME_BETWEEN_TELEGRAMS, RATE_LIMITER); + private static final DependantRateLimiter TELEGRAM_RATE_LIMITER; /** * The rate limiter for recruitment telegrams. The mandated rate limit is 1 * telegram per 180 seconds. To make sure we're on the safe side, we reduce * this to 1 telegram per 180.05 seconds. */ - private static final DependantRateLimiter RECRUITMENT_TELEGRAM_RATE_LIMITER - = new DependantRateLimiter(1, TIME_BETWEEN_RECRUITMENT_TELEGRAMS, TELEGRAM_RATE_LIMITER); + private static final DependantRateLimiter RECRUITMENT_TELEGRAM_RATE_LIMITER; + + // Lazily initialize the rate limiters. + static { + TELEGRAM_RATE_LIMITER = new DependantRateLimiter(1, TIME_BETWEEN_TELEGRAMS, RATE_LIMITER); + RECRUITMENT_TELEGRAM_RATE_LIMITER = new DependantRateLimiter(1, TIME_BETWEEN_RECRUITMENT_TELEGRAMS, TELEGRAM_RATE_LIMITER); + } /** * List of listeners.