Package: Configuration
Configuration
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Configuration() |
|
|
|
|
|
||||||||||||||||||||
addConfiguration(Map, Collection) |
|
|
|
|
|
||||||||||||||||||||
equals(Object) |
|
|
|
|
|
||||||||||||||||||||
getProperty(ConfigurationParameter) |
|
|
|
|
|
||||||||||||||||||||
getProperty(ConfigurationParameter, String) |
|
|
|
|
|
||||||||||||||||||||
hashCode() |
|
|
|
|
|
||||||||||||||||||||
is(ConfigurationParameter) |
|
|
|
|
|
||||||||||||||||||||
isSet(ConfigurationParameter) |
|
|
|
|
|
||||||||||||||||||||
lambda$addConfiguration$0(Map, ConfigurationParameter) |
|
|
|
|
|
||||||||||||||||||||
lambda$addConfiguration$1(Map, ConfigurationParameter) |
|
|
|
|
|
||||||||||||||||||||
setProperty(ConfigurationParameter, String) |
|
|
|
|
|
Coverage
1: /**
2: * Copyright (C) 2016 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.ontodriver.config;
16:
17: import java.util.Collection;
18: import java.util.HashMap;
19: import java.util.Map;
20: import java.util.Objects;
21:
22: /**
23: * Holds configuration of the OntoDriver.
24: */
25: public final class Configuration {
26:
27: private final Map<ConfigurationParameter, String> configuration = new HashMap<>();
28:
29: /**
30: * Loads configuration of parameters specified by {@code parameters} from the provided properties map.
31: *
32: * @param properties Map of configuration values
33: * @param parameters Parameters to extract from the map
34: */
35: public void addConfiguration(Map<String, String> properties, Collection<ConfigurationParameter> parameters) {
36: Objects.requireNonNull(properties);
37: Objects.requireNonNull(parameters);
38: parameters.stream().filter(p -> properties.containsKey(p.toString()))
39: .forEach(p -> setProperty(p, properties.get(p.toString())));
40: }
41:
42: /**
43: * Sets configuration of the specified parameter to the specified value.
44: * <p>
45: * Overrides any previous setting.
46: *
47: * @param property Parameter
48: * @param value Value
49: */
50: public void setProperty(ConfigurationParameter property, String value) {
51: Objects.requireNonNull(property);
52: configuration.put(property, value);
53: }
54:
55: /**
56: * Gets value of the specified property.
57: *
58: * @param property Parameter
59: * @return Value of the property or {@code null}, if it is not set
60: */
61: public String getProperty(ConfigurationParameter property) {
62: Objects.requireNonNull(property);
63: return configuration.get(property);
64: }
65:
66: /**
67: * Gets value of the specified property or the default value, if the property is not set.
68: *
69: * @param property Parameter
70: * @param defaultValue Value to return if the property is not set
71: * @return Value of the property or {@code defaultValue}, if it is not set
72: */
73: public String getProperty(ConfigurationParameter property, String defaultValue) {
74: Objects.requireNonNull(property);
75: return configuration.getOrDefault(property, defaultValue);
76: }
77:
78: /**
79: * Returns value of the specified property as boolean.
80: * <p>
81: * If the property is not configured, {@code false} is returned.
82: *
83: * @param property Parameter
84: * @return Property value (false for unknown)
85: */
86: public boolean is(ConfigurationParameter property) {
87:• if (configuration.containsKey(property)) {
88: final String value = configuration.get(property);
89: return Boolean.parseBoolean(value);
90: }
91: return false;
92: }
93:
94: /**
95: * Checks whether the specified property is set in this configuration.
96: *
97: * @param property The property to check
98: * @return Whether the specified property is set here
99: */
100: public boolean isSet(ConfigurationParameter property) {
101: return configuration.containsKey(property);
102: }
103:
104: @Override
105: public boolean equals(Object o) {
106:• if (this == o) return true;
107:• if (o == null || getClass() != o.getClass()) return false;
108:
109: Configuration that = (Configuration) o;
110:
111: return configuration.equals(that.configuration);
112:
113: }
114:
115: @Override
116: public int hashCode() {
117: return configuration.hashCode();
118: }
119: }