Java 类io.reactivex.MaybeSource 实例源码

项目:sprockets-android    文件:LocationLoader.java   
@Override
public Location loadInBackground() {
    mCancel = MaybeSubject.create();
    ArrayList<MaybeSource<Location>> sources;
    if (mPriorities != null) {
        sources = new ArrayList<>(mPriorities.length + 1);
        for (int priority : mPriorities) {
            sources.add(mProvider.getCurrentLocation(priority));
        }
    } else {
        sources = new ArrayList<>(2);
        sources.add(mProvider.getCurrentLocation(mPriority));
    }
    sources.add(mCancel);
    Location location = Maybe.amb(sources).blockingGet();
    mCancel = null;
    return location;
}
项目:vertx-rx    文件:MaybeUnmarshaller.java   
@Override
public MaybeSource<T> apply(@NonNull Maybe<B> upstream) {
  Maybe<Buffer> unwrapped = upstream.map(unwrap::apply);
  Maybe<T> unmarshalled = unwrapped.concatMap(buffer -> {
    if (buffer.length() > 0) {
      try {
        T obj = nonNull(mappedType) ? mapper.readValue(buffer.getBytes(), mappedType) :
          mapper.readValue(buffer.getBytes(), mappedTypeRef);
        return Maybe.just(obj);
      } catch (IOException e) {
        return Maybe.error(e);
      }
    } else {
      return Maybe.empty();
    }
  });
  return unmarshalled;
}
项目:Quran    文件:QuranImportPresenter.java   
private Maybe<BookmarkData> getBookmarkDataObservable(Maybe<BufferedSource> source) {
  return source
      .flatMap(new Function<BufferedSource, MaybeSource<BookmarkData>>() {
        @Override
        public MaybeSource<BookmarkData> apply(BufferedSource bufferedSource) throws Exception {
          return mBookmarkImportExportModel.readBookmarks(bufferedSource).toMaybe();
        }
      })
      .subscribeOn(Schedulers.io());
}
项目:Quran    文件:QuranImportPresenter.java   
@NonNull
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
Maybe<BufferedSource> parseUri(final Uri uri) {
  return Maybe.defer(new Callable<MaybeSource<BufferedSource>>() {
    @Override
    public MaybeSource<BufferedSource> call() throws Exception {
      ParcelFileDescriptor pfd = mAppContext.getContentResolver().openFileDescriptor(uri, "r");
      if (pfd != null) {
        FileDescriptor fd = pfd.getFileDescriptor();
        return Maybe.just(Okio.buffer(Okio.source(new FileInputStream(fd))));
      }
      return Maybe.empty();
    }
  });
}
项目:Quran    文件:QuranImportPresenter.java   
@NonNull
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
Maybe<BufferedSource> parseExternalFile(final Uri uri) {
  return Maybe.defer(new Callable<MaybeSource<BufferedSource>>() {
    @Override
    public MaybeSource<BufferedSource> call() throws Exception {
      InputStream stream = mAppContext.getContentResolver().openInputStream(uri);
      if (stream != null) {
        return Maybe.just(Okio.buffer(Okio.source(stream)));
      }
      return Maybe.empty();
    }
  });
}
项目:LifecycleAwareRx    文件:LifecycleTransformer.java   
@Override
public MaybeSource<T> apply(Maybe<T> upstream) {
    Maybe<T> transformedStream = upstream
            .cache() // Cache to replay emitted values to late subscriber
            .filter(filterIfDestroyedPredicate); // Filter to stop emitting items once LifecycleOwner is destroyed
    setReactiveType((R)transformedStream);

    return transformedStream;
}
项目:Reactive-Android-Programming    文件:MainActivity.java   
@NonNull
private Function<StockUpdate, MaybeSource<? extends StockUpdate>> skipTweetsThatDoNotContainKeywords(String[] trackingKeywords) {
    return update -> Observable.fromArray(trackingKeywords)
            .filter(keyword -> update.getTwitterStatus().toLowerCase().contains(keyword.toLowerCase()))
            .map(keyword -> update)
            .firstElement();
}
项目:Reactive-Android-Programming    文件:MainActivity.java   
@NonNull
private Function<StockUpdate, MaybeSource<? extends StockUpdate>> skipTweetsThatDoNotContainKeywords(String[] trackingKeywords) {
    return update -> Observable.fromArray(trackingKeywords)
            .filter(keyword -> update.getTwitterStatus().toLowerCase().contains(keyword.toLowerCase()))
            .map(keyword -> update)
            .firstElement();
}
项目:rxtasks    文件:RxTask.java   
/**
 * @param callable
 * @param <R>
 * @return
 */
@CheckReturnValue
@NonNull
public static <R> Maybe<R> maybe(@NonNull final Callable<Task<R>> callable) {
    return Single.fromCallable(callable).flatMapMaybe(
            new Function<Task<R>, MaybeSource<? extends R>>() {
        @Override
        public MaybeSource<? extends R> apply(Task<R> task) throws Exception {
            return maybe(task);
        }
    });
}
项目:pandroid    文件:MainObserverTransformer.java   
@Override
public MaybeSource<T> apply(Maybe<T> upstream) {
    Maybe<T> tObservable = upstream
            .observeOn(AndroidSchedulers.mainThread());
    if (provider == null) {
        return tObservable;
    }
    return tObservable.compose(RxLifecycleDelegate.<T>bindLifecycle(provider));
}
项目:science-journal    文件:RecorderControllerImpl.java   
private MaybeSource<GoosciSnapshotValue.SnapshotLabelValue.SensorSnapshot> makeSnapshot(
        String sensorId, SensorRegistry sensorRegistry) throws Exception {
    BehaviorSubject<ScalarReading> subject = mLatestValues.get(sensorId);
    if (subject == null) {
        return Maybe.empty();
    }
    final GoosciSensorSpec.SensorSpec spec = getSensorSpec(sensorId, sensorRegistry);
    return subject.firstElement().map(value -> generateSnapshot(spec, value));
}
项目:AutoDispose    文件:Scoper.java   
/**
 * Accepts a {@link ScopeProvider} for scope resolution.
 *
 * @param provider the {@link ScopeProvider}.
 */
Scoper(final ScopeProvider provider) {
  this(Maybe.defer(new Callable<MaybeSource<?>>() {
    @Override public MaybeSource<?> call() throws Exception {
      return provider.requestScope();
    }
  }));
}
项目:Rx2Firebase    文件:RxFirebaseDatabase.java   
/**
 * Method which retrieve a list of DataSnapshot from multiple {@link DatabaseReference}.
 *
 * @param whereRefs array of {@link DatabaseReference references.}
 * @return a {@link Flowable} which emmit {@link DataSnapshot} from the given queries.
 */
@NonNull
public static Flowable<DataSnapshot> observeMultipleSingleValueEvent(@NonNull DatabaseReference... whereRefs) {
   return Maybe.merge(Flowable.fromArray(whereRefs)
   .map(new Function<DatabaseReference, MaybeSource<? extends DataSnapshot>>() {
         @Override
         public MaybeSource<? extends DataSnapshot> apply(@NonNull DatabaseReference databaseReference) throws
               Exception {
            return observeSingleValueEvent(databaseReference);
         }
      })
   );
}
项目:DisposableAttach    文件:AttachDisposableMaybe.java   
@Override
public final MaybeSource<T> source() {
    return source;
}
项目:RxLifeCycle    文件:LifecycleTransformer.java   
@Override
public MaybeSource<T> apply(Maybe<T> upstream) {
    return upstream.takeUntil(observable.firstElement());
}
项目:RxConditions    文件:MaybeIfThen.java   
MaybeIfThen(BooleanSupplier condition, MaybeSource<? extends T> then,
            MaybeSource<? extends T> orElse) {
    this.condition = condition;
    this.then = then;
    this.orElse = orElse;
}
项目:pandroid    文件:RxLifecycleTransformerEmpty.java   
@Override
public MaybeSource<T> apply(Maybe<T> upstream) {
    return upstream;
}
项目:pandroid    文件:RxLifecycleTransformer.java   
@Override
public MaybeSource<T> apply(Maybe<T> upstream) {
    return upstream.takeUntil(mObservable.firstElement());
}
项目:AutoDispose    文件:MaybeScoper.java   
AutoDisposeMaybe(MaybeSource<T> source, Maybe<?> scope) {
  this.source = source;
  this.scope = scope;
}
项目:ObservableCache    文件:CacheableMaybe.java   
@Override
public MaybeSource<T> apply(Maybe<T> upstream) {
    return observableCache.cacheMaybe(key, upstream);
}
项目:appkit    文件:CBMaybeTransformer.java   
@Override public MaybeSource<T> apply(Maybe<T> maybe) {
  return maybe.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread());
}
项目:recyclerview-binder    文件:LifecycleTransformer.java   
@Override
public MaybeSource<T> apply(Maybe<T> upstream) {
    return upstream.takeUntil(observable.firstElement());
}
项目:arctor    文件:WaitViewLatestTransformer.java   
@Override
public MaybeSource<T> apply(Maybe<T> upstream) {
    return ((Observable<T>) apply(upstream.toObservable())).singleElement();
}
项目:arctor    文件:WaitViewReplayTransformer.java   
@Override
public MaybeSource<T> apply(Maybe<T> upstream) {
    return ((Observable<T>) apply(upstream.toObservable())).singleElement();
}
项目:AutoDispose    文件:AutoDispose.java   
/**
 * Entry point for auto-disposing streams from a {@link ScopeProvider}.
 * <p>
 * Example usage:
 * <pre><code>
 *   Observable.just(1)
 *        .as(AutoDispose.<Integer>autoDisposable(scope))
 *        .subscribe(...)
 * </code></pre>
 *
 * @param provider the target scope provider
 * @param <T> the stream type.
 * @return an {@link AutoDisposeConverter} to transform with operators like
 * {@link Observable#as(ObservableConverter)}
 */
public static <T> AutoDisposeConverter<T> autoDisposable(final ScopeProvider provider) {
  checkNotNull(provider, "provider == null");
  return autoDisposable(Maybe.defer(new Callable<MaybeSource<?>>() {
    @Override public MaybeSource<?> call() {
      return provider.requestScope();
    }
  }));
}
项目:DisposableAttach    文件:AttachDisposableMaybe.java   
/**
 *
 * @param source the consumable MaybeSource
 * @param compositeDisposable the composite disposable
 */
public AttachDisposableMaybe(MaybeSource<T> source, CompositeDisposable compositeDisposable) {
    this.source = source;
    this.compositeDisposable = compositeDisposable;
}