Skip to contentPackage: Configuration
Configuration
Coverage
1: /**
2: * Copyright (C) 2011 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(Map<String, String> properties) {
32: Objects.requireNonNull(properties);
33: this.properties = new HashMap<>(properties);
34: }
35:
36: public String get(String property) {
37: return get(property, null);
38: }
39:
40: public String get(String property, String defaultValue) {
41: return properties.getOrDefault(property, defaultValue);
42: }
43:
44: public boolean is(String property) {
45: final String propertyValue = get(property, null);
46:• return propertyValue != null && Boolean.parseBoolean(propertyValue);
47: }
48:
49: public synchronized void set(String property, String value) {
50: Objects.requireNonNull(property);
51: properties.put(property, value);
52: }
53:
54: public boolean contains(String property) {
55: return properties.containsKey(property);
56: }
57:
58: public Map<String, String> getProperties() {
59: return Collections.unmodifiableMap(properties);
60: }
61: }