本文整理汇总了Java中io.reactivex.Single.error方法的典型用法代码示例。如果您正苦于以下问题:Java Single.error方法的具体用法?Java Single.error怎么用?Java Single.error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.Single
的用法示例。
在下文中一共展示了Single.error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: morePlaylists
import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<List<PlaylistEntity>> morePlaylists() {
Page<?> page=queryMap.get(Type.PLAYLIST);
if(page!=null){
if(page.isLast) {
return Single.just(new ArrayList<>());
}
return service.searchPlaylistsPage(PlaylistEntity.Filter.start()
.nextPage(page).limit(100).createOptions())
.map(result->{
if(result!=null){
queryMap.put(Type.PLAYLIST,result);
return result.collection;
}
return null;
}).map(filter::filterPlaylists);
}
return Single.error(new IllegalArgumentException("You haven't made a query!"));
}
示例2: queryMetadata
import io.reactivex.Single; //导入方法依赖的package包/类
private static synchronized Single<HashMap<String, String>> queryMetadata(Database dataSource) {
final URL url = Resources.getResource("metadata_key_value.sql");
String query;
try {
query = Resources.toString(url, Charsets.UTF_8);
} catch (final IOException ex) {
return Single.error(ex);
}
return dataSource.select(query).get(new ResultSetMapper<HashMap<String, String>>() {
@Override
public HashMap<String, String> apply(@Nonnull ResultSet rs) throws SQLException {
final HashMap<String, String> metadata = new LinkedHashMap<>();
while (rs.getRow() != 0) {
metadata.put(rs.getString("name"), rs.getString("value"));
rs.next();
}
return metadata;
}
}).singleOrError();
}
示例3: getUserBy
import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<UserDetailsEntity> getUserBy(String id) {
if(id!=null){
Single<List<TrackEntity>> singleTracks=service.fetchUserTracks(id)
.subscribeOn(schedulerProvider.multi());
Single<List<PlaylistEntity>> singlePlaylists=service.fetchUserPlaylists(id)
.subscribeOn(schedulerProvider.multi());
Single<UserEntity> singleUser=service.fetchUser(id)
.subscribeOn(schedulerProvider.multi());
return Single.zip(singleUser,
singleTracks.onErrorResumeNext(Single.just(new ArrayList<>())),
singlePlaylists.onErrorResumeNext(Single.just(new ArrayList<>())),
(user,tracks,playlists)->{
UserDetailsEntity userDetails=new UserDetailsEntity();
userDetails.setUserEntity(user);
userDetails.setTracks(filter.filterTracks(tracks));
userDetails.setPlaylists(filter.filterPlaylists(playlists));
return userDetails;
});
}
return Single.error(new IllegalArgumentException("id is null"));
}
示例4: getPlaylistsBy
import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<List<PlaylistEntity>> getPlaylistsBy(List<String> categories) {
if(categories!=null) {
Single<List<PlaylistEntity>> start = Single.just(new LinkedList<>());
for(String category:categories){
start=Single.zip(start,service.searchPlaylists(PlaylistEntity
.Filter.start()
.byName(category)
.limit(100)
.createOptions())
.onErrorResumeNext(Single.just(new ArrayList<>())),(first,second)->{
if(second!=null){
first.addAll(second);
}
return first;
});
}
return start.map(filter::filterPlaylists);
}
return Single.error(new IllegalArgumentException("categories are null"));
}
示例5: getContentItem
import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<ContentItem> getContentItem(int id) {
if (fakeData != null) {
ContentItem contentItem = contentItemController.
findItemForId(fakeData, id);
if (contentItem != null) {
return Single.just(contentItem);
} else {
return Single.error(new Exception("ContentItem not found"));
}
} else {
return Single.error(new Exception("My mocked/fake error"));
}
}
示例6: moreTracks
import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<List<TrackEntity>> moreTracks() {
Page<?> page=queryMap.get(Type.TRACK);
if(page!=null){
if(page.isLast) {
return Single.just(new ArrayList<>());
}
return service.searchTracksPage(TrackEntity.Filter.start()
.nextPage(page).limit(100).createOptions())
.map(result->{
if(result!=null){
queryMap.put(Type.TRACK,result);
return result.collection;
}
return null;
}).map(filter::filterTracks);
}
return Single.error(new IllegalArgumentException("You haven't made a query!"));
}
示例7: buildUseCase
import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<TrackSet> buildUseCase(MelophileTheme theme) {
if(theme!=null){
return repository.getTracksBy(theme)
.map(list -> new TrackSet(theme, list));
}
return Single.error(new IllegalArgumentException("Melophile theme is null!"));
}
示例8: getUserFollowers
import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<List<User>> getUserFollowers(String id) {
if(!TextUtils.isEmpty(id)){
return Single.fromCallable(()->userHandler.queryFollowers(id));
}
return Single.error(new IllegalArgumentException("Id is empty"));
}
示例9: getUserFollowers
import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<List<UserEntity>> getUserFollowers(String id) {
if(!TextUtils.isEmpty(id)){
return service.fetchUserFollowers(id)
.map(page->page.collection)
.map(filter::filterUsers);
}
return Single.error(new IllegalArgumentException("id is null"));
}
示例10: post
import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<Post> post(int accountId, int ownerId, Boolean friendsOnly, Boolean fromGroup, String message,
List<AbsModel> attachments, String services, Boolean signed,
Long publishDate, Double latitude, Double longitude, Integer placeId,
final Integer postId, Integer guid, Boolean markAsAds, Boolean adsPromotedStealth) {
List<IAttachmentToken> tokens = null;
try {
if (nonEmpty(attachments)) {
tokens = Model2Dto.createTokens(attachments);
}
} catch (Exception e) {
return Single.error(e);
}
return networker.vkDefault(accountId)
.wall()
.post(ownerId, friendsOnly, fromGroup, message, tokens, services, signed, publishDate,
latitude, longitude, placeId, postId, guid, markAsAds, adsPromotedStealth)
.flatMap(vkid -> {
Completable completable;
if (nonNull(postId) && !postId.equals(vkid)) {
// если id поста изменился - удаляем его из бд
completable = invalidatePost(accountId, postId, ownerId);
} else {
completable = Completable.complete();
}
return completable.andThen(getAndStorePost(accountId, ownerId, vkid));
});
}
示例11: internalSend
import io.reactivex.Single; //导入方法依赖的package包/类
private Single<Integer> internalSend(int accountId, MessageEntity dbo) {
if (isEmpty(dbo.getExtras()) && isEmpty(dbo.getAttachments()) && dbo.getForwardCount() == 0) {
return networker.vkDefault(accountId)
.messages()
.send(dbo.getId(), dbo.getPeerId(), null, dbo.getBody(), null, null, null, null, null);
}
final Collection<IAttachmentToken> attachments = new LinkedList<>();
try {
if (nonEmpty(dbo.getAttachments())) {
for (Entity a : dbo.getAttachments()) {
if (a instanceof StickerEntity) {
final int stickerId = ((StickerEntity) a).getId();
return networker.vkDefault(accountId)
.messages()
.send(dbo.getId(), dbo.getPeerId(), null, null, null, null, null, null, stickerId);
}
attachments.add(Entity2Dto.createToken(a));
}
}
} catch (Exception e) {
return Single.error(e);
}
return checkVoiceMessage(accountId, dbo)
.flatMap(optionalToken -> {
if (optionalToken.nonEmpty()) {
attachments.add(optionalToken.get());
}
return checkForwardMessages(accountId, dbo)
.flatMap(optionalFwd -> networker.vkDefault(accountId)
.messages()
.send(dbo.getId(), dbo.getPeerId(), null, dbo.getBody(), null, null, attachments, optionalFwd.get(), null));
});
}
示例12: getUserFavorites
import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<List<TrackEntity>> getUserFavorites(String id) {
if(!TextUtils.isEmpty(id)){
return service.fetchUserFavoriteTracks(id)
.map(filter::filterTracks);
}
return Single.error(new IllegalArgumentException("id is null"));
}
示例13: buildUseCase
import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<Playlist> buildUseCase(String id) {
if(id==null||id.isEmpty()){
return Single.error(new IllegalArgumentException("Id is null"));
}
return repository.getPlaylistBy(id);
}
示例14: searchOnError
import io.reactivex.Single; //导入方法依赖的package包/类
@Test
public void searchOnError() {
String location = "Parts Unknown";
LocationNotFoundError locationError = new LocationNotFoundError(location);
Single<Channel> single = Single.error(locationError);
when(weatherRepository.getForecast(location)).thenReturn(single);
presenter.search(location);
verify(view).showLoading(false);
assertThat(presenter.getChannel(), is(nullValue()));
verify(view).showError(locationError, false);
}
示例15: buildUseCase
import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<List<Track>> buildUseCase(String id) {
if(!TextUtils.isEmpty(id)){
return repository.getUserFavorites(id);
}
return Single.error(new IllegalArgumentException("Id is null"));
}