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

LearnLib / learnlib / 6605620268

22 Oct 2023 06:53PM UTC coverage: 93.218% (+0.9%) from 92.296%
6605620268

push

github

mtf90
cleanup passive integration tests

11546 of 12386 relevant lines covered (93.22%)

1.68 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.api.logging.Category;
23
import de.learnlib.api.setting.LearnLibSettingsSource;
24
import net.automatalib.common.util.WrapperUtil;
25
import net.automatalib.common.util.setting.SettingsSource;
26
import org.checkerframework.checker.nullness.qual.Nullable;
27
import org.slf4j.Logger;
28
import org.slf4j.LoggerFactory;
29

30
public final class LearnLibSettings {
31

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

97
}
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