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

AuthMe / ConfigMe / 7041999669

30 Nov 2023 04:25AM UTC coverage: 99.413%. Remained the same
7041999669

Pull #401

github

web-flow
Bump actions/setup-java from 3 to 4

Bumps [actions/setup-java](https://github.com/actions/setup-java) from 3 to 4.
- [Release notes](https://github.com/actions/setup-java/releases)
- [Commits](https://github.com/actions/setup-java/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/setup-java
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #401: Bump actions/setup-java from 3 to 4

527 of 540 branches covered (0.0%)

1524 of 1533 relevant lines covered (99.41%)

4.57 hits per line

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

95.24
/src/main/java/ch/jalu/configme/configurationdata/PropertyListBuilder.java
1
package ch.jalu.configme.configurationdata;
2

3
import ch.jalu.configme.exception.ConfigMeException;
4
import ch.jalu.configme.properties.Property;
5
import org.jetbrains.annotations.NotNull;
6

7
import java.util.ArrayList;
8
import java.util.LinkedHashMap;
9
import java.util.List;
10
import java.util.Map;
11

12
/**
13
 * Builds a list of known properties in an ordered and grouped manner.
14
 * <p>
15
 * It guarantees that the added entries:
16
 * <ul>
17
 *   <li>are grouped by path, e.g. all "DataSource.mysql" properties are together, and "DataSource.mysql" properties
18
 *   are within the broader "DataSource" group.</li>
19
 *   <li>are ordered by insertion, e.g. if the first "DataSource" property is inserted before the first "security"
20
 *   property, then "DataSource" properties will come before the "security" ones.</li>
21
 *   <li>are unique: if any property is attempted to be added twice, or the addition of a property would remove another
22
 *   existing property, an exception is thrown</li>
23
 * </ul>
24
 */
25
public class PropertyListBuilder {
2✔
26

27
    private final @NotNull Map<String, Object> rootEntries = new LinkedHashMap<>();
6✔
28

29
    /**
30
     * Adds the property to the list builder.
31
     *
32
     * @param property the property to add
33
     */
34
    public void add(@NotNull Property<?> property) {
35
        String[] pathElements = property.getPath().split("\\.", -1);
6✔
36
        Map<String, Object> mapForProperty = getMapBeforeLastElement(pathElements);
4✔
37

38
        final String lastElement = pathElements[pathElements.length - 1];
7✔
39
        if (mapForProperty.containsKey(lastElement)) {
4✔
40
            throw new ConfigMeException("Path at '" + property.getPath() + "' already exists");
15✔
41
        } else if (pathElements.length > 1 && "".equals(lastElement)) {
8✔
42
            throwExceptionForMalformedPath(property.getPath());
×
43
        }
44
        mapForProperty.put(lastElement, property);
5✔
45
    }
1✔
46

47
    /**
48
     * Creates a list of properties that have been added, by insertion order but grouped by path parents
49
     * (see class JavaDoc).
50
     *
51
     * @return ordered list of registered properties
52
     */
53
    public @NotNull List<Property<?>> create() {
54
        List<Property<?>> result = new ArrayList<>();
4✔
55
        collectEntries(rootEntries, result);
4✔
56
        if (result.size() > 1 && rootEntries.containsKey("")) {
9✔
57
            throw new ConfigMeException("A property at the root path (\"\") cannot be defined alongside "
5✔
58
                + "other properties as the paths would conflict");
59
        }
60
        return result;
2✔
61
    }
62

63
    /**
64
     * Returns the nested map for the given path parts in which a property can be saved (for the last element
65
     * in the path parts). Throws an exception if the path is malformed.
66
     *
67
     * @param pathParts the path elements (i.e. the property path split by ".")
68
     * @return the map to store the property in
69
     */
70
    protected @NotNull Map<String, Object> getMapBeforeLastElement(String @NotNull [] pathParts) {
71
        Map<String, Object> map = rootEntries;
3✔
72
        for (int i = 0; i < pathParts.length - 1; ++i) {
10✔
73
            map = getChildMap(map, pathParts[i]);
6✔
74
            if (pathParts[i].equals("")) {
6✔
75
                throwExceptionForMalformedPath(String.join(".", pathParts));
×
76
            }
77
        }
78
        return map;
2✔
79
    }
80

81
    protected void throwExceptionForMalformedPath(@NotNull String path) {
82
        throw new ConfigMeException("The path at '" + path + "' is malformed: dots may not be at the beginning or end "
14✔
83
            + "of a path, and dots may not appear multiple times successively.");
84
    }
85

86
    protected final @NotNull Map<String, Object> getRootEntries() {
87
        return rootEntries;
3✔
88
    }
89

90
    private static @NotNull Map<String, Object> getChildMap(@NotNull Map<String, Object> parent, @NotNull String path) {
91
        Object o = parent.get(path);
4✔
92
        if (o instanceof Map<?, ?>) {
3✔
93
            return asTypedMap(o);
3✔
94
        } else if (o == null) {
2✔
95
            Map<String, Object> map = new LinkedHashMap<>();
4✔
96
            parent.put(path, map);
5✔
97
            return map;
2✔
98
        } else { // uh oh
99
            if (o instanceof Property<?>) {
3✔
100
                throw new ConfigMeException("Unexpected entry found at path '" + path + "'");
14✔
101
            } else {
102
                throw new ConfigMeException("Value of unknown type found at '" + path + "': " + o);
16✔
103
            }
104
        }
105
    }
106

107
    private static void collectEntries(@NotNull Map<String, Object> map, @NotNull List<Property<?>> results) {
108
        for (Object o : map.values()) {
10✔
109
            if (o instanceof Map<?, ?>) {
3✔
110
                collectEntries(asTypedMap(o), results);
5✔
111
            } else if (o instanceof Property<?>) {
3✔
112
                results.add((Property<?>) o);
5✔
113
            }
114
        }
1✔
115
    }
1✔
116

117
    @SuppressWarnings("unchecked")
118
    private static @NotNull Map<String, Object> asTypedMap(@NotNull Object o) {
119
        return (Map<String, Object>) o;
3✔
120
    }
121
}
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