Skip to content

Commit 59da969

Browse files
committed
refactoring, javadoc
1 parent c11355e commit 59da969

1 file changed

Lines changed: 13 additions & 19 deletions

File tree

src/main/java/io/jbock/util/Eithers.java

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,22 @@ public Set<Characteristics> characteristics() {
7070
}
7171
}
7272

73+
/**
74+
* @param <L> Type of LHS values in the stream
75+
* @param <C> Type of collected LHS values
76+
* @param <R> Type of RHS values in the stream
77+
*/
7378
// visible for testing
7479
static abstract class Acc<L, C, R> {
7580
private ArrayList<R> right;
7681

7782
abstract void combineLeft(C otherLeft);
7883

79-
abstract boolean isLeft();
80-
81-
/** Returns {@code null} iff {@link #isLeft()} */
84+
// nullable
8285
abstract C left();
8386

8487
final void addRight(R value) {
85-
if (isLeft()) {
88+
if (left() != null) {
8689
return;
8790
}
8891
if (right == null) {
@@ -92,11 +95,11 @@ final void addRight(R value) {
9295
}
9396

9497
final Acc<L, C, R> combine(Acc<L, C, R> other) {
95-
if (isLeft()) {
98+
if (left() != null) {
9699
combineLeft(other.left());
97100
return this;
98101
}
99-
if (other.isLeft()) {
102+
if (other.left() != null) {
100103
return other;
101104
}
102105
if (other.right == null) {
@@ -111,8 +114,9 @@ final Acc<L, C, R> combine(Acc<L, C, R> other) {
111114
}
112115

113116
final Either<C, List<R>> finish() {
114-
return isLeft()
115-
? Either.left(left())
117+
C left = left();
118+
return left != null
119+
? Either.left(left)
116120
: Either.right(right == null ? List.of() : right);
117121
}
118122
}
@@ -125,11 +129,6 @@ void combineLeft(L otherLeft) {
125129
addLeft(otherLeft);
126130
}
127131

128-
@Override
129-
boolean isLeft() {
130-
return left != null;
131-
}
132-
133132
void addLeft(L value) {
134133
if (left == null) {
135134
left = value;
@@ -148,16 +147,11 @@ private static class FullAcc<L, R> extends Acc<L, List<L>, R> {
148147
void combineLeft(List<L> otherLeft) {
149148
if (left == null) {
150149
left = otherLeft;
151-
} else if (otherLeft != null && !otherLeft.isEmpty()) {
150+
} else if (otherLeft != null) {
152151
left.addAll(otherLeft);
153152
}
154153
}
155154

156-
@Override
157-
boolean isLeft() {
158-
return left != null && !left.isEmpty();
159-
}
160-
161155
void addLeft(L value) {
162156
if (left == null) {
163157
left = new ArrayList<>();

0 commit comments

Comments
 (0)