本文整理汇总了Java中io.reactivex.Single类的典型用法代码示例。如果您正苦于以下问题:Java Single类的具体用法?Java Single怎么用?Java Single使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Single类属于io.reactivex包,在下文中一共展示了Single类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeMiniHarvester
import io.reactivex.Single; //导入依赖的package包/类
static Single<List<String>> makeMiniHarvester(InputStream inputStream) {
return Observable
.create((ObservableOnSubscribe<String>) emitter -> {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
LineReader lineReader = new LineReader();
String line;
try {
while ((line = lineReader.readLine(reader)) != null && !emitter.isDisposed()) {
emitter.onNext(line);
}
} catch (IOException e) {
if (RXSDebug.isDebug()) Timber.tag(TAG).d("MiniHarvester read error: %s", e.getMessage());
} finally {
emitter.onComplete();
}
})
.doOnEach(n -> { if (RXSDebug.isDebug()) Timber.tag(TAG).v("miniHarvesters:doOnEach %s", n); })
.subscribeOn(Schedulers.io())
.toList()
.onErrorReturnItem(new ArrayList<>())
.cache();
}
示例2: loadingErrorAtRepository_UpdateViewModelToDisplayError
import io.reactivex.Single; //导入依赖的package包/类
@Test
public void loadingErrorAtRepository_UpdateViewModelToDisplayError() {
when(contentRepository.getContentItem(anyInt())).thenReturn(Single.error(new RuntimeException()));
assertTrue(viewModel.isShowLoadingIndicator());
assertFalse(viewModel.isShowErrorMessage());
contentPresenter.loadContent();
testScheduler.triggerActions();
assertFalse(viewModel.isShowLoadingIndicator());
assertTrue(viewModel.isShowErrorMessage());
assertNull(viewModel.getContentDescription());
assertNull(viewModel.getImageUrl());
}
示例3: getById
import io.reactivex.Single; //导入依赖的package包/类
@Override
public Single<Post> getById(int accountId, int ownerId, int postId) {
final IdPair id = new IdPair(postId, ownerId);
return networker.vkDefault(accountId)
.wall()
.getById(Collections.singleton(id), true, 5, Constants.MAIN_OWNER_FIELDS)
.flatMap(response -> {
if(isEmpty(response.posts)){
throw new NotFoundException();
}
List<Owner> owners = Dto2Model.transformOwners(response.profiles, response.groups);
List<VKApiPost> dtos = response.posts;
VKApiPost dto = dtos.get(0);
VKOwnIds ids = new VKOwnIds().append(dto);
return ownersInteractor.findBaseOwnersDataAsBundle(accountId, ids.getAll(), IOwnersInteractor.MODE_ANY, owners)
.map(bundle -> Dto2Model.transform(dto, bundle));
});
}
示例4: findLastKeyPair
import io.reactivex.Single; //导入依赖的package包/类
@Override
public Single<Optional<AesKeyPair>> findLastKeyPair(int accountId, int peerId) {
return Single.create(e -> {
Uri uri = MessengerContentProvider.getKeysContentUriFor(accountId);
Cursor cursor = getContext().getContentResolver()
.query(uri, null, KeyColumns.PEER_ID + " = ?",
new String[]{String.valueOf(peerId)}, KeyColumns._ID + " DESC LIMIT 1");
AesKeyPair pair = null;
if(nonNull(cursor)){
if(cursor.moveToNext()){
pair = map(cursor).setAccountId(accountId);
}
cursor.close();
}
e.onSuccess(Optional.wrap(pair));
});
}
示例5: calculateUnreadCount
import io.reactivex.Single; //导入依赖的package包/类
@Override
public Single<Integer> calculateUnreadCount(int accountId, int peerId) {
return Single.fromCallable(() -> {
int result = 0;
Cursor cursor = DBHelper.getInstance(getContext(), accountId)
.getReadableDatabase()
.rawQuery("SELECT COUNT(" + MessageColumns._ID + ") FROM " + MessageColumns.TABLENAME +
" WHERE " + MessageColumns.PEER_ID + " = ?" +
" AND " + MessageColumns.READ_STATE + " = ?" +
" AND " + MessageColumns.OUT + " = ?" +
" AND " + MessageColumns.ATTACH_TO + " = ?" +
" AND " + MessageColumns.DELETED + " = ?",
new String[]{String.valueOf(peerId), "0", "0", "0", "0"});
if (cursor.moveToNext()) {
result = cursor.getInt(0);
}
cursor.close();
return result;
});
}
示例6: deleteFriends
import io.reactivex.Single; //导入依赖的package包/类
@Override
public Single<Integer> deleteFriends(int accountId, int userId) {
return networker.vkDefault(accountId)
.friends()
.delete(userId)
.map(response -> {
if(response.friend_deleted){
return DeletedCodes.FRIEND_DELETED;
}
if(response.in_request_deleted){
return DeletedCodes.IN_REQUEST_DELETED;
}
if(response.out_request_deleted){
return DeletedCodes.OUT_REQUEST_DELETED;
}
if(response.suggestion_deleted){
return DeletedCodes.SUGGESTION_DELETED;
}
throw new UnepectedResultException();
});
}
示例7: getChairs
import io.reactivex.Single; //导入依赖的package包/类
@Override
public Single<List<Chair>> getChairs(int accoutnId, int facultyId, int count, int offset) {
return networker.vkDefault(accoutnId)
.database()
.getChairs(facultyId, offset, count)
.map(items -> {
List<ChairDto> dtos = Utils.listEmptyIfNull(items.getItems());
List<Chair> chairs = new ArrayList<>(dtos.size());
for(ChairDto dto : dtos){
chairs.add(new Chair(dto.id, dto.title));
}
return chairs;
});
}
示例8: oneEvent
import io.reactivex.Single; //导入依赖的package包/类
@Test
public void oneEvent() {
TestObserver<String> testObserver = Single.just("1")
.delay(1, TimeUnit.MILLISECONDS, testScheduler)
.compose(RxLifecycle.<String, String>bind(lifecycle))
.test();
testObserver.assertNoValues();
testObserver.assertNoErrors();
lifecycle.onNext("stop");
testScheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS);
testObserver.assertNoValues();
testObserver.assertError(CancellationException.class);
}
示例9: getKeys
import io.reactivex.Single; //导入依赖的package包/类
@Override
public Single<List<AesKeyPair>> getKeys(int accountId, int peerId) {
return Single.create(e -> {
List<AesKeyPair> list = mData.get(accountId);
List<AesKeyPair> result = new ArrayList<>(Objects.isNull(list) ? 0 : 1);
if (Objects.nonNull(list)) {
for (AesKeyPair pair : list) {
if (pair.getPeerId() == peerId) {
result.add(pair);
}
}
}
e.onSuccess(result);
});
}
示例10: searchSmall
import io.reactivex.Single; //导入依赖的package包/类
/**
* Recherche
*/
public Single<AllocineResponseSmall> searchSmall(final String recherche, final List<String> filter, final int count, final int page) {
return Single
.create(new SingleOnSubscribe<Pair<String, String>>() {
@Override
public void subscribe(SingleEmitter<Pair<String, String>> e) throws Exception {
final String params = ServiceSecurity.construireParams(false,
AllocineService.Q, "" + recherche.replace(" ", "+"),
AllocineService.FILTER, filter,
AllocineService.COUNT, "" + count,
AllocineService.PAGE, "" + page
);
final String sed = ServiceSecurity.getSED();
final String sig = ServiceSecurity.getSIG(params, sed);
e.onSuccess(Pair.create(sed, sig));
}
})
.flatMap(new Function<Pair<String, String>, SingleSource<AllocineResponseSmall>>() {
@Override
public SingleSource<AllocineResponseSmall> apply(Pair<String, String> pair) throws Exception {
return allocineService.searchSmall(recherche, ServiceSecurity.applatir(filter), count, page, pair.first, pair.second);
}
})
.compose(this.<AllocineResponseSmall>retry());
}
示例11: getCachedWall
import io.reactivex.Single; //导入依赖的package包/类
@Override
public Single<List<Post>> getCachedWall(int accountId, int ownerId, int wallFilter) {
WallCriteria criteria = new WallCriteria(accountId, ownerId).setMode(wallFilter);
return repositories.wall()
.findDbosByCriteria(criteria)
.compose(dbos2models(accountId));
}
示例12: testTaskError
import io.reactivex.Single; //导入依赖的package包/类
@Test
public void testTaskError() {
when(requestSenderMock.sendRequest(any())).thenReturn(Single.error(EXCEPTION));
task.run(QUEUE_URL, ENTRY_MAP);
ENTRY_MAP.values().forEach((entry) -> entry.getResultSubject().test().assertError(EXCEPTION));
verify(requestSenderMock).sendRequest(any());
}
示例13: search
import io.reactivex.Single; //导入依赖的package包/类
@FormUrlEncoded
@POST("friends.search")
Single<BaseResponse<Items<VKApiUser>>> search(@Field("user_id") int userId,
@Field("q") String query,
@Field("fields") String fields,
@Field("name_case") String nameCase,
@Field("offset") Integer offset,
@Field("count") Integer count);
示例14: findById
import io.reactivex.Single; //导入依赖的package包/类
@Override
public Single<Document> findById(int accountId, int ownerId, int docId) {
return networker.vkDefault(accountId)
.docs()
.getById(Collections.singletonList(new IdPair(docId, ownerId)))
.map(dtos -> {
if(dtos.isEmpty()){
throw new NotFoundException();
}
return Dto2Model.transform(dtos.get(0));
});
}
示例15: startFetchWhitelistState
import io.reactivex.Single; //导入依赖的package包/类
@Override
public Single<? extends WhitelistState> startFetchWhitelistState() {
return Single.zip(FFMService.getDiscussWhitelist(), OpenQQService.getDiscussesInfo(),
new BiFunction<DiscussWhitelistState, List<Discuss>, DiscussWhitelistState>() {
@Override
public DiscussWhitelistState apply(DiscussWhitelistState state, List<Discuss> groups) throws Exception {
state.generateStates(groups);
return state;
}
});
}