io.reactivex.annotations.CheckReturnValue Java Examples

The following examples show how to use io.reactivex.annotations.CheckReturnValue. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ParseObservable.java    From RxParse with Apache License 2.0 6 votes vote down vote up
/**
 *  Limit 10000 by skip
 */
@NonNull
@CheckReturnValue
public static <R extends ParseObject> Observable<R> all(@NonNull final ParseQuery<R> query, int count) {
    final int limit = 1000; // limit limitation
    query.setSkip(0);
    query.setLimit(limit);
    Observable<R> find = find(query);
    for (int i = limit; i < count; i+= limit) {
        if (i >= 10000) break; // skip limitation
        query.setSkip(i);
        query.setLimit(limit);
        find.concatWith(find(query));
    }
    return find.distinct(o -> o.getObjectId());
}
 
Example #2
Source File: RxFirebaseUser.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
/**
 * @param user
 * @param forceRefresh
 * @return
 */
@CheckReturnValue
@NonNull
public static Single<String> getToken(@NonNull final FirebaseUser user,
                                      final boolean forceRefresh) {
    return RxTask.single(new Callable<Task<GetTokenResult>>() {
        @Override
        public Task<GetTokenResult> call() throws Exception {
            return user.getToken(forceRefresh);
        }
    })
    .map(new Function<GetTokenResult, String>() {
        @Override
        public String apply(@NonNull GetTokenResult getTokenResult) throws Exception {
            return getTokenResult.getToken();
        }
    });
}
 
Example #3
Source File: RxFirebaseAuth.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
/**
 * TODO: Should use Maybe instead of Single
 * TODO: flatten List
 *
 * @param instance
 * @param email
 * @return &lt;emptyList&gt; if providers is null
 */
@CheckReturnValue
@NonNull
public static Single<List<String>> fetchProvidersForEmail(
        @NonNull final FirebaseAuth instance, @NonNull final String email) {
    return RxTask.single(new Callable<Task<ProviderQueryResult>>() {
        @Override
        public Task<ProviderQueryResult> call() throws Exception {
            return instance.fetchProvidersForEmail(email);
        }
    }).map(new Function<ProviderQueryResult, List<String>>() {
        @Override
        public List<String> apply(@NonNull ProviderQueryResult providerQueryResult)
                throws Exception {
            List<String> providers = providerQueryResult.getProviders();
            if (null == providers) {
                providers = Collections.emptyList();
            }
            return providers;
        }
    });
}
 
Example #4
Source File: Rx2Apollo.java    From apollo-android with MIT License 6 votes vote down vote up
/**
 * Converts an {@link ApolloQueryWatcher} to an asynchronous Observable.
 *
 * @param watcher the ApolloQueryWatcher to convert.
 * @param <T>     the value type
 * @return the converted Observable
 * @throws NullPointerException if watcher == null
 */
@NotNull
@CheckReturnValue
public static <T> Observable<Response<T>> from(@NotNull final ApolloQueryWatcher<T> watcher) {
  checkNotNull(watcher, "watcher == null");
  return Observable.create(new ObservableOnSubscribe<Response<T>>() {
    @Override public void subscribe(final ObservableEmitter<Response<T>> emitter) throws Exception {
      cancelOnObservableDisposed(emitter, watcher);

      watcher.enqueueAndWatch(new ApolloCall.Callback<T>() {
        @Override public void onResponse(@NotNull Response<T> response) {
          if (!emitter.isDisposed()) {
            emitter.onNext(response);
          }
        }

        @Override public void onFailure(@NotNull ApolloException e) {
          Exceptions.throwIfFatal(e);
          if (!emitter.isDisposed()) {
            emitter.onError(e);
          }
        }
      });
    }
  });
}
 
Example #5
Source File: RxValue.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
/**
 * @param emit
 * @return
 */
@NonNull
@CheckReturnValue
public static ValueEventListener listener(@NonNull final SingleEmitter<DataSnapshot> emit) {
    return new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (!emit.isDisposed()) {
                emit.onSuccess(dataSnapshot);
            }
        }

        @Override
        public void onCancelled(DatabaseError e) {
            if (!emit.isDisposed()) {
                emit.onError(e.toException());
            }
        }
    };
}
 
Example #6
Source File: Rx2Apollo.java    From apollo-android with MIT License 6 votes vote down vote up
/**
 * Converts an {@link ApolloPrefetch} to a synchronous Completable
 *
 * @param prefetch the ApolloPrefetch to convert
 * @return the converted Completable
 * @throws NullPointerException if prefetch == null
 */
