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

AuthMe / ConfigMe / 6022426951

30 Aug 2023 08:26AM UTC coverage: 97.279% (+3.7%) from 93.592%
6022426951

push

github

ljacqu
Draft: collection property types (3)

528 of 546 branches covered (0.0%)

45 of 45 new or added lines in 12 files covered. (100.0%)

1466 of 1507 relevant lines covered (97.28%)

4.44 hits per line

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

91.67
/src/main/java/ch/jalu/configme/properties/types/EnumPropertyType.java
1
package ch.jalu.configme.properties.types;
2

3
import ch.jalu.configme.properties.convertresult.ConvertErrorRecorder;
4
import ch.jalu.configme.utils.Utils;
5
import ch.jalu.typeresolver.EnumUtils;
6
import org.jetbrains.annotations.NotNull;
7
import org.jetbrains.annotations.Nullable;
8

9
/**
10
 * Property type for an enum type.
11
 *
12
 * @param <E> the enum type
13
 */
14
public class EnumPropertyType<E extends Enum<E>> implements PropertyType<E> {
15

16
    private final Class<E> enumType;
17

18
    /**
19
     * Constructor. You can also create instances with {@link EnumPropertyType#of}.
20
     *
21
     * @param enumType the enum type this type should convert to
22
     */
23
    public EnumPropertyType(@NotNull Class<E> enumType) {
2✔
24
        this.enumType = enumType;
3✔
25
    }
1✔
26

27
    public static <E extends Enum<E>> @NotNull EnumPropertyType<E> of(@NotNull Class<E> type) {
28
        return new EnumPropertyType<>(type);
5✔
29
    }
30

31
    @Override
32
    @SuppressWarnings("unchecked")
33
    public @Nullable E convert(@Nullable Object object, @NotNull ConvertErrorRecorder errorRecorder) {
34
        if (object instanceof String) {
3✔
35
            return EnumUtils.tryValueOfCaseInsensitive(enumType, (String) object).orElse(null);
9✔
36
        } else if (enumType.isInstance(object)) {
5✔
37
            return (E) object;
3✔
38
        }
39
        return null;
2✔
40
    }
41

42
    @Override
43
    public @NotNull String toExportValue(@NotNull E value) {
44
        return value.name();
3✔
45
    }
46

47
    public final @NotNull Class<E> getEnumType() {
48
        return enumType;
3✔
49
    }
50

51
    public ArrayPropertyType<E> arrayType() {
52
        return new ArrayPropertyType<>(this, size -> Utils.createArrayForReferenceType(enumType, size));
×
53
    }
54
}
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

© 2026 Coveralls, Inc