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

ljacqu / FileDuplicateFinder / 14006930974

22 Mar 2025 08:35AM UTC coverage: 23.055%. Remained the same
14006930974

push

github

ljacqu
Add Nullable annotation next to return value in methods

111 of 610 branches covered (18.2%)

Branch coverage included in aggregate %.

378 of 1511 relevant lines covered (25.02%)

1.28 hits per line

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

0.0
/src/main/java/ch/jalu/fileduplicatefinder/config/ValueOrError.java
1
package ch.jalu.fileduplicatefinder.config;
2

3
import com.google.common.base.Preconditions;
4
import org.jetbrains.annotations.Nullable;
5

6
/**
7
 * Encapsulates a value or an error. Exactly one field is always non-null.
8
 *
9
 * @param <T> the value type
10
 */
11
public class ValueOrError<T> {
12

13
    private final @Nullable T value;
14
    private final @Nullable String errorReason;
15

16
    private ValueOrError(@Nullable T value, @Nullable String errorReason) {
×
17
        Preconditions.checkArgument(value != null ^ errorReason != null,
×
18
            "Value xor errorReason must be not null");
19
        this.value = value;
×
20
        this.errorReason = errorReason;
×
21
    }
×
22

23
    /**
24
     * Creates a new instance with the given value.
25
     *
26
     * @param value the result (not null)
27
     * @return instance with the value
28
     * @param <T> the value's type
29
     */
30
    public static <T> ValueOrError<T> forValue(T value) {
31
        return new ValueOrError<>(value, null);
×
32
    }
33

34
    /**
35
     * Creates a new instance with the given error reason.
36
     *
37
     * @param errorReason error detailing the issue with the conversion (not null)
38
     * @return instance with the error
39
     * @param <T> value or error type
40
     */
41
    public static <T> ValueOrError<T> forError(String errorReason) {
42
        return new ValueOrError<>(null, errorReason);
×
43
    }
44

45
    /**
46
     * @return the value; null if there is an error, otherwise guaranteed not-null
47
     */
48
    public @Nullable T getValue() {
49
        return value;
×
50
    }
51

52
    /**
53
     * @return the error; null if there is a value, otherwise guaranteed not-null
54
     */
55
    public @Nullable String getErrorReason() {
56
        return errorReason;
×
57
    }
58
}
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