From: David ‘Bombe’ Roden Date: Wed, 7 Dec 2011 15:03:38 +0000 (+0100) Subject: Extend Options to include enum options. X-Git-Tag: 0.7.6^2~1^2~7 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=ecaea8c0b09431eabddd323a87fce59bba6f0238 Extend Options to include enum options. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Options.java b/src/main/java/net/pterodactylus/sone/core/Options.java index 1bdf21f..f280aae 100644 --- a/src/main/java/net/pterodactylus/sone/core/Options.java +++ b/src/main/java/net/pterodactylus/sone/core/Options.java @@ -226,6 +226,9 @@ public class Options { /** Holds all {@link String} {@link Option}s. */ private final Map> stringOptions = Collections.synchronizedMap(new HashMap>()); + /** Holds all {@link Enum} {@link Option}s. */ + private final Map>> enumOptions = Collections.synchronizedMap(new HashMap>>()); + /** * Adds a boolean option. * @@ -304,4 +307,37 @@ public class Options { return stringOptions.get(name); } + /** + * Adds an {@link Enum} {@link Option}. + * + * @param name + * The name of the option + * @param enumOption + * The option + * @return The given option + */ + public > Option addEnumOption(String name, Option enumOption) { + enumOptions.put(name, enumOption); + return enumOption; + } + + /** + * Returns a {@link Enum} {@link Option}. As the type can probably not be + * interred correctly you could help the compiler by calling this method + * like this: + *

+ * + *

+	 * options.<SomeEnum> getEnumOption("SomeEnumOption").get();
+	 * 
+ * + * @param name + * The name of the option + * @return The enum option, or {@code null} if there is no enum option with + * the given name + */ + public > Option getEnumOption(String name) { + return (Option) enumOptions.get(name); + } + }