Skip to contentMethod: get(String)
1: /**
2: * Copyright (C) 2020 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jopa.utils;
16:
17: import java.util.Collections;
18: import java.util.HashMap;
19: import java.util.Map;
20: import java.util.Objects;
21:
22: /**
23: * Contains configuration for the persistence provider and utility access methods for it.
24: * <p>
25: * This class is thread safe.
26: */
27: public final class Configuration {
28:
29: private final Map<String, String> properties;
30:
31: public Configuration() {
32: this.properties = new HashMap<>();
33: }
34:
35: public Configuration(Map<String, String> properties) {
36: Objects.requireNonNull(properties);
37: this.properties = new HashMap<>(properties);
38: }
39:
40: public String get(String property) {
41: return get(property, null);
42: }
43:
44: public String get(String property, String defaultValue) {
45: return properties.getOrDefault(property, defaultValue);
46: }
47:
48: public boolean is(String property) {
49: final String propertyValue = get(property, null);
50: return Boolean.parseBoolean(propertyValue);
51: }
52:
53: public synchronized void set(String property, String value) {
54: Objects.requireNonNull(property);
55: properties.put(property, value);
56: }
57:
58: public boolean contains(String property) {
59: return properties.containsKey(property);
60: }
61:
62: public Map<String, String> getProperties() {
63: return Collections.unmodifiableMap(properties);
64: }
65: }