当前位置: 首页>>代码示例>>Java>>正文


Java Single类代码示例

本文整理汇总了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();
}
 
开发者ID:d4rken,项目名称:RxShell,代码行数:23,代码来源:RootKiller.java

示例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());
}
 
开发者ID:Frank1234,项目名称:FireBaseTest,代码行数:17,代码来源:ContentPresenterTest.java

示例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));
            });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:23,代码来源:WallsImpl.java

示例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));
    });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:21,代码来源:KeysPersistStore.java

示例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;
    });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:23,代码来源:MessagesStore.java

示例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();
            });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:26,代码来源:RelationshipInteractor.java

示例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;
            });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:17,代码来源:DatabaseInteractor.java

示例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);
}
 
开发者ID:xufreshman,项目名称:RxLifeCycle,代码行数:17,代码来源:UntilLifecycleTransformerSingleTest.java

示例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);
    });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:17,代码来源:KeysRamStore.java

示例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());
}
 
开发者ID:florent37,项目名称:Android-Allocine-Api,代码行数:30,代码来源:AllocineApi.java

示例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));
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:8,代码来源:WallsImpl.java

示例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());
}
 
开发者ID:Bandwidth,项目名称:async-sqs,代码行数:8,代码来源:DeleteMessageTaskTest.java

示例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);
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:9,代码来源:IFriendsService.java

示例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));
            });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:14,代码来源:DocsInteractor.java

示例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;
                }
            });
}
 
开发者ID:RikkaApps,项目名称:FCM-for-Mojo,代码行数:12,代码来源:DiscussWhitelistActivity.java


注:本文中的io.reactivex.Single类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。