@NotNull
@CheckReturnValue
public static Completable from(@NotNull final ApolloPrefetch prefetch) {
  checkNotNull(prefetch, "prefetch == null");

  return Completable.create(new CompletableOnSubscribe() {
    @Override public void subscribe(final CompletableEmitter emitter) {
      cancelOnCompletableDisposed(emitter, prefetch);
      prefetch.enqueue(new ApolloPrefetch.Callback() {
        @Override public void onSuccess() {
          if (!emitter.isDisposed()) {
            emitter.onComplete();
          }
        }

        @Override public void onFailure(@NotNull ApolloException e) {
          Exceptions.throwIfFatal(e);
          if (!emitter.isDisposed()) {
            emitter.onError(e);
          }
        }
      });
    }
  });
}
 
Example #7
Source File: Rx2Apollo.java    From apollo-android with MIT License 6 votes vote down vote up
/**
 * Converts an {@link ApolloStoreOperation} to a Single.
 *
 * @param operation the ApolloStoreOperation to convert
 * @param <T>       the value type
 * @return the converted Single
 */
@NotNull
@CheckReturnValue
public static <T> Single<T> from(@NotNull final ApolloStoreOperation<T> operation) {
  checkNotNull(operation, "operation == null");
  return Single.create(new SingleOnSubscribe<T>() {
    @Override
    public void subscribe(final SingleEmitter<T> emitter) {
      operation.enqueue(new ApolloStoreOperation.Callback<T>() {
        @Override
        public void onSuccess(T result) {
          emitter.onSuccess(result);
        }

        @Override
        public void onFailure(Throwable t) {
          emitter.onError(t);
        }
      });
    }
  });
}
 
Example #8
Source File: RxFirebaseDatabase.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
/**
 * @param ref
 * @param fireLocalEvents
 * @param function
 * @return
 * ref.runTransaction(handler, fireLocalEvents);
 */
@NonNull
@CheckReturnValue
public static Single<DataSnapshot> runTransaction(
        @NonNull final DatabaseReference ref,
        @NonNull final Function<MutableData, Transaction.Result> function,
        final boolean fireLocalEvents) {
    return RxValue.transaction(ref, function, fireLocalEvents);
}
 
Example #9
Source File: UpdateBuilder.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
@CheckReturnValue
public UpdateBuilder where(String colName, String value) {
    DataBaseInfo.checkColumnName(colName, tablePosition);
    String whereClauseText = colName + " = ?";
    whereClause.add(whereClauseText);
    whereArgs.add(value);
    return this;
}
 
Example #10
Source File: QueryBuilder.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
@CheckReturnValue
public QueryBuilder setOrderByColumnDesc(String colName) {
    DataBaseInfo.checkColumnName(colName, tablePosition);
    isAsc = false;
    this.orderByColName = colName;
    return this;
}
 
Example #11
Source File: QueryBuilder.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
@CheckReturnValue
private Cursor execute() {

    //selection
    String clause = null;
    String[] args = null;
    if (whereArgs.size() > 0) {
        args = new String[whereClause.size()];
        StringBuilder clauseBuilder = new StringBuilder();
        for (int i = 0; i < whereClause.size(); i++) {
            clauseBuilder.append(whereClause.get(i)).append(" AND ");
            args[i] = whereArgs.get(i);
        }
        if (clauseBuilder.length() > 5) {
            clause = clauseBuilder.substring(0, clauseBuilder.length() - 5);
        }
    }

    //order by
    String orderByText;
    if (isAsc) {
        orderByText = orderByColName == null ? null : orderByColName + " ASC";
    } else {
        orderByText = orderByColName == null ? null : orderByColName + " DESC";
    }

    if (sqLiteDatabase.isOpen())
        return sqLiteDatabase.query(DataBaseInfo.getTableNames()[tablePosition], colNames, clause, args, groupColName, having, orderByText, limit);
    return null;
}
 
Example #12
Source File: QueryBuilder.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
/**
 * 查询数据库,不能在主线程执行
 *
 * 执行callback后返回值
 */
@CheckReturnValue
public synchronized <T> T executeAsync(QuerySyncResultCallback<T> callBack) {
    ActionBuilder.checkThreadLocal();

    Cursor cursor = execute();
    T result = callBack.onQuery(cursor);
    //自动检查Cursor是否关闭
    if (cursor != null && !cursor.isClosed()) {
        cursor.close();
    }
    return result;
}
 
Example #13
Source File: RxDatabaseReference.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
/**
 * @param ref
 * @param function
 * @param fireLocalEvents
 * @return
 */
@NonNull
@CheckReturnValue
public static Single<DataSnapshot> transaction(
        @NonNull final DatabaseReference ref,
        @NonNull final Function<MutableData, Transaction.Result> function,
        final boolean fireLocalEvents) {
    return Single.create(new SingleOnSubscribe<DataSnapshot>() {
        @Override
        public void subscribe(
                @NonNull final SingleEmitter<DataSnapshot> emit) throws Exception {
            ref.runTransaction(transaction(emit, function), fireLocalEvents);
        }
    });
}
 
