• 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

94.12
/src/main/java/ch/jalu/configme/properties/types/BooleanType.java
1
package ch.jalu.configme.properties.types;
2

3
import ch.jalu.configme.properties.convertresult.ConvertErrorRecorder;
4
import ch.jalu.typeresolver.TypeInfo;
5
import ch.jalu.typeresolver.primitives.PrimitiveType;
6
import org.jetbrains.annotations.NotNull;
7
import org.jetbrains.annotations.Nullable;
8

9
/**
10
 * Property type and mapper leaf type for boolean values.
11
 */
12
public class BooleanType extends PropertyAndLeafType<Boolean> {
13

14
    /** Instance of this class. Named {@code BOOLEAN} rather than {@code INSTANCE} so it can be statically imported. */
15
    public static final BooleanType BOOLEAN = new BooleanType();
5✔
16

17
    /**
18
     * Constructor. Use {@link BooleanType#BOOLEAN} for the standard behavior.
19
     */
20
    protected BooleanType() {
21
        super(Boolean.class);
3✔
22
    }
1✔
23

24
    @Override
25
    public @Nullable Boolean convert(@Nullable Object object, @NotNull ConvertErrorRecorder errorRecorder) {
26
        if (object instanceof Boolean) {
3✔
27
            return (Boolean) object;
3✔
28
        } else if (object instanceof String) {
3✔
29
            return convertFromString((String) object);
5✔
30
        }
31
        return null;
2✔
32
    }
33

34
    @Override
35
    public @NotNull Boolean toExportValue(@NotNull Boolean value) {
36
        return value;
2✔
37
    }
38

39
    @Override
40
    public boolean canConvertToType(@NotNull TypeInfo typeInformation) {
41
        Class<?> requiredClass = PrimitiveType.toReferenceType(typeInformation.toClass());
4✔
42
        return requiredClass != null && requiredClass.isAssignableFrom(Boolean.class);
10✔
43
    }
44

45
    /**
46
     * Converts the String value to its boolean value, if applicable.
47
     *
48
     * @param value the value to convert
49
     * @return boolean value represented by the string, or null if not applicable
50
     */
51
    protected @Nullable Boolean convertFromString(@NotNull String value) {
52
        // Note: Explicitly check for true/false because Boolean#parseBoolean returns false for
53
        // any value it doesn't recognize
54
        if ("true".equalsIgnoreCase(value)) {
4✔
55
            return true;
3✔
56
        } else if ("false".equalsIgnoreCase(value)) {
4✔
57
            return false;
3✔
58
        }
59
        return null;
2✔
60
    }
61

62
    public ArrayPropertyType<Boolean> arrayType() {
63
        return new ArrayPropertyType<>(this, Boolean[]::new);
×
64
    }
65
}
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