2 * Sone - Options.java - Copyright © 2010–2020 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;
27 * Stores various options that influence Sone’s behaviour.
29 public class Options {
31 /** Holds all {@link Boolean} {@link Option}s. */
32 private final Map<String, Option<Boolean>> booleanOptions = Collections.synchronizedMap(new HashMap<String, Option<Boolean>>());
34 /** Holds all {@link Integer} {@link Option}s. */
35 private final Map<String, Option<Integer>> integerOptions = Collections.synchronizedMap(new HashMap<String, Option<Integer>>());
37 /** Holds all {@link String} {@link Option}s. */
38 private final Map<String, Option<String>> stringOptions = Collections.synchronizedMap(new HashMap<String, Option<String>>());
40 /** Holds all {@link Enum} {@link Option}s. */
41 private final Map<String, Option<? extends Enum<?>>> enumOptions = Collections.synchronizedMap(new HashMap<String, Option<? extends Enum<?>>>());
44 * Adds a boolean option.
47 * The name of the option
48 * @param booleanOption
50 * @return The given option
52 public Option<Boolean> addBooleanOption(String name, Option<Boolean> booleanOption) {
53 booleanOptions.put(name, booleanOption);
58 * Returns the boolean option with the given name.
61 * The name of the option
62 * @return The option, or {@code null} if there is no option with the given
65 public Option<Boolean> getBooleanOption(String name) {
66 return booleanOptions.get(name);
70 * Adds an {@link Integer} {@link Option}.
73 * The name of the option
74 * @param integerOption
76 * @return The given option
78 public Option<Integer> addIntegerOption(String name, Option<Integer> integerOption) {
79 integerOptions.put(name, integerOption);
84 * Returns an {@link Integer} {@link Option}.
87 * The name of the integer option to get
88 * @return The integer option, or {@code null} if there is no option with
91 public Option<Integer> getIntegerOption(String name) {
92 return integerOptions.get(name);
96 * Adds a {@link String} {@link Option}.
99 * The name of the option
100 * @param stringOption
102 * @return The given option
104 public Option<String> addStringOption(String name, Option<String> stringOption) {
105 stringOptions.put(name, stringOption);
110 * Returns a {@link String} {@link Option}.
113 * The name of the string option to get
114 * @return The string option, or {@code null} if there is no option with the
117 public Option<String> getStringOption(String name) {
118 return stringOptions.get(name);
122 * Adds an {@link Enum} {@link Option}.
127 * The name of the option
130 * @return The given option
132 public <T extends Enum<T>> Option<T> addEnumOption(String name, Option<T> enumOption) {
133 enumOptions.put(name, enumOption);
138 * Returns a {@link Enum} {@link Option}. As the type can probably not be
139 * interred correctly you could help the compiler by calling this method
144 * options.<SomeEnum> getEnumOption("SomeEnumOption").get();
150 * The name of the option
151 * @return The enum option, or {@code null} if there is no enum option with
154 @SuppressWarnings("unchecked")
155 public <T extends Enum<T>> Option<T> getEnumOption(String name) {
156 return (Option<T>) enumOptions.get(name);