Example #14
Source File: RxFirebaseStorage.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
/**
 * @see StorageReference#getMetadata()
 */
@CheckReturnValue
@NonNull
public static Single<StorageMetadata> getMetadata(@NonNull final StorageReference ref) {
    return RxTask.single(new Callable<Task<StorageMetadata>>() {
        @Override
        public Task<StorageMetadata> call() throws Exception {
            return ref.getMetadata();
        }
    });
}
 
Example #15
Source File: RealRxPermission.java    From RxPermission with Apache License 2.0 5 votes vote down vote up
/**
 * Map emitted items from the source observable into {@link Permission} objects for each
 * permission in parameters.
 * <p>
 * If one or several permissions have never been requested, invoke the related framework method
 * to ask the user if he allows the permissions.
 */
@NonNull @CheckReturnValue private <T> ObservableTransformer<T, Permission> ensureEach(@NonNull final String... permissions) {
  checkPermissions(permissions);

  return new ObservableTransformer<T, Permission>() {
    @Override @NonNull @CheckReturnValue public ObservableSource<Permission> apply(final Observable<T> o) {
      return request(o, permissions);
    }
  };
}
 
Example #16
Source File: RxFirebaseStorage.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
/**
 * @see StorageReference#getBytes(long)
 */
@CheckReturnValue
@NonNull
public static Single<byte[]> getBytes(@NonNull final StorageReference ref,
                                      final long maxDownloadSizeBytes) {
    return RxTask.single(new Callable<Task<byte[]>>() {
        @Override
        public Task<byte[]> call() throws Exception {
            return ref.getBytes(maxDownloadSizeBytes);
        }
    });
}
 
Example #17
Source File: RxFirebaseDatabase.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
/**
 * @param ref
 * @return
 */
@NonNull
@CheckReturnValue
public static Completable removeValue(@NonNull final DatabaseReference ref) {
    return RxTask.completes(new Callable<Task<Void>>() {
        @Override
        public Task<Void> call() throws Exception {
            return ref.removeValue();
        }
    });
}
 
Example #18
Source File: RxValue.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
/**
 * @param query
 * @return
 */
@NonNull
@CheckReturnValue
public static Observable<DataSnapshot> changes(@NonNull final Query query) {
    return Observable.create(new ObservableOnSubscribe<DataSnapshot>() {
        @Override
        public void subscribe(
                @NonNull final ObservableEmitter<DataSnapshot> emit) throws Exception {
            final ValueEventListener listener = new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    if (!emit.isDisposed()) {
                        emit.onNext(dataSnapshot);
                    }
                }

                @Override
                public void onCancelled(DatabaseError e) {
                    if (!emit.isDisposed()) {
                        emit.onError(e.toException());
                    }
                }
            };

            emit.setCancellable(new Cancellable() {
                @Override
                public void cancel() throws Exception {
                    query.removeEventListener(listener);
                }
            });

            query.addValueEventListener(listener);
        }
    });
}
 
Example #19
Source File: RxFirebaseStorage.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
/**
 * @see StorageReference#putFile(Uri)
 */
@CheckReturnValue
@NonNull
public static Single<UploadTask.TaskSnapshot> putFile(@NonNull final StorageReference ref,
                                                      @NonNull final Uri uri) {
    return RxTask.single(new Callable<Task<UploadTask.TaskSnapshot>>() {
        @Override
        public Task<UploadTask.TaskSnapshot> call() throws Exception {
            return ref.putFile(uri);
        }
    });
}
 
Example #20
Source File: RxValue.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
/**
 * @param ref
 * @param function
 * @param fireLocalEvents
 * @return
 */
@NonNull
@CheckReturnValue
public static Single<DataSnapshot> transaction(
        @NonNull final DatabaseReference ref,
        @NonNull final Function<MutableData, Transaction.Result> function,
        final boolean fireLocalEvents) {
    return Single.create(new SingleOnSubscribe<DataSnapshot>() {
        @Override
        public void subscribe(
                @NonNull final SingleEmitter<DataSnapshot> emit) throws Exception {
            ref.runTransaction(transaction(emit, function), fireLocalEvents);
        }
    });
}
 
Example #21
Source File: RxValue.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
/**
 * @param emitter
 * @param function
 * @return
 */
