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


Java Single.fromCallable方法代码示例

本文整理汇总了Java中io.reactivex.Single.fromCallable方法的典型用法代码示例。如果您正苦于以下问题:Java Single.fromCallable方法的具体用法?Java Single.fromCallable怎么用?Java Single.fromCallable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.reactivex.Single的用法示例。


在下文中一共展示了Single.fromCallable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fetchTags

import io.reactivex.Single; //导入方法依赖的package包/类
public static Single<ImmutableMap<String, GitCommitHash>> fetchTags(final String gitURL) {

        Preconditions.checkNotNull(gitURL);

        return Single.fromCallable(() -> {

            // The repository is not actually used, JGit just seems to require it.
            final Repository repository = FileRepositoryBuilder.create(Paths.get("").toFile());
            final Collection<Ref> refs = new LsRemoteCommand(repository)
                .setRemote(gitURL)
                .setTags(true)
                .call();

            final String prefix = "refs/tags/";

            return refs.stream()
                .filter(x -> x.getTarget().getName().startsWith(prefix))
                .collect(ImmutableMap.toImmutableMap(
                    x -> x.getTarget().getName().substring(prefix.length()),
                    x -> GitCommitHash.of((x.getPeeledObjectId() == null ? x.getObjectId() : x.getPeeledObjectId()).getName())));
        });
    }
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:23,代码来源:GitTasks.java

示例2: add

