本文整理汇总了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())));
});
}
示例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);
});
}
示例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;
});
}
示例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;
});
}
示例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);
});
}
示例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;
});
}
示例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;
});
}
示例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);
}
示例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();
});
}
示例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();
}
});
}
示例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);
});
}
示例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"));
}
示例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();
}
});
}
示例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);
}
});
}
示例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);
});
}