• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LearnLib / learnlib / 6805330902

08 Nov 2023 11:40PM UTC coverage: 93.335% (+0.008%) from 93.327%
6805330902

push

github

mtf90
typo

11736 of 12574 relevant lines covered (93.34%)

1.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.83
/commons/settings/src/main/java/de/learnlib/setting/LearnLibSettings.java
1
/* Copyright (C) 2013-2023 TU Dortmund
2
 * This file is part of LearnLib, http://www.learnlib.de/.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package de.learnlib.setting;
17

18
import java.util.Locale;
19
import java.util.Properties;
20
import java.util.function.Function;
21

22
import de.learnlib.logging.Category;
23
import net.automatalib.common.util.WrapperUtil;
24
import net.automatalib.common.util.setting.SettingsSource;
25
import org.checkerframework.checker.nullness.qual.Nullable;
26
import org.slf4j.Logger;
27
import org.slf4j.LoggerFactory;
28

29
public final class LearnLibSettings {
30

31
    private static final Logger LOG = LoggerFactory.getLogger(LearnLibSettings.class);
2✔
32

33
    private static final LearnLibSettings INSTANCE = new LearnLibSettings();
2✔
34
    private final Properties properties;
35

36
    private LearnLibSettings() {
2✔
37
        properties = SettingsSource.readSettings(LearnLibSettingsSource.class);
2✔
38
    }
2✔
39

40
    public static LearnLibSettings getInstance() {
41
        return INSTANCE;
2✔
42
    }
43

44
    public String getProperty(LearnLibProperty property, String defaultValue) {
45
        return properties.getProperty(property.getPropertyKey(), defaultValue);
×
46
    }
47

48
    public @Nullable String getProperty(LearnLibProperty property) {
49
        return properties.getProperty(property.getPropertyKey());
2✔
50
    }
51

52
    public <E extends Enum<E>> E getEnumValue(LearnLibProperty property, Class<E> enumClazz, E defaultValue) {
53
        E value = getEnumValue(property, enumClazz);
1✔
54
        if (value != null) {
1✔
55
            return value;
×
56
        }
57
        return defaultValue;
1✔
58
    }
59

60
    public <E extends Enum<E>> @Nullable E getEnumValue(LearnLibProperty property, Class<E> enumClazz) {
61
        // TODO: the assumption that enum constants are all-uppercase does not *always* hold!
62
        return getTypedValue(property, p -> Enum.valueOf(enumClazz, p.toUpperCase(Locale.ROOT)));
1✔
63
    }
64

65
    public boolean getBool(LearnLibProperty property, boolean defaultValue) {
66
        return WrapperUtil.booleanValue(getBoolean(property), defaultValue);
×
67
    }
68

69
    public @Nullable Boolean getBoolean(LearnLibProperty property) {
70
        return getTypedValue(property, Boolean::parseBoolean);
×
71
    }
72

73
    public int getInt(LearnLibProperty property, int defaultValue) {
74
        return WrapperUtil.intValue(getInteger(property), defaultValue);
2✔
75
    }
76

77
    public @Nullable Integer getInteger(LearnLibProperty property) {
78
        return getTypedValue(property, Integer::parseInt);
2✔
79
    }
80

81
    private <T> @Nullable T getTypedValue(LearnLibProperty property, Function<String, T> valueExtractor) {
82
        String prop = getProperty(property);
2✔
83

84
        if (prop == null) {
2✔
85
            return null;
1✔
86
        }
87

88
        try {
89
            return valueExtractor.apply(prop);
2✔
90
        } catch (IllegalArgumentException ex) {
×
91
            LOG.warn(Category.CONFIG, "Could not parse LearnLib property '" + property + "'.", ex);
×
92
            return null;
×
93
        }
94
    }
95

96
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc