2 * Sone - Options.java - Copyright © 2010–2019 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 public class Options {
33 /** Holds all {@link Boolean} {@link Option}s. */
34 private final Map<String, Option<Boolean>> booleanOptions = Collections.synchronizedMap(new HashMap<String, Option<Boolean>>());
36 /** Holds all {@link Integer} {@link Option}s. */
37 private final Map<String, Option<Integer>> integerOptions = Collections.synchronizedMap(new HashMap<String, Option<Integer>>());
39 /** Holds all {@link String} {@link Option}s. */
40 private final Map<String, Option<String>> stringOptions = Collections.synchronizedMap(new HashMap<String, Option<String>>());
42 /** Holds all {@link Enum} {@link Option}s. */
43 private final Map<String, Option<? extends Enum<?>>> enumOptions = Collections.synchronizedMap(new HashMap<String, Option<? extends Enum<?>>>());
46 * Adds a boolean option.
49 * The name of the option
50 * @param booleanOption
52 * @return The given option
54 public Option<Boolean> addBooleanOption(String name, Option<Boolean> booleanOption) {
55 booleanOptions.put(name, booleanOption);
60 * Returns the boolean option with the given name.
63 * The name of the option
64 * @return The option, or {@code null} if there is no option with the given
67 public Option<Boolean> getBooleanOption(String name) {
68 return booleanOptions.get(name);
72 * Adds an {@link Integer} {@link Option}.
75 * The name of the option
76 * @param integerOption
78 * @return The given option
80 public Option<Integer> addIntegerOption(String name, Option<Integer> integerOption) {
81 integerOptions.put(name, integerOption);
86 * Returns an {@link Integer} {@link Option}.
89 * The name of the integer option to get
90 * @return The integer option, or {@code null} if there is no option with
93 public Option<Integer> getIntegerOption(String name) {
94 return integerOptions.get(name);
98 * Adds a {@link String} {@link Option}.
101 * The name of the option
102 * @param stringOption
104 * @return The given option
106 public Option<String> addStringOption(String name, Option<String> stringOption) {
107 stringOptions.put(name, stringOption);
112 * Returns a {@link String} {@link Option}.
115 * The name of the string option to get
116 * @return The string option, or {@code null} if there is no option with the
119 public Option<String> getStringOption(String name) {
120 return stringOptions.get(name);
124 * Adds an {@link Enum} {@link Option}.
129 * The name of the option
132 * @return The given option
134 public <T extends Enum<T>> Option<T> addEnumOption(String name, Option<T> enumOption) {
135 enumOptions.put(name, enumOption);
140 * Returns a {@link Enum} {@link Option}. As the type can probably not be
141 * interred correctly you could help the compiler by calling this method
146 * options.<SomeEnum> getEnumOption("SomeEnumOption").get();
152 * The name of the option
153 * @return The enum option, or {@code null} if there is no enum option with
156 @SuppressWarnings("unchecked")
157 public <T extends Enum<T>> Option<T> getEnumOption(String name) {
158 return (Option<T>) enumOptions.get(name);