Skip to content

Commit

Permalink
Move wrapOptional method to allow Dao to use it
Browse files Browse the repository at this point in the history
  • Loading branch information
tspoke committed Sep 13, 2017
1 parent 2f12fe0 commit 50aa629
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;

import io.reactivex.Flowable;
import io.reactivex.functions.Function;

/**
* @author Thibaud Giovannetti
Expand Down Expand Up @@ -78,4 +79,23 @@ public Flowable<Integer> delete(final T item) {
public Flowable<Integer> deleteAll() {
throw new UnsupportedOperationException("This method has not been implemented in the child class");
}

/**
* Wrap an object into an flowable optional
*/
protected <S> Flowable<Optional<S>> wrapOptional(S obj){
return Flowable.just(Optional.wrap(obj));
}

/**
* Wrap a flowable object into an flowable optional
*/
protected <S> Flowable<Optional<S>> wrapOptional(Flowable<S> obj){
return obj.flatMap(new Function<S, Flowable<Optional<S>>>() {
@Override
public Flowable<Optional<S>> apply(S s) throws Exception {
return wrapOptional(s);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -591,23 +591,4 @@ public Flowable<Integer> apply(Optional<T> reinsertedItem) throws Exception {
flowables.add(flowStorage);
return Flowable.concat(flowables);
}

/**
* Wrap an object into an flowable optional
*/
public <S> Flowable<Optional<S>> wrapOptional(S obj){
return Flowable.just(Optional.wrap(obj));
}

/**
* Wrap a flowable object into an flowable optional
*/
public <S> Flowable<Optional<S>> wrapOptional(Flowable<S> obj){
return obj.flatMap(new Function<S, Flowable<Optional<S>>>() {
@Override
public Flowable<Optional<S>> apply(S s) throws Exception {
return wrapOptional(s);
}
});
}
}

0 comments on commit 50aa629

Please sign in to comment.