2 * Sone - Options.java - Copyright © 2010–2013 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.core;
20 import java.util.Collections;
21 import java.util.HashMap;
24 import net.pterodactylus.sone.utils.Option;
26 import com.google.common.base.Predicate;
29 * Stores various options that influence Sone’s behaviour.
31 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
33 public class Options {
35 /** Holds all {@link Boolean} {@link Option}s. */
36 private final Map<String, Option<Boolean>> booleanOptions = Collections.synchronizedMap(new HashMap<String, Option<Boolean>>());
38 /** Holds all {@link Integer} {@link Option}s. */
39 private final Map<String, Option<Integer>> integerOptions = Collections.synchronizedMap(new HashMap<String, Option<Integer>>());
41 /** Holds all {@link String} {@link Option}s. */
42 private final Map<String, Option<String>> stringOptions = Collections.synchronizedMap(new HashMap<String, Option<String>>());
44 /** Holds all {@link Enum} {@link Option}s. */
45 private final Map<String, Option<? extends Enum<?>>> enumOptions = Collections.synchronizedMap(new HashMap<String, Option<? extends Enum<?>>>());
48 * Adds a boolean option.
51 * The name of the option
52 * @param booleanOption
54 * @return The given option
56 public Option<Boolean> addBooleanOption(String name, Option<Boolean> booleanOption) {
57 booleanOptions.put(name, booleanOption);
62 * Returns the boolean option with the given name.
65 * The name of the option
66 * @return The option, or {@code null} if there is no option with the given
69 public Option<Boolean> getBooleanOption(String name) {
70 return booleanOptions.get(name);
74 * Adds an {@link Integer} {@link Option}.
77 * The name of the option
78 * @param integerOption
80 * @return The given option
82 public Option<Integer> addIntegerOption(String name, Option<Integer> integerOption) {
83 integerOptions.put(name, integerOption);
88 * Returns an {@link Integer} {@link Option}.
91 * The name of the integer option to get
92 * @return The integer option, or {@code null} if there is no option with
95 public Option<Integer> getIntegerOption(String name) {
96 return integerOptions.get(name);
100 * Adds a {@link String} {@link Option}.
103 * The name of the option
104 * @param stringOption
106 * @return The given option
108 public Option<String> addStringOption(String name, Option<String> stringOption) {
109 stringOptions.put(name, stringOption);
114 * Returns a {@link String} {@link Option}.
117 * The name of the string option to get
118 * @return The string option, or {@code null} if there is no option with the
121 public Option<String> getStringOption(String name) {
122 return stringOptions.get(name);
126 * Adds an {@link Enum} {@link Option}.
131 * The name of the option
134 * @return The given option
136 public <T extends Enum<T>> Option<T> addEnumOption(String name, Option<T> enumOption) {
137 enumOptions.put(name, enumOption);
142 * Returns a {@link Enum} {@link Option}. As the type can probably not be
143 * interred correctly you could help the compiler by calling this method
148 * options.<SomeEnum> getEnumOption("SomeEnumOption").get();
154 * The name of the option
155 * @return The enum option, or {@code null} if there is no enum option with
158 @SuppressWarnings("unchecked")
159 public <T extends Enum<T>> Option<T> getEnumOption(String name) {
160 return (Option<T>) enumOptions.get(name);