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

AuthMe / ConfigMe / 6014622287

29 Aug 2023 03:52PM UTC coverage: 93.592% (-1.7%) from 95.279%
6014622287

push

github

ljacqu
Draft: collection property types (2)

522 of 544 branches covered (0.0%)

37 of 37 new or added lines in 3 files covered. (100.0%)

1446 of 1545 relevant lines covered (93.59%)

4.28 hits per line

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

0.0
/src/main/java/ch/jalu/configme/properties/types/InlineArrayPropertyType.java
1
package ch.jalu.configme.properties.types;
2

3
import ch.jalu.configme.properties.convertresult.ConvertErrorRecorder;
4
import org.jetbrains.annotations.NotNull;
5
import org.jetbrains.annotations.Nullable;
6

7
import java.util.Arrays;
8
import java.util.Objects;
9
import java.util.function.IntFunction;
10
import java.util.regex.Pattern;
11
import java.util.stream.Collectors;
12

13
public class InlineArrayPropertyType<T> implements PropertyType<T[]> {
14

15
    private final PropertyType<T> entryType;
16
    private final String separator;
17
    private final boolean useTrimAndSpaces;
18
    private final IntFunction<T[]> arrayProducer;
19

20
    public InlineArrayPropertyType(@NotNull PropertyType<T> entryType, @NotNull String separator,
21
                                   boolean useTrimAndSpaces, @NotNull IntFunction<T[]> arrayProducer) {
×
22
        this.entryType = entryType;
×
23
        this.separator = separator;
×
24
        this.useTrimAndSpaces = useTrimAndSpaces;
×
25
        this.arrayProducer = arrayProducer;
×
26
    }
×
27

28
    @Override
29
    public T @Nullable [] convert(@Nullable Object object, @NotNull ConvertErrorRecorder errorRecorder) {
30
        if (object != null) {
×
31
            String strValue = (String) object;
×
32

33
            return Arrays.stream(strValue.split(Pattern.quote(separator)))
×
34
                .map(entry -> entryType.convert(entry, errorRecorder))
×
35
                .filter(Objects::nonNull)
×
36
                .toArray(arrayProducer);
×
37
        }
38
        return null;
×
39
    }
40

41
    @Override
42
    public @NotNull String toExportValue(T @NotNull [] value) {
43
        String delimiter = useTrimAndSpaces ? (separator + " ") : separator;
×
44
        return Arrays.stream(value)
×
45
            .map(entryType::toExportValue)
×
46
            .filter(Objects::nonNull)
×
47
            .map(Object::toString)
×
48
            .collect(Collectors.joining(delimiter));
×
49
    }
50
}
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