io.reactivex.Observable#empty ( )源码实例Demo

下面列出了io.reactivex.Observable#empty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: News   文件: LocalStoriesDataSource.java
@Override
public Observable<List<Story>> getStories(String date) {
    List<Story> storyList = new ArrayList<>();
    SQLiteDatabase database = this.mDbHelper.getReadableDatabase();
    String[] projections = {
            StoriesPersistenceContract.StoryEntry.COLUMN_NAME_STORY_ID,
            StoriesPersistenceContract.StoryEntry.COLUMN_NAME_TITLE};
    Cursor cursor = database.query(StoriesPersistenceContract.StoryEntry.TABLE_NAME, projections, null, null, null, null, null);
    if (cursor != null && cursor.getCount() > 0) {
        while (cursor.moveToNext()) {
            int storyId = cursor.getInt(cursor.getColumnIndexOrThrow(StoriesPersistenceContract.StoryEntry.COLUMN_NAME_STORY_ID));
            String title = cursor.getString(cursor.getColumnIndexOrThrow(StoriesPersistenceContract.StoryEntry.COLUMN_NAME_TITLE));
            Story story = new Story(storyId, title);
            storyList.add(story);
        }
    }
    if (cursor != null) {
        cursor.close();
    }
    database.close();
    if (storyList.size() == 0) {
        return Observable.empty();
    } else {
        return Observable.just(storyList);
    }
}
 
源代码2 项目: akarnokd-misc   文件: Cartesian.java
static Observable<int[]> cartesian(List<Observable<Integer>> sources) {
    if (sources.size() == 0) {
        return Observable.<int[]>empty();
    }
    Observable<int[]> main = sources.get(0).map(v -> new int[] { v });
    
    for (int i = 1; i < sources.size(); i++) {
        int j = i;
        Observable<Integer> o = sources.get(i).cache();
        main = main.flatMap(v -> {
            return o.map(w -> {
                int[] arr = Arrays.copyOf(v, j + 1);
                arr[j] = w;
                return arr;
            });
        });
    }
    
    return main;
}
 
@Test
void empty_test() {
    Observable<Object> empty = Observable.empty();
    empty.subscribe(System.out::println,
            Throwable::printStackTrace,
            () -> System.out.println("I am Done!! Completed normally"));
}
 
源代码4 项目: akarnokd-misc   文件: SwitchFallback.java
public static void main(String[] args) {
    Observable<List<Integer>> source = Observable.empty();

            Observable<List<Integer>> fallbackSource = Observable.empty();

            source.flatMap(list -> {
                if (list.isEmpty()) {
                    return fallbackSource;
                }
                return Observable.just(list);
            });
}
 
源代码5 项目: RxEasyHttp   文件: Optional.java
public static <T> Optional<T> ofNullable(T value) {
    if (value == null) {
        return new Optional<T>(Observable.<T>empty());
    } else {
        return new Optional<T>(Observable.just(value));
    }
}
 
public static void main(String[] args) {
	// TODO Auto-generated method stub
	Observable<String> observable = Observable.empty();
	observable.subscribe(item -> System.out.println("we got" + item), 
			error -> System.out.print(error),
			()->System.out.print("I am Done!! Completed normally"));
}
 
public static void main(String[] args) {
	Observable source2 = Observable.empty();
	source2.switchIfEmpty(Observable.just(10)).subscribe(
	    new Consumer<Integer>() {

				@Override
				public void accept(Integer value) throws Exception {
					// TODO Auto-generated method stub
					System.out.println("value emitted:"+value);
				}
	});

}
 
源代码8 项目: mvvm-template   文件: TimelineModel.java
@NonNull
public static Observable<List<TimelineModel>> construct(@Nullable List<Comment> comments) {
    if (comments == null || comments.isEmpty()) return Observable.empty();
    return Observable.fromIterable(comments)
            .map(TimelineModel::new)
            .toList()
            .toObservable();
}
 
