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

jhannes / fluent-jdbc / #178

09 Aug 2024 12:30PM UTC coverage: 92.992% (-1.2%) from 94.146%
#178

push

jhannes
added DatabaseQueryBuilder.singleInt and fixed DatabaseQueryBuilder.singleLong

1 of 1 new or added line in 1 file covered. (100.0%)

24 existing lines in 3 files now uncovered.

1181 of 1270 relevant lines covered (92.99%)

0.93 hits per line

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

50.0
/src/main/java/org/fluentjdbc/SingleRow.java
1
package org.fluentjdbc;
2

3
import javax.annotation.Nonnull;
4
import java.util.Collections;
5
import java.util.Iterator;
6
import java.util.function.Consumer;
7
import java.util.function.Function;
8
import java.util.function.Supplier;
9
import java.util.stream.Stream;
10

11
public interface SingleRow<TYPE> extends Iterable<TYPE> {
12

13
    /**
14
     * Signifies that no row matched the query. If the variable is accessed, the specified exception is thrown
15
     */
16
    static <T, EX extends RuntimeException> SingleRow<T> absent(Supplier<EX> exception) {
17
        return new Absent<>(exception);
1✔
18
    }
19

20
    static <T> SingleRow<T> of(T result) {
21
        return new Present<>(result);
1✔
22
    }
23

24
    @Nonnull
25
    TYPE orElseThrow();
26

27
    boolean isPresent();
28

29
    default TYPE get() {
30
        return orElseThrow();
1✔
31
    }
32

33
    default boolean isEmpty() {
34
        return !isPresent();
1✔
35
    }
36

37
    <U> SingleRow<U> map(Function<? super TYPE, ? extends U> mapper);
38

39
    void ifPresent(Consumer<? super TYPE> consumer);
40

41
    void ifPresentOrElse(Consumer<? super TYPE> consumer, Runnable emptyAction);
42

43
    Stream<TYPE> stream();
44

45
    class Absent<T, EX extends RuntimeException> implements SingleRow<T> {
46
        private final Supplier<EX> exception;
47

48
        public Absent(Supplier<EX> exception) {
1✔
49
            this.exception = exception;
1✔
50
        }
1✔
51

52
        @Override
53
        @Nonnull
54
        public Iterator<T> iterator() {
55
            return Collections.emptyIterator();
1✔
56
        }
57

58
        @Nonnull
59
        @Override
60
        public T orElseThrow() throws EX {
UNCOV
61
            throw exception.get();
×
62
        }
63

64
        @Override
65
        public boolean isPresent() {
66
            return false;
1✔
67
        }
68

69
        @Override
70
        public <U> SingleRow<U> map(Function<? super T, ? extends U> mapper) {
UNCOV
71
            return new Absent<>(exception);
×
72
        }
73

74
        @Override
75
        public void ifPresent(Consumer<? super T> consumer) {
UNCOV
76
        }
×
77

78
        @Override
79
        public void ifPresentOrElse(Consumer<? super T> consumer, Runnable emptyAction) {
UNCOV
80
            emptyAction.run();
×
81
        }
×
82

83
        @Override
84
        public Stream<T> stream() {
UNCOV
85
            return Stream.empty();
×
86
        }
87
    }
88

89
    class Present<T> implements SingleRow<T> {
90
        private final T result;
91

92
        public Present(@Nonnull T result) {
1✔
93
            this.result = result;
1✔
94
        }
1✔
95

96
        @Override
97
        @Nonnull
98
        public Iterator<T> iterator() {
UNCOV
99
            return Collections.singletonList(result).iterator();
×
100
        }
101

102
        @Nonnull
103
        @Override
104
        public T orElseThrow() {
105
            return result;
1✔
106
        }
107

108
        @Override
109
        public boolean isPresent() {
110
            return true;
1✔
111
        }
112

113
        @Override
114
        public <U> SingleRow<U> map(Function<? super T, ? extends U> mapper) {
UNCOV
115
            return new Present<>(mapper.apply(result));
×
116
        }
117

118
        @Override
119
        public void ifPresent(Consumer<? super T> consumer) {
UNCOV
120
            consumer.accept(result);
×
UNCOV
121
        }
×
122

123
        @Override
124
        public void ifPresentOrElse(Consumer<? super T> consumer, Runnable emptyAction) {
UNCOV
125
            consumer.accept(result);
×
UNCOV
126
        }
×
127

128
        @Override
129
        public Stream<T> stream() {
UNCOV
130
            return Stream.of(result);
×
131
        }
132

133
        @Override
134
        public String toString() {
UNCOV
135
            return "SingleRow{" + result + "}";
×
136
        }
137
    }
138
}
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