Skip to content

Commit 22f31f5

Browse files
authored
2.x: small note on Maybe.defaultIfEmpty regarding toSingle (#5486)
1 parent 46ec6a6 commit 22f31f5

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/main/java/io/reactivex/Maybe.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,6 +2193,10 @@ public final Single<Long> count() {
21932193
* Returns a Maybe that emits the item emitted by the source Maybe or a specified default item
21942194
* if the source Maybe is empty.
21952195
* <p>
2196+
* Note that the result Maybe is semantically equivalent to a {@code Single}, since it's guaranteed
2197+
* to emit exactly one item or an error. See {@link #toSingle(Object)} for a method with equivalent
2198+
* behavior which returns a {@code Single}.
2199+
* <p>
21962200
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/defaultIfEmpty.png" alt="">
21972201
* <dl>
21982202
* <dt><b>Scheduler:</b></dt>

src/test/java/io/reactivex/JavadocWording.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,11 @@ public void maybeDocRefersToMaybeTypes() throws Exception {
148148
for (;;) {
149149
int idx = m.javadoc.indexOf("Single", jdx);
150150
if (idx >= 0) {
151-
if (!m.signature.contains("Single")) {
151+
int j = m.javadoc.indexOf("#toSingle", jdx);
152+
int k = m.javadoc.indexOf("{@code Single", jdx);
153+
if (!m.signature.contains("Single") && (j + 3 != idx && k + 7 != idx)) {
152154
e.append("java.lang.RuntimeException: Maybe doc mentions Single but not in the signature\r\n at io.reactivex.")
153-
.append("Maybe (Maybe.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
155+
.append("Maybe(Maybe.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
154156
}
155157
jdx = idx + 6;
156158
} else {

0 commit comments

Comments
 (0)