源代码9 项目: AndroidGodEye   文件: RxModule.java
public static <T> Observable<T> wrapThreadComputationObservable(@GodEye.ModuleName String moduleName) {
    try {
        T module = GodEye.instance().getModule(moduleName);
        if (!(module instanceof SubjectSupport)) {
            throw new UnexpectException(moduleName + " is not instance of SubjectSupport.");
        }
        // noinspection unchecked
        return wrapThreadComputationObservable(((SubjectSupport<T>) module).subject());
    } catch (UninstallException e) {
        L.d(moduleName + " is not installed.");
        return Observable.empty();
    }
}
 
源代码10 项目: RxAndroidBle   文件: Presenter.java
private static Observable<PresenterEvent> setupReadingBehaviour(Observable<Boolean> readClicks,
                                                                BluetoothGattCharacteristic characteristic,
                                                                RxBleConnection connection) {
    return !hasProperty(characteristic, BluetoothGattCharacteristic.PROPERTY_READ)
            // if the characteristic is not readable return an empty (dummy) observable
            ? Observable.empty()
            : readClicks // else use the readClicks observable from the activity
            // every click is requesting a read operation from the peripheral
            .flatMapSingle(ignoredClick -> connection.readCharacteristic(characteristic))
            .compose(transformToPresenterEvent(Type.READ)); // convenience method to wrap reads
}
 
源代码11 项目: RxAndroidBle   文件: Presenter.java
private static Observable<PresenterEvent> setupWritingBehaviour(Observable<byte[]> writeClicks,
                                                                BluetoothGattCharacteristic characteristic,
                                                                RxBleConnection connection) {
    // basically the same logic as in the reads
    return !hasProperty(characteristic, BluetoothGattCharacteristic.PROPERTY_WRITE)
            ? Observable.empty()
            : writeClicks // with exception that clicks emit byte[] to write
            .flatMapSingle(bytes -> connection.writeCharacteristic(characteristic, bytes))
            .compose(transformToPresenterEvent(Type.WRITE));
}
 
源代码12 项目: GankGirl   文件: RxPermissions.java
private Observable<?> pending(final String... permissions) {
    for (String p : permissions) {
        if (!mRxPermissionsFragment.containsByPermission(p)) {
            return Observable.empty();
        }
    }
    return Observable.just(TRIGGER);
}
 
@RequestMapping(method = RequestMethod.GET, value = "/empty")
public ObservableDeferredResult<String> empty() {
    return new ObservableDeferredResult<>(Observable.<String>empty());
}
 
@RequestMapping(method = RequestMethod.GET, value = "/empty")
public ObservableDeferredResult<String> empty() {
    return new ObservableDeferredResult<>(Observable.<String>empty());
}
 
源代码15 项目: Android-CleanArchitecture   文件: UseCaseTest.java
@Override Observable<Object> buildUseCaseObservable(Params params) {
  return Observable.empty();
}
 
@Override
public Observable<SingleValue> getCurrencyValues(final Date startDate, final Date endDate, final String currencyCode) {
    return Observable.empty();
}
 
源代码17 项目: GankGirl   文件: Delivery.java
public static <View, T> Observable<Delivery<View, T>> validObservable(OptionalView<View> view, Notification<T> notification) {
    return isValid(view, notification) ?
            Observable.just(new Delivery<>(view.view, notification)) :
            Observable.<Delivery<View, T>>empty();
}
 
@RequestMapping(method = RequestMethod.GET, value = "/empty")
public Observable<Void> empty() {
    return Observable.empty();
}
 
@RequestMapping(method = RequestMethod.GET, value = "/empty")
public ObservableDeferredResult<String> empty() {
    return new ObservableDeferredResult<String>(Observable.<String>empty());
}
 
源代码20 项目: rx-jersey   文件: ObservableResourceTest.java
@GET
@Path("empty")
public Observable<String> empty() {
    return Observable.empty();
}