import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<LogEvent> add(int type, String tag, String body) {
    return Single.fromCallable(() -> {
        long now = System.currentTimeMillis();

        ContentValues cv = new ContentValues();
        cv.put(LogColumns.TYPE, type);
        cv.put(LogColumns.TAG, tag);
        cv.put(LogColumns.BODY, body);
        cv.put(LogColumns.DATE, now);

        long id = helper().getWritableDatabase().insert(LogColumns.TABLENAME, null, cv);
        return new LogEvent((int) id)
                .setBody(body)
                .setTag(tag)
                .setDate(now)
                .setType(type);
    });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:20,代码来源:LogsStore.java

示例3: 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

示例4: getMessageStatus

import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<Integer> getMessageStatus(int accountId, int dbid) {
    return Single.fromCallable(() -> {
        Cursor cursor = getContentResolver().query(MessengerContentProvider.getMessageContentUriFor(accountId),
                new String[]{MessageColumns.STATUS}, MessageColumns.FULL_ID + " = ?", new String[]{String.valueOf(dbid)}, null);

        Integer result = null;

        if (cursor != null) {
            if (cursor.moveToNext()) {
                result = cursor.getInt(cursor.getColumnIndex(MessageColumns.STATUS));
            }

            cursor.close();
        }

        if (isNull(result)) {
            throw new RecordNotFoundException("Message with id " + dbid + " not found");
        }

        return result;
    });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:24,代码来源:MessagesStore.java

示例5: provideAuthRetrofit

import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<RetrofitWrapper> provideAuthRetrofit() {
    return Single.fromCallable(() -> {

        OkHttpClient.Builder builder = new OkHttpClient.Builder()
                .readTimeout(30, TimeUnit.SECONDS)
                .addInterceptor(HttpLogger.DEFAULT_LOGGING_INTERCEPTOR);

        ProxyUtil.applyProxyConfig(builder, proxySettings.getActiveProxy());
        Gson gson = new GsonBuilder().create();

        final Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("https://oauth.vk.com/")
                .addConverterFactory(GsonConverterFactory.create(gson))
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .client(builder.build())
                .build();

        return RetrofitWrapper.wrap(retrofit, false);
    });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:22,代码来源:OtherVkRetrofitProvider.java

示例6: getLocalLocationApiCodes

import io.reactivex.Single; //导入方法依赖的package包/类
private Single<Set<String>> getLocalLocationApiCodes() {
    return Single.fromCallable(() -> {
        final String sql = "SELECT "
                + Contract.LocationsTable.COLUMN_API_CODE
                + " FROM "
                + Contract.LocationsTable.TABLE_NAME;
        final Set<String> codes = new HashSet<>();

        try (Cursor cursor = dbHelper.getBriteDatabase().query(sql)) {
            while (cursor.moveToNext()) {
                String code = DbUtils.getStringFromCursor(
                        cursor, Contract.LocationsTable.COLUMN_API_CODE);
                codes.add(code);
            }
        }

        return codes;
    });
}
 
开发者ID:andreybgm,项目名称:gigreminder,代码行数:20,代码来源:LocationRepository.java

示例7: provideNormalRetrofit

import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<RetrofitWrapper> provideNormalRetrofit(int accountId) {
    return Single.fromCallable(() -> {
        RetrofitWrapper retrofit;

        synchronized (retrofitCacheLock){
            retrofit = retrofitCache.get(accountId);

            if (nonNull(retrofit)) {
                return retrofit;
            }

            OkHttpClient client = clientFactory.createDefaultVkHttpClient(accountId, VKGSON, proxyManager.getActiveProxy());
            retrofit = createDefaultVkApiRetrofit(client);
            retrofitCache.put(accountId, retrofit);
        }

        return retrofit;
    });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:21,代码来源:VkRetrofitProvider.java

示例8: useCoupon

import io.reactivex.Single; //导入方法依赖的package包/类
private void useCoupon() {
    DebugLog.logMethod();
    Single<Boolean> useCouponSingle = Single.fromCallable(new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            DebugLog.logMessage("useCouponSingle - call");
            return updateCouponState();
        }
    });
    useCouponSingle.subscribeOn(Schedulers.newThread())
            .observeOn(AndroidSchedulers.mainThread());
    DisposableSingleObserver<Boolean> disposableSingleObserver = useCouponSingle.subscribeWith(new DisposableSingleObserver<Boolean>() {
        @Override
        public void onSuccess(Boolean value) {
            DebugLog.logMessage("useCouponSingle - onSuccess");
            Utilities.showToast(getContext(), getString(R.string.coupon_state_update_successful));
            if (getActivity() != null) {
                getActivity().onBackPressed();
            }
        }

        @Override
        public void onError(Throwable e) {
            e.printStackTrace();
            DebugLog.logMessage("useCouponSingle - onError");
            DebugLog.logMessage(e.getMessage());
            Utilities.showToast(getContext(), getString(R.string.coupon_state_update_unsuccessful));
        }
    });
    compositeDisposable.add(disposableSingleObserver);
}
 
开发者ID:darsh2,项目名称:CouponsTracker,代码行数:32,代码来源:CouponFragment.java

示例9: handle

import io.reactivex.Single; //导入方法依赖的package包/类
public Single<Integer> handle(final BrokerAccountData brokerAccountData) {
    return Single.fromCallable(() -> {
        if (!accountInfo.isConnected())
            return ZorroReturnValues.ACCOUNT_UNAVAILABLE.getValue();

        brokerAccountData.fill(accountInfo);
        return ZorroReturnValues.ACCOUNT_AVAILABLE.getValue();
    });
}
 
开发者ID:juxeii,项目名称:dztools,代码行数:10,代码来源:BrokerAccount.java

示例10: debugAsync

import io.reactivex.Single; //导入方法依赖的package包/类
/**
 * Async, observable version of {@link #debug()}.
 * Same exceptions are passed through observable.
 */
public Single<JsonObject> debugAsync() {
  return Single.fromCallable(new Callable<JsonObject>() {
    @Override
    public JsonObject call() throws Exception {
      return debug();
    }
  });
}
 
开发者ID:filestack,项目名称:filestack-java,代码行数:13,代码来源:ImageTransform.java

示例11: createDirectory

import io.reactivex.Single; //导入方法依赖的package包/类
public static Single<CreateDirectoryEvent> createDirectory(final Path path) {
    Preconditions.checkNotNull(path);
    return Single.fromCallable(() -> {
        Files.createDirectories(path);
        return CreateDirectoryEvent.of(path);
    });
}
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:8,代码来源:CommonTasks.java

示例12: getPlaylistBy

import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<Playlist> getPlaylistBy(String id) {
    if(!TextUtils.isEmpty(id)){
        return Single.fromCallable(()->playlistHandler.query(id));
    }
    return Single.error(new IllegalArgumentException("Id is empty or null"));
}
 
开发者ID:vpaliyX,项目名称:Melophile,代码行数:8,代码来源:LocalMusicSource.java

示例13: getContentAsync

import io.reactivex.Single; //导入方法依赖的package包/类
/**
 * Asynchronously returns the content of a transformation.
 *
 * @see #getContent()
 */
public Single<ResponseBody> getContentAsync() {
  return Single.fromCallable(new Callable<ResponseBody>() {
    @Override
    public ResponseBody call() throws Exception {
      return getContent();
    }
  });
}
 
开发者ID:filestack,项目名称:filestack-java,代码行数:14,代码来源:Transform.java

示例14: fromLocationName

import io.reactivex.Single; //导入方法依赖的package包/类
public Single<List<Address>> fromLocationName(final Locale locale, @NonNull final String locationName, final int maxResults, final double lowerLeftLatitude, final double lowerLeftLongitude, final double upperRightLatitude, final double upperRightLongitude) {
    return Single.fromCallable(new Callable<List<Address>>() {
        @Override
        public List<Address> call() throws Exception {
            return Geocoding.this.getGeocoder(locale).getFromLocationName(locationName, maxResults, lowerLeftLatitude, lowerLeftLongitude, upperRightLatitude, upperRightLongitude);
        }
    });
}
 
开发者ID:TechIsFun,项目名称:RxJava2-weather-example,代码行数:9,代码来源:Geocoding.java

示例15: findChatById

import io.reactivex.Single; //导入方法依赖的package包/类
@Override
public Single<Optional<Chat>> findChatById(int accountId, int peerId) {
    return Single.fromCallable(() -> {
        String[] projection = {
                DialogsColumns.TITLE,
                DialogsColumns.PHOTO_200,
                DialogsColumns.PHOTO_100,
                DialogsColumns.PHOTO_50,
                DialogsColumns.ADMIN_ID
        };

        Uri uri = MessengerContentProvider.getDialogsContentUriFor(accountId);
        Cursor cursor = getContentResolver().query(uri, projection,
                DialogsColumns.FULL_ID + " = ?", new String[]{String.valueOf(peerId)}, null);

        Chat chat = null;
        if (cursor != null) {
            if (cursor.moveToNext()) {
                chat = new Chat(peerId);
                chat.setTitle(cursor.getString(cursor.getColumnIndex(DialogsColumns.TITLE)))
                        .setPhoto200(cursor.getString(cursor.getColumnIndex(DialogsColumns.PHOTO_200)))
                        .setPhoto100(cursor.getString(cursor.getColumnIndex(DialogsColumns.PHOTO_100)))
                        .setPhoto50(cursor.getString(cursor.getColumnIndex(DialogsColumns.PHOTO_50)))
                        .setAdminId(cursor.getInt(cursor.getColumnIndex(DialogsColumns.ADMIN_ID)));
            }

            cursor.close();
        }

        return Optional.wrap(chat);
    });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:33,代码来源:DialogsStore.java


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