Java Code Examples for io.reactivex.Observable#empty()

The following examples show how to use io.reactivex.Observable#empty() . 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: Cartesian.java    From akarnokd-misc with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: LocalStoriesDataSource.java    From News with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example 3
Source File: ObservableTest.java    From Java-programming-methodology-Rxjava-articles with Apache License 2.0 5 votes vote down vote up
@Test
void empty_test() {
    Observable<Object> empty = Observable.empty();
    empty.subscribe(System.out::println,
            Throwable::printStackTrace,
            () -> System.out.println("I am Done!! Completed normally"));
}
 
Example 4
Source File: RxPermissions.java    From GankGirl with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Observable<?> pending(final String... permissions) {
    for (String p : permissions) {
        if (!mRxPermissionsFragment.containsByPermission(p)) {
            return Observable.empty();
        }
    }
    return Observable.just(TRIGGER);
}
 
Example 5
Source File: Presenter.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 6
Source File: Presenter.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
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
}
 
Example 7
Source File: RxModule.java    From AndroidGodEye with Apache License 2.0 5 votes vote down vote up
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();
    }
}
 
Example 8
Source File: TimelineModel.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
@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();
}
 
Example 9
Source File: Demo_switchIfEmpty.java    From Reactive-Programming-With-Java-9 with MIT License 5 votes vote down vote up
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);
				}
	});

}
 
Example 10
Source File: DemoObservable_empty.java    From Reactive-Programming-With-Java-9 with MIT License 5 votes vote down vote up
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"));
}
 
Example 11
Source File: Optional.java    From RxEasyHttp with Apache License 2.0 5 votes vote down vote up
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));
    }
}
 
Example 12
Source File: SwitchFallback.java    From akarnokd-misc with Apache License 2.0 5 votes vote down vote up
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);
            });
}
 
Example 13
Source File: UseCaseTest.java    From Android-CleanArchitecture with Apache License 2.0 4 votes vote down vote up
@Override Observable<Object> buildUseCaseObservable(Params params) {
  return Observable.empty();
}
 
Example 14
Source File: RetrofitCurrencyDataSource.java    From exchange-rates-mvvm with Apache License 2.0 4 votes vote down vote up
@Override
public Observable<SingleValue> getCurrencyValues(final Date startDate, final Date endDate, final String currencyCode) {
    return Observable.empty();
}
 
Example 15
Source File: Delivery.java    From GankGirl with GNU Lesser General Public License v2.1 4 votes vote down vote up
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();
}
 
Example 16
Source File: ObservableReturnValueHandlerTest.java    From rxjava-spring-boot-starter with Apache License 2.0 4 votes vote down vote up
@RequestMapping(method = RequestMethod.GET, value = "/empty")
public Observable<Void> empty() {
    return Observable.empty();
}
 
Example 17
Source File: ObservableDeferredResultTest.java    From rxjava-spring-boot-starter with Apache License 2.0 4 votes vote down vote up
@RequestMapping(method = RequestMethod.GET, value = "/empty")
public ObservableDeferredResult<String> empty() {
    return new ObservableDeferredResult<String>(Observable.<String>empty());
}
 
Example 18
Source File: ObservableResourceTest.java    From rx-jersey with MIT License 4 votes vote down vote up
@GET
@Path("empty")
public Observable<String> empty() {
    return Observable.empty();
}
 
Example 19
Source File: ObservableDeferredResultTest.java    From Java-9-Spring-Webflux with Apache License 2.0 4 votes vote down vote up
@RequestMapping(method = RequestMethod.GET, value = "/empty")
public ObservableDeferredResult<String> empty() {
    return new ObservableDeferredResult<>(Observable.<String>empty());
}
 
Example 20
Source File: ObservableDeferredResultTest.java    From Java-programming-methodology-Rxjava-articles with Apache License 2.0 4 votes vote down vote up
@RequestMapping(method = RequestMethod.GET, value = "/empty")
public ObservableDeferredResult<String> empty() {
    return new ObservableDeferredResult<>(Observable.<String>empty());
}