@NonNull
@CheckReturnValue
public static Transaction.Handler transaction(
        @NonNull final SingleEmitter<DataSnapshot> emitter,
        @NonNull final Function<MutableData, Transaction.Result> function) {
    return new Transaction.Handler() {
        @Override
        public Transaction.Result doTransaction(MutableData mutableData) {
            try {
                return function.apply(mutableData);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public void onComplete(@Nullable DatabaseError databaseError,
                               boolean committed,
                               @NonNull DataSnapshot dataSnapshot) {
            if (!emitter.isDisposed()) {
                if (null == databaseError) {
                    emitter.onSuccess(dataSnapshot);
                } else {
                    emitter.onError(databaseError.toException());
                }
            }
        }
    };
}
 
Example #22
Source File: RxFirebaseStorage.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
/**
 * @see StorageReference#putFile(Uri, StorageMetadata)
 */
@CheckReturnValue
@NonNull
public static Single<UploadTask.TaskSnapshot> putFile(
        @NonNull final StorageReference ref,
        @NonNull final Uri uri,
        @NonNull final StorageMetadata storageMetadata) {
    return RxTask.single(new Callable<Task<UploadTask.TaskSnapshot>>() {
        @Override
        public Task<UploadTask.TaskSnapshot> call() throws Exception {
            return ref.putFile(uri, storageMetadata);
        }
    });
}
 
Example #23
Source File: RxFirebaseStorage.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
/**
 * @see StorageReference#putFile(Uri, StorageMetadata, Uri)
 */
@CheckReturnValue
@NonNull
public static Single<UploadTask.TaskSnapshot> putFile(
        @NonNull final StorageReference ref,
        @NonNull final Uri uri,
        @Nullable final StorageMetadata storageMetadata,
        @Nullable final Uri existingUploadUri) {
    return RxTask.single(new Callable<Task<UploadTask.TaskSnapshot>>() {
        @Override
        public Task<UploadTask.TaskSnapshot> call() throws Exception {
            return ref.putFile(uri, storageMetadata, existingUploadUri);
        }
    });
}
 
Example #24
Source File: RxFirebaseAuth.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
/**
 * @param instance
 * @param credential
 * @return
 */
@CheckReturnValue
@NonNull
public static Single<FirebaseUser> signInWithCredential(
        @NonNull final FirebaseAuth instance, @NonNull final AuthCredential credential) {
    return RxTask.single(new Callable<Task<AuthResult>>() {
        @Override
        public Task<AuthResult> call() throws Exception {
            return instance.signInWithCredential(credential);
        }
    }).map(authToUserFunction());
}
 
Example #25
Source File: RxFirebaseDatabase.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
/**
 * @param query
 * @param clazz
 * @param <T>
 * @return
 */
@NonNull
@CheckReturnValue
public static <T> Observable<DataValue<T>> dataChangesOf(
        @NonNull final Query query, @NonNull final Class<T> clazz) {
    return dataChanges(query).compose(new TransformerOfClazz<>(clazz));
}
 
Example #26
Source File: RxFirebaseDatabase.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
/**
 * @param ref
 * @param typeIndicator
 * @param <T>
 * @return
 */
@NonNull
@CheckReturnValue
public static <T> Observable<DataValue<T>> dataChangesOf(
        @NonNull DatabaseReference ref, @NonNull GenericTypeIndicator<T> typeIndicator) {
    return dataChanges(ref)
            .compose(new TransformerOfGenericTypeIndicator<T>(typeIndicator));
}
 
Example #27
Source File: RxFirebaseDatabase.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
/**
 * @param query
 * @param typeIndicator
 * @param <T>
 * @return
 */
@NonNull
@CheckReturnValue
public static <T> Observable<DataValue<T>> dataChangesOf(
        @NonNull Query query, @NonNull GenericTypeIndicator<T> typeIndicator) {
    return dataChanges(query)
            .compose(new TransformerOfGenericTypeIndicator<T>(typeIndicator));
}
 
Example #28
Source File: RxFirebaseDatabase.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
/**
 * @param ref
 * @param clazz
 * @param <T>
 * @return
 */
@NonNull
@CheckReturnValue
public static <T> Single<T> dataOf(
        @NonNull DatabaseReference ref, @NonNull Class<T> clazz) {
    return data(ref).compose(new SingleTransformerOfClazz<>(clazz));
}
 
Example #29
Source File: RxFirebaseDatabase.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
/**
 * @param query
 * @param clazz
 * @param <T>
 * @return
 */
@NonNull
@CheckReturnValue
public static <T> Single<T> dataOf(
        @NonNull Query query, @NonNull Class<T> clazz) {
    return data(query).compose(new SingleTransformerOfClazz<T>(clazz));
}
 
Example #30
Source File: RxFirebaseDatabase.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
/**
 * @param ref
 * @param typeIndicator
 * @param <T>
 * @return
 */
@NonNull
@CheckReturnValue
public static <T> Single<T> dataOf(
        @NonNull DatabaseReference ref, @NonNull GenericTypeIndicator<T> typeIndicator) {
    return data(ref).compose(new SingleTransformerOfGenericTypeIndicator<T>(typeIndicator));
}