-
Notifications
You must be signed in to change notification settings - Fork 412
mapToOneOrNull replaced by mapToOneOrDefault #56
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,11 +9,13 @@ | |
|
|
||
| final class QueryToOneOperator<T> implements Observable.Operator<T, SqlBrite.Query> { | ||
| private final Func1<Cursor, T> mapper; | ||
| private final boolean emitNull; | ||
| private boolean emitDefault; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You still need this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can still emit
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But then you break
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. Fixed. |
||
| private T defaultValue; | ||
|
|
||
| QueryToOneOperator(Func1<Cursor, T> mapper, boolean emitNull) { | ||
| QueryToOneOperator(Func1<Cursor, T> mapper, boolean emitDefault, T defaultValue) { | ||
| this.mapper = mapper; | ||
| this.emitNull = emitNull; | ||
| this.emitDefault = emitDefault; | ||
| this.defaultValue = defaultValue; | ||
| } | ||
|
|
||
| @Override public Subscriber<? super SqlBrite.Query> call(final Subscriber<? super T> subscriber) { | ||
|
|
@@ -35,8 +37,12 @@ final class QueryToOneOperator<T> implements Observable.Operator<T, SqlBrite.Que | |
| } finally { | ||
| cursor.close(); | ||
| } | ||
| if (!subscriber.isUnsubscribed() && (item != null || emitNull)) { | ||
| subscriber.onNext(item); | ||
| if (!subscriber.isUnsubscribed()) { | ||
| if (item != null) { | ||
| subscriber.onNext(item); | ||
| } else if (emitDefault) { | ||
| subscriber.onNext(defaultValue); | ||
| } | ||
| } | ||
| } catch (Throwable e) { | ||
| Exceptions.throwIfFatal(e); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you duplicate this test and use a non-null default? Maybe rename this one to "EmptyUsingNull" or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.