From 409fc83819dce654ea247d5cbf47a020f8bbcd7d Mon Sep 17 00:00:00 2001 From: huangyuhui Date: Tue, 26 Jan 2016 19:50:26 +0800 Subject: [PATCH] To make death I removed RxJava --- .../hellominecraft/launcher/Main.java | 4 +- .../core/assets/AssetsMojangLoader.java | 91 +- .../launcher/core/assets/IAssetsHandler.java | 4 +- .../core/assets/MinecraftAssetService.java | 5 +- .../download/MinecraftDownloadService.java | 16 +- .../launcher/core/launch/MinecraftLoader.java | 3 +- .../service/IMinecraftDownloadService.java | 4 +- .../utils/DefaultMinecraftService.java | 4 + .../utils/upgrade/AppDataUpgrader.java | 5 +- .../launcher/views/GameDownloadPanel.java | 11 +- .../launcher/views/GameSettingsPanel.java | 26 +- .../launcher/views/LauncherSettingsPanel.java | 9 +- .../launcher/views/modpack/ModpackWizard.java | 2 - .../hellominecraft/utils/CollectionUtils.java | 5 +- .../hellominecraft/utils/IUpdateChecker.java | 5 +- .../hellominecraft/utils/NetUtils.java | 11 - .../utils/OverridableSwingWorker.java | 65 + .../hellominecraft/utils/UpdateChecker.java | 63 +- .../utils/tasks/TaskObservable.java | 45 - HMCLAPI/src/main/java/rx/Notification.java | 156 - HMCLAPI/src/main/java/rx/Observable.java | 3662 ----------------- HMCLAPI/src/main/java/rx/Observer.java | 68 - HMCLAPI/src/main/java/rx/Scheduler.java | 69 - HMCLAPI/src/main/java/rx/Subscription.java | 38 - .../rx/concurrency/AbstractScheduler.java | 53 - .../concurrency/CurrentThreadScheduler.java | 72 - .../rx/concurrency/DiscardableAction.java | 58 - .../rx/concurrency/EventQueueScheduler.java | 51 - .../rx/concurrency/ExecutorScheduler.java | 106 - .../rx/concurrency/ImmediateScheduler.java | 47 - .../rx/concurrency/NewThreadScheduler.java | 50 - .../main/java/rx/concurrency/Schedulers.java | 162 - .../java/rx/concurrency/SleepingAction.java | 52 - .../rx/observables/GroupedObservable.java | 46 - .../main/java/rx/operators/OperationAll.java | 60 - .../rx/operators/OperationCombineLatest.java | 293 -- .../java/rx/operators/OperationConcat.java | 130 - .../java/rx/operators/OperationDefer.java | 30 - .../rx/operators/OperationDematerialize.java | 84 - .../java/rx/operators/OperationFilter.java | 69 - .../java/rx/operators/OperationFinally.java | 98 - .../main/java/rx/operators/OperationMap.java | 123 - .../rx/operators/OperationMaterialize.java | 85 - .../java/rx/operators/OperationMerge.java | 261 -- .../operators/OperationMergeDelayError.java | 337 -- .../rx/operators/OperationMostRecent.java | 106 - .../main/java/rx/operators/OperationNext.java | 143 - .../java/rx/operators/OperationObserveOn.java | 45 - ...OperationOnErrorResumeNextViaFunction.java | 108 - ...erationOnErrorResumeNextViaObservable.java | 101 - .../rx/operators/OperationOnErrorReturn.java | 125 - .../main/java/rx/operators/OperationScan.java | 136 - .../main/java/rx/operators/OperationSkip.java | 105 - .../rx/operators/OperationSubscribeOn.java | 62 - .../rx/operators/OperationSynchronize.java | 75 - .../main/java/rx/operators/OperationTake.java | 135 - .../java/rx/operators/OperationTakeLast.java | 84 - .../java/rx/operators/OperationTakeWhile.java | 144 - .../OperationToObservableFuture.java | 71 - .../OperationToObservableIterable.java | 39 - .../operators/OperationToObservableList.java | 79 - .../OperationToObservableSortedList.java | 131 - .../java/rx/operators/OperationWhere.java | 28 - .../main/java/rx/operators/OperationZip.java | 284 -- .../java/rx/operators/OperatorGroupBy.java | 117 - .../java/rx/operators/OperatorTakeUntil.java | 141 - .../java/rx/operators/OperatorToIterator.java | 82 - .../java/rx/operators/ScheduledObserver.java | 53 - .../java/rx/plugins/RxJavaErrorHandler.java | 45 - .../rx/plugins/RxJavaErrorHandlerDefault.java | 31 - .../RxJavaObservableExecutionHook.java | 107 - .../RxJavaObservableExecutionHookDefault.java | 32 - .../main/java/rx/plugins/RxJavaPlugins.java | 156 - .../src/main/java/rx/subjects/Subject.java | 57 - .../rx/subscriptions/BooleanSubscription.java | 28 - .../java/rx/subscriptions/Subscriptions.java | 45 - .../rx/util/AtomicObservableSubscription.java | 78 - .../src/main/java/rx/util/AtomicObserver.java | 101 - .../main/java/rx/util/CompositeException.java | 64 - HMCLAPI/src/main/java/rx/util/Exceptions.java | 31 - HMCLAPI/src/main/java/rx/util/Range.java | 75 - .../java/rx/util/SynchronizedObserver.java | 109 - .../main/java/rx/util/functions/Action0.java | 21 - .../main/java/rx/util/functions/Action1.java | 21 - .../main/java/rx/util/functions/Action2.java | 21 - .../main/java/rx/util/functions/Action3.java | 21 - .../main/java/rx/util/functions/Func0.java | 21 - .../main/java/rx/util/functions/Func1.java | 21 - .../main/java/rx/util/functions/Func2.java | 21 - .../main/java/rx/util/functions/Func3.java | 21 - .../main/java/rx/util/functions/Func4.java | 21 - .../main/java/rx/util/functions/Func5.java | 21 - .../main/java/rx/util/functions/Func6.java | 21 - .../main/java/rx/util/functions/Func7.java | 21 - .../main/java/rx/util/functions/Func8.java | 21 - .../main/java/rx/util/functions/Func9.java | 21 - .../main/java/rx/util/functions/FuncN.java | 21 - .../main/java/rx/util/functions/Function.java | 10 - .../functions/FunctionLanguageAdaptor.java | 40 - .../java/rx/util/functions/Functions.java | 503 --- .../hellominecraft/launcher/I18N.properties | 2 +- .../launcher/I18N_en.properties | 2 +- .../launcher/I18N_zh.properties | 6 +- .../launcher/I18N_zh_CN.properties | 2 +- .../servers/ServerPlugin.java | 4 +- .../mfcraft/CheckModsMinecraftProvider.java | 7 +- .../servers/mfcraft/MFCraftAuthenticator.java | 2 +- .../servers/mfcraft/Servers.java | 6 +- .../jackhuang/hellominecraft/svrmgr/Main.java | 3 +- 109 files changed, 197 insertions(+), 10696 deletions(-) create mode 100644 HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/OverridableSwingWorker.java delete mode 100755 HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/tasks/TaskObservable.java delete mode 100755 HMCLAPI/src/main/java/rx/Notification.java delete mode 100755 HMCLAPI/src/main/java/rx/Observable.java delete mode 100755 HMCLAPI/src/main/java/rx/Observer.java delete mode 100755 HMCLAPI/src/main/java/rx/Scheduler.java delete mode 100755 HMCLAPI/src/main/java/rx/Subscription.java delete mode 100755 HMCLAPI/src/main/java/rx/concurrency/AbstractScheduler.java delete mode 100755 HMCLAPI/src/main/java/rx/concurrency/CurrentThreadScheduler.java delete mode 100755 HMCLAPI/src/main/java/rx/concurrency/DiscardableAction.java delete mode 100755 HMCLAPI/src/main/java/rx/concurrency/EventQueueScheduler.java delete mode 100755 HMCLAPI/src/main/java/rx/concurrency/ExecutorScheduler.java delete mode 100755 HMCLAPI/src/main/java/rx/concurrency/ImmediateScheduler.java delete mode 100755 HMCLAPI/src/main/java/rx/concurrency/NewThreadScheduler.java delete mode 100755 HMCLAPI/src/main/java/rx/concurrency/Schedulers.java delete mode 100755 HMCLAPI/src/main/java/rx/concurrency/SleepingAction.java delete mode 100755 HMCLAPI/src/main/java/rx/observables/GroupedObservable.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationAll.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationCombineLatest.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationConcat.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationDefer.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationDematerialize.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationFilter.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationFinally.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationMap.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationMaterialize.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationMerge.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationMergeDelayError.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationMostRecent.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationNext.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationObserveOn.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationOnErrorResumeNextViaFunction.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationOnErrorResumeNextViaObservable.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationOnErrorReturn.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationScan.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationSkip.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationSubscribeOn.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationSynchronize.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationTake.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationTakeLast.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationTakeWhile.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationToObservableFuture.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationToObservableIterable.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationToObservableList.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationToObservableSortedList.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationWhere.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperationZip.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperatorGroupBy.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperatorTakeUntil.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/OperatorToIterator.java delete mode 100755 HMCLAPI/src/main/java/rx/operators/ScheduledObserver.java delete mode 100755 HMCLAPI/src/main/java/rx/plugins/RxJavaErrorHandler.java delete mode 100755 HMCLAPI/src/main/java/rx/plugins/RxJavaErrorHandlerDefault.java delete mode 100755 HMCLAPI/src/main/java/rx/plugins/RxJavaObservableExecutionHook.java delete mode 100755 HMCLAPI/src/main/java/rx/plugins/RxJavaObservableExecutionHookDefault.java delete mode 100755 HMCLAPI/src/main/java/rx/plugins/RxJavaPlugins.java delete mode 100755 HMCLAPI/src/main/java/rx/subjects/Subject.java delete mode 100755 HMCLAPI/src/main/java/rx/subscriptions/BooleanSubscription.java delete mode 100755 HMCLAPI/src/main/java/rx/subscriptions/Subscriptions.java delete mode 100755 HMCLAPI/src/main/java/rx/util/AtomicObservableSubscription.java delete mode 100755 HMCLAPI/src/main/java/rx/util/AtomicObserver.java delete mode 100755 HMCLAPI/src/main/java/rx/util/CompositeException.java delete mode 100755 HMCLAPI/src/main/java/rx/util/Exceptions.java delete mode 100755 HMCLAPI/src/main/java/rx/util/Range.java delete mode 100755 HMCLAPI/src/main/java/rx/util/SynchronizedObserver.java delete mode 100755 HMCLAPI/src/main/java/rx/util/functions/Action0.java delete mode 100755 HMCLAPI/src/main/java/rx/util/functions/Action1.java delete mode 100755 HMCLAPI/src/main/java/rx/util/functions/Action2.java delete mode 100755 HMCLAPI/src/main/java/rx/util/functions/Action3.java delete mode 100755 HMCLAPI/src/main/java/rx/util/functions/Func0.java delete mode 100755 HMCLAPI/src/main/java/rx/util/functions/Func1.java delete mode 100755 HMCLAPI/src/main/java/rx/util/functions/Func2.java delete mode 100755 HMCLAPI/src/main/java/rx/util/functions/Func3.java delete mode 100755 HMCLAPI/src/main/java/rx/util/functions/Func4.java delete mode 100755 HMCLAPI/src/main/java/rx/util/functions/Func5.java delete mode 100755 HMCLAPI/src/main/java/rx/util/functions/Func6.java delete mode 100755 HMCLAPI/src/main/java/rx/util/functions/Func7.java delete mode 100755 HMCLAPI/src/main/java/rx/util/functions/Func8.java delete mode 100755 HMCLAPI/src/main/java/rx/util/functions/Func9.java delete mode 100755 HMCLAPI/src/main/java/rx/util/functions/FuncN.java delete mode 100755 HMCLAPI/src/main/java/rx/util/functions/Function.java delete mode 100755 HMCLAPI/src/main/java/rx/util/functions/FunctionLanguageAdaptor.java delete mode 100755 HMCLAPI/src/main/java/rx/util/functions/Functions.java diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/Main.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/Main.java index 80a4490f9..5b4dbee3e 100755 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/Main.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/Main.java @@ -47,7 +47,6 @@ import org.jackhuang.hellominecraft.lookandfeel.HelloMinecraftLookAndFeel; import org.jackhuang.hellominecraft.utils.MathUtils; import org.jackhuang.hellominecraft.utils.StrUtils; import org.jackhuang.hellominecraft.utils.VersionNumber; -import rx.concurrency.Schedulers; /** * @@ -146,8 +145,7 @@ public final class Main implements Runnable { } Settings.UPDATE_CHECKER.outdated.register(IUpgrader.NOW_UPGRADER); - Settings.UPDATE_CHECKER.process(false).subscribeOn(Schedulers.newThread()).subscribe(t - -> Main.invokeUpdate()); + Settings.UPDATE_CHECKER.process(false).reg(t -> Main.invokeUpdate()).execute(); if (StrUtils.isNotBlank(Settings.getInstance().getProxyHost()) && StrUtils.isNotBlank(Settings.getInstance().getProxyPort()) && MathUtils.canParseInt(Settings.getInstance().getProxyPort())) { HMCLog.log("Initializing customized proxy"); diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/assets/AssetsMojangLoader.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/assets/AssetsMojangLoader.java index c7aa92f3b..a016fe262 100755 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/assets/AssetsMojangLoader.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/assets/AssetsMojangLoader.java @@ -18,7 +18,6 @@ package org.jackhuang.hellominecraft.launcher.core.assets; import java.io.File; -import java.io.IOException; import java.util.ArrayList; import java.util.Map; import org.jackhuang.hellominecraft.utils.C; @@ -30,9 +29,8 @@ import org.jackhuang.hellominecraft.utils.system.IOUtils; import org.jackhuang.hellominecraft.utils.StrUtils; import org.jackhuang.hellominecraft.launcher.core.download.IDownloadProvider; import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion; +import org.jackhuang.hellominecraft.utils.OverridableSwingWorker; import org.jackhuang.hellominecraft.utils.VersionNumber; -import rx.Observable; -import rx.Observer; /** * @@ -45,61 +43,42 @@ public class AssetsMojangLoader extends IAssetsHandler { } @Override - public Observable getList(MinecraftVersion mv, IMinecraftAssetService mp) { - return Observable.createWithEmptySubscription((Observer t1) -> { - if (mv == null) { - t1.onError(null); - return; - } - String assetsId = mv.assets == null ? "legacy" : mv.assets; - File assets = mp.getAssets(); - HMCLog.log("Get index: " + assetsId); - File f = IOUtils.tryGetCanonicalFile(new File(assets, "indexes/" + assetsId + ".json")); - if (!f.exists() && !mp.downloadMinecraftAssetsIndex(assetsId)) { - t1.onError(null); - return; - } + public OverridableSwingWorker getList(MinecraftVersion mv, IMinecraftAssetService mp) { + return new OverridableSwingWorker() { + @Override + protected void work() throws Exception { + if (mv == null) + throw new IllegalArgumentException("AssetsMojangLoader: null argument: MinecraftVersion"); + String assetsId = mv.assets == null ? "legacy" : mv.assets; + File assets = mp.getAssets(); + HMCLog.log("Gathering asset index: " + assetsId); + File f = IOUtils.tryGetCanonicalFile(new File(assets, "indexes/" + assetsId + ".json")); + if (!f.exists() && !mp.downloadMinecraftAssetsIndex(assetsId)) + throw new IllegalStateException("Failed to get index json"); - String result; - try { - result = FileUtils.readFileToString(f); - } catch (IOException ex) { - HMCLog.warn("Failed to read index json: " + f, ex); - t1.onError(null); - return; - } - if (StrUtils.isBlank(result)) { - HMCLog.err("Index json is empty, please redownload it!"); - t1.onError(null); - return; - } - AssetsIndex o; - try { - o = C.gson.fromJson(result, AssetsIndex.class); - } catch (Exception e) { - HMCLog.err("Failed to parse index json, please redownload it!", e); - t1.onError(null); - return; - } - assetsDownloadURLs = new ArrayList<>(); - assetsLocalNames = new ArrayList<>(); - ArrayList al = new ArrayList<>(); - contents = new ArrayList<>(); - if (o != null && o.getFileMap() != null) - for (Map.Entry e : o.getFileMap().entrySet()) { - Contents c = new Contents(); - c.eTag = e.getValue().getHash(); - c.key = c.eTag.substring(0, 2) + "/" + e.getValue().getHash(); - c.size = e.getValue().getSize(); - contents.add(c); - assetsDownloadURLs.add(c.key); - assetsLocalNames.add(new File(assets, "objects" + File.separator + c.key.replace("/", File.separator))); - al.add(e.getKey()); - } + String result = FileUtils.readFileToString(f); + if (StrUtils.isBlank(result)) + throw new IllegalStateException("Index json is empty, please redownload it!"); + AssetsIndex o = C.gson.fromJson(result, AssetsIndex.class); + assetsDownloadURLs = new ArrayList<>(); + assetsLocalNames = new ArrayList<>(); + ArrayList al = new ArrayList<>(); + contents = new ArrayList<>(); + if (o != null && o.getFileMap() != null) + for (Map.Entry e : o.getFileMap().entrySet()) { + Contents c = new Contents(); + c.eTag = e.getValue().getHash(); + c.key = c.eTag.substring(0, 2) + "/" + e.getValue().getHash(); + c.size = e.getValue().getSize(); + contents.add(c); + assetsDownloadURLs.add(c.key); + assetsLocalNames.add(new File(assets, "objects" + File.separator + c.key.replace("/", File.separator))); + al.add(e.getKey()); + } - t1.onNext(al.toArray(new String[1])); - t1.onCompleted(); - }); + publish(al.toArray(new String[1])); + } + }; } @Override diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/assets/IAssetsHandler.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/assets/IAssetsHandler.java index 94be9621e..6333d8c4a 100755 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/assets/IAssetsHandler.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/assets/IAssetsHandler.java @@ -33,7 +33,7 @@ import org.jackhuang.hellominecraft.utils.tasks.download.FileDownloadTask; import org.jackhuang.hellominecraft.utils.code.DigestUtils; import org.jackhuang.hellominecraft.utils.system.IOUtils; import org.jackhuang.hellominecraft.utils.NetUtils; -import rx.Observable; +import org.jackhuang.hellominecraft.utils.OverridableSwingWorker; /** * Assets @@ -73,7 +73,7 @@ public abstract class IAssetsHandler { * @param mp Asset Service * @param x finished event */ - public abstract Observable getList(MinecraftVersion mv, IMinecraftAssetService mp); + public abstract OverridableSwingWorker getList(MinecraftVersion mv, IMinecraftAssetService mp); /** * Will be invoked when the user invoked "Download all assets". diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/assets/MinecraftAssetService.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/assets/MinecraftAssetService.java index a06213ae9..66c9dc6b7 100755 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/assets/MinecraftAssetService.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/assets/MinecraftAssetService.java @@ -29,7 +29,6 @@ import org.jackhuang.hellominecraft.utils.tasks.TaskWindow; import org.jackhuang.hellominecraft.utils.tasks.download.FileDownloadTask; import org.jackhuang.hellominecraft.utils.system.FileUtils; import org.jackhuang.hellominecraft.utils.system.IOUtils; -import rx.concurrency.Schedulers; /** * @@ -49,9 +48,7 @@ public class MinecraftAssetService extends IMinecraftAssetService { public void executeTask() throws Throwable { IAssetsHandler type = IAssetsHandler.ASSETS_HANDLER; type.getList(service.version().getVersionById(mcVersion), service.asset()) - .subscribeOn(Schedulers.newThread()) - .observeOn(Schedulers.eventQueue()) - .subscribe((t) -> TaskWindow.getInstance().addTask(type.getDownloadTask(service.getDownloadType().getProvider())).start()); + .reg((t) -> TaskWindow.getInstance().addTask(type.getDownloadTask(service.getDownloadType().getProvider())).start()).execute(); } @Override diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/download/MinecraftDownloadService.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/download/MinecraftDownloadService.java index 6c121f4bc..7ab25d1df 100755 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/download/MinecraftDownloadService.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/download/MinecraftDownloadService.java @@ -31,12 +31,12 @@ import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion; import org.jackhuang.hellominecraft.utils.tasks.TaskWindow; import org.jackhuang.hellominecraft.utils.tasks.download.FileDownloadTask; import org.jackhuang.hellominecraft.utils.NetUtils; +import org.jackhuang.hellominecraft.utils.OverridableSwingWorker; import org.jackhuang.hellominecraft.utils.system.FileUtils; import org.jackhuang.hellominecraft.utils.system.IOUtils; import org.jackhuang.hellominecraft.utils.tasks.Task; import org.jackhuang.hellominecraft.utils.version.MinecraftRemoteVersion; import org.jackhuang.hellominecraft.utils.version.MinecraftRemoteVersions; -import rx.Observable; /** * @@ -151,10 +151,14 @@ public class MinecraftDownloadService extends IMinecraftDownloadService { } @Override - public Observable getRemoteVersions() { - return NetUtils.getRx(service.getDownloadType().getProvider().getVersionsListDownloadURL()) - .map(r -> C.gson.fromJson(r, MinecraftRemoteVersions.class)) - .filter(r -> r != null && r.versions != null) - .flatMap(r -> Observable.from(r.versions)); + public OverridableSwingWorker getRemoteVersions() { + return new OverridableSwingWorker() { + @Override + protected void work() throws Exception { + MinecraftRemoteVersions r = C.gson.fromJson(NetUtils.get(service.getDownloadType().getProvider().getVersionsListDownloadURL()), MinecraftRemoteVersions.class); + if (r != null && r.versions != null) + publish(r.versions.toArray(new MinecraftRemoteVersion[0])); + } + }; } } diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/launch/MinecraftLoader.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/launch/MinecraftLoader.java index abfae8b3c..7dfec6efb 100755 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/launch/MinecraftLoader.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/launch/MinecraftLoader.java @@ -76,8 +76,7 @@ public class MinecraftLoader extends AbstractMinecraftLoader { if (!checkAssetsExist()) if (MessageBox.Show(C.i18n("assets.no_assets"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) { - IAssetsHandler.ASSETS_HANDLER.getList(version, service.asset()).subscribe(a -> { - }); + IAssetsHandler.ASSETS_HANDLER.getList(version, service.asset()).execute(); TaskWindow.getInstance().addTask(IAssetsHandler.ASSETS_HANDLER.getDownloadTask(service.getDownloadType().getProvider())).start(); } diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/service/IMinecraftDownloadService.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/service/IMinecraftDownloadService.java index 691890943..80c5b3fc4 100755 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/service/IMinecraftDownloadService.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/core/service/IMinecraftDownloadService.java @@ -22,9 +22,9 @@ import java.util.List; import org.jackhuang.hellominecraft.launcher.core.GameException; import org.jackhuang.hellominecraft.launcher.core.download.DownloadLibraryJob; import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion; +import org.jackhuang.hellominecraft.utils.OverridableSwingWorker; import org.jackhuang.hellominecraft.utils.tasks.Task; import org.jackhuang.hellominecraft.utils.version.MinecraftRemoteVersion; -import rx.Observable; /** * @@ -51,6 +51,6 @@ public abstract class IMinecraftDownloadService extends IMinecraftBasicService { */ public abstract List getDownloadLibraries(MinecraftVersion mv) throws GameException; - public abstract Observable getRemoteVersions(); + public abstract OverridableSwingWorker getRemoteVersions(); } diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/utils/DefaultMinecraftService.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/utils/DefaultMinecraftService.java index e27cc7152..581a14859 100644 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/utils/DefaultMinecraftService.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/utils/DefaultMinecraftService.java @@ -100,4 +100,8 @@ public class DefaultMinecraftService extends IMinecraftService { return new MinecraftLoader(options, this, p); } + public Profile getProfile() { + return p; + } + } diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/utils/upgrade/AppDataUpgrader.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/utils/upgrade/AppDataUpgrader.java index 6ebf647cf..eab21d939 100755 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/utils/upgrade/AppDataUpgrader.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/utils/upgrade/AppDataUpgrader.java @@ -48,7 +48,6 @@ import org.jackhuang.hellominecraft.utils.VersionNumber; import org.jackhuang.hellominecraft.utils.system.FileUtils; import org.jackhuang.hellominecraft.utils.system.IOUtils; import org.jackhuang.hellominecraft.utils.system.OS; -import rx.concurrency.Schedulers; /** * @@ -91,7 +90,7 @@ public class AppDataUpgrader extends IUpgrader { @Override public boolean call(Object sender, VersionNumber number) { - ((UpdateChecker) sender).requestDownloadLink().subscribeOn(Schedulers.newThread()).observeOn(Schedulers.eventQueue()).subscribe(map -> { + ((UpdateChecker) sender).requestDownloadLink().reg(map -> { if (map != null && map.containsKey("pack")) try { if (TaskWindow.getInstance().addTask(new AppDataUpgraderTask(map.get("pack"), number.version)).start()) { @@ -120,7 +119,7 @@ public class AppDataUpgrader extends IUpgrader { MessageBox.Show(C.i18n("update.no_browser")); } } - }); + }).execute(); return true; } diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/GameDownloadPanel.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/GameDownloadPanel.java index fafa1808c..3f9f0d4cb 100755 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/GameDownloadPanel.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/GameDownloadPanel.java @@ -23,7 +23,6 @@ import org.jackhuang.hellominecraft.utils.logging.HMCLog; import org.jackhuang.hellominecraft.utils.MessageBox; import org.jackhuang.hellominecraft.utils.StrUtils; import org.jackhuang.hellominecraft.utils.views.SwingUtils; -import rx.concurrency.Schedulers; /** * @@ -108,13 +107,13 @@ public class GameDownloadPanel extends AnimatedPanel implements Selectable { public void refreshDownloads() { DefaultTableModel model = SwingUtils.clearDefaultTable(lstDownloads); gsp.getProfile().service().download().getRemoteVersions() - .observeOn(Schedulers.eventQueue()).subscribeOn(Schedulers.newThread()) - .subscribe((ver) -> model.addRow(new Object[] { ver.id, ver.time, - StrUtils.equalsOne(ver.type, "old_beta", "old_alpha", "release", "snapshot") ? C.i18n("versions." + ver.type) : ver.type }), - (e) -> { + .reg((ver) -> model.addRow(new Object[] { ver.id, ver.time, + StrUtils.equalsOne(ver.type, "old_beta", "old_alpha", "release", "snapshot") ? C.i18n("versions." + ver.type) : ver.type })) + .regDone(lstDownloads::updateUI).execute(); + /*(e) -> { MessageBox.Show("Failed to refresh download: " + e.getLocalizedMessage()); HMCLog.err("Failed to refresh download.", e); - }, lstDownloads::updateUI); + }, );*/ } void downloadMinecraft() { diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/GameSettingsPanel.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/GameSettingsPanel.java index 7d3f21272..90b9a356a 100755 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/GameSettingsPanel.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/GameSettingsPanel.java @@ -32,9 +32,7 @@ import java.awt.event.ItemEvent; import java.awt.event.KeyEvent; import java.io.File; import java.io.IOException; -import java.util.Arrays; import java.util.List; -import java.util.Map; import javax.swing.JFileChooser; import javax.swing.JMenuItem; import javax.swing.JOptionPane; @@ -46,7 +44,6 @@ import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.table.DefaultTableModel; import org.jackhuang.hellominecraft.utils.C; import org.jackhuang.hellominecraft.utils.logging.HMCLog; -import org.jackhuang.hellominecraft.launcher.core.GameException; import org.jackhuang.hellominecraft.launcher.core.LauncherVisibility; import org.jackhuang.hellominecraft.launcher.settings.Profile; import org.jackhuang.hellominecraft.launcher.settings.Settings; @@ -56,13 +53,12 @@ import org.jackhuang.hellominecraft.launcher.core.installers.InstallerType; import org.jackhuang.hellominecraft.launcher.core.mod.ModpackManager; import org.jackhuang.hellominecraft.launcher.core.version.GameDirType; import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion; -import org.jackhuang.hellominecraft.launcher.views.modpack.ModpackInitializationPanel; import org.jackhuang.hellominecraft.launcher.views.modpack.ModpackWizard; -import org.jackhuang.hellominecraft.utils.tasks.TaskRunnable; import org.jackhuang.hellominecraft.utils.tasks.TaskWindow; import org.jackhuang.hellominecraft.utils.Event; import org.jackhuang.hellominecraft.utils.system.IOUtils; import org.jackhuang.hellominecraft.utils.MessageBox; +import org.jackhuang.hellominecraft.utils.OverridableSwingWorker; import org.jackhuang.hellominecraft.utils.version.MinecraftVersionRequest; import org.jackhuang.hellominecraft.utils.system.OS; import org.jackhuang.hellominecraft.utils.StrUtils; @@ -70,8 +66,6 @@ import org.jackhuang.hellominecraft.utils.system.FileUtils; import org.jackhuang.hellominecraft.utils.views.SwingUtils; import org.jackhuang.hellominecraft.utils.system.Java; import org.jackhuang.hellominecraft.utils.views.wizard.api.WizardDisplayer; -import rx.Observable; -import rx.concurrency.Schedulers; /** * @@ -1300,14 +1294,16 @@ public final class GameSettingsPanel extends AnimatedPanel implements DropTarget return; reloadingMods = true; DefaultTableModel model = SwingUtils.clearDefaultTable(lstExternalMods); - Observable.>createWithEmptySubscription( - t -> t.onNext(getProfile().service().mod().recacheMods(getProfile().getSelectedVersion()))) - .subscribeOn(Schedulers.newThread()).observeOn(Schedulers.eventQueue()) - .subscribe(t -> { - for (ModInfo x : t) - model.addRow(new Object[] { x.isActive(), x, x.version }); - reloadingMods = false; - }); + new OverridableSwingWorker>() { + @Override + protected void work() throws Exception { + publish(getProfile().service().mod().recacheMods(getProfile().getSelectedVersion())); + } + }.reg(t -> { + for (ModInfo x : t) + model.addRow(new Object[] { x.isActive(), x, x.version }); + reloadingMods = false; + }).execute(); } // diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/LauncherSettingsPanel.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/LauncherSettingsPanel.java index 7b8ee68d6..1576e8068 100755 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/LauncherSettingsPanel.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/LauncherSettingsPanel.java @@ -29,7 +29,6 @@ import org.jackhuang.hellominecraft.launcher.core.download.DownloadType; import org.jackhuang.hellominecraft.utils.system.IOUtils; import org.jackhuang.hellominecraft.utils.MessageBox; import org.jackhuang.hellominecraft.utils.views.SwingUtils; -import rx.Observable; /** * @@ -43,8 +42,10 @@ public class LauncherSettingsPanel extends AnimatedPanel { public LauncherSettingsPanel() { initComponents(); - Observable.from(DownloadType.values()).map(t -> t.getName()).toList() - .subscribe(t -> cboDownloadSource.setModel(new DefaultComboBoxModel(t.toArray(new String[0])))); + DefaultComboBoxModel d = new DefaultComboBoxModel(); + for (DownloadType type : DownloadType.values()) + d.addElement(type.getName()); + cboDownloadSource.setModel(d); txtBackgroundPath.setText(Settings.getInstance().getBgpath()); txtProxyHost.setText(Settings.getInstance().getProxyHost()); @@ -362,7 +363,7 @@ public class LauncherSettingsPanel extends AnimatedPanel { private void chkDecoratedFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_chkDecoratedFocusLost Settings.getInstance().setDecorated(chkDecorated.isSelected()); }//GEN-LAST:event_chkDecoratedFocusLost - + private void jLabel9MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel9MouseClicked SwingUtils.openLink("http://blog.163.com/huanghongxun2008@126/blog/static/7738046920160323812771/"); }//GEN-LAST:event_jLabel9MouseClicked diff --git a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/modpack/ModpackWizard.java b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/modpack/ModpackWizard.java index 52dbe4932..efde0b662 100644 --- a/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/modpack/ModpackWizard.java +++ b/HMCL/src/main/java/org/jackhuang/hellominecraft/launcher/views/modpack/ModpackWizard.java @@ -20,7 +20,6 @@ package org.jackhuang.hellominecraft.launcher.views.modpack; import java.io.File; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Enumeration; import java.util.Iterator; import java.util.List; @@ -31,7 +30,6 @@ import org.jackhuang.hellominecraft.launcher.core.mod.ModpackManager; import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService; import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersion; import org.jackhuang.hellominecraft.utils.C; -import org.jackhuang.hellominecraft.utils.MessageBox; import org.jackhuang.hellominecraft.utils.logging.HMCLog; import org.jackhuang.hellominecraft.utils.views.checktree.CheckBoxTreeNode; import org.jackhuang.hellominecraft.utils.views.wizard.spi.DeferredWizardResult; diff --git a/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/CollectionUtils.java b/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/CollectionUtils.java index bb183a7a5..6a9440cbe 100755 --- a/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/CollectionUtils.java +++ b/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/CollectionUtils.java @@ -21,7 +21,6 @@ import org.jackhuang.hellominecraft.utils.functions.Predicate; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; -import rx.Observable; /** * @@ -31,7 +30,9 @@ public final class CollectionUtils { public static ArrayList map(Collection coll, Predicate p) { ArrayList newColl = new ArrayList<>(); - Observable.from(coll).filter(t -> p.apply(t)).subscribe(t -> newColl.add(t)); + for (T t : coll) + if (p.apply(t)) + newColl.add(t); return newColl; } diff --git a/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/IUpdateChecker.java b/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/IUpdateChecker.java index 750abe432..110b7c653 100755 --- a/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/IUpdateChecker.java +++ b/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/IUpdateChecker.java @@ -18,7 +18,6 @@ package org.jackhuang.hellominecraft.utils; import java.util.Map; -import rx.Observable; /** * @@ -50,13 +49,13 @@ public interface IUpdateChecker { * * @return the process observable. */ - Observable process(boolean showMessage); + OverridableSwingWorker process(boolean showMessage); /** * Get the download links. * * @return a JSON, which contains the server response. */ - Observable> requestDownloadLink(); + OverridableSwingWorker> requestDownloadLink(); } diff --git a/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/NetUtils.java b/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/NetUtils.java index ce800bf0c..f0c562408 100755 --- a/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/NetUtils.java +++ b/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/NetUtils.java @@ -29,7 +29,6 @@ import java.net.Proxy; import java.net.URL; import java.util.Map; import org.jackhuang.hellominecraft.utils.system.IOUtils; -import rx.Observable; /** * @@ -158,14 +157,4 @@ public final class NetUtils { throw new IllegalArgumentException("Could not concatenate given URL with GET arguments!", ex); } } - - public static Observable getRx(String url) { - return Observable.createWithEmptySubscription(t1 -> { - try { - t1.onNext(get(url)); - } catch (Exception e) { - t1.onError(e); - } - }); - } } diff --git a/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/OverridableSwingWorker.java b/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/OverridableSwingWorker.java new file mode 100644 index 000000000..d50075ea6 --- /dev/null +++ b/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/OverridableSwingWorker.java @@ -0,0 +1,65 @@ +/* + * Hello Minecraft! Launcher. + * Copyright (C) 2013 huangyuhui + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see {http://www.gnu.org/licenses/}. + */ +package org.jackhuang.hellominecraft.utils; + +import java.util.ArrayList; +import java.util.List; +import javax.swing.SwingWorker; +import org.jackhuang.hellominecraft.utils.functions.Consumer; + +/** + * + * @author huangyuhui + */ +public abstract class OverridableSwingWorker extends SwingWorker { + + List> processListeners = new ArrayList<>(); + List doneListeners = new ArrayList<>(); + + protected abstract void work() throws Exception; + + @Override + protected void done() { + for (Runnable c : doneListeners) + c.run(); + } + + @Override + protected Void doInBackground() throws Exception { + work(); + return null; + } + + public OverridableSwingWorker reg(Consumer c) { + processListeners.add(c); + return this; + } + + public OverridableSwingWorker regDone(Runnable c) { + doneListeners.add(c); + return this; + } + + @Override + protected void process(List chunks) { + for (T t : chunks) + for (Consumer c : processListeners) + c.accept(t); + } + +} diff --git a/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/UpdateChecker.java b/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/UpdateChecker.java index b4db4315e..143542033 100755 --- a/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/UpdateChecker.java +++ b/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/UpdateChecker.java @@ -19,7 +19,6 @@ package org.jackhuang.hellominecraft.utils; import org.jackhuang.hellominecraft.utils.logging.HMCLog; import java.util.Map; -import rx.Observable; /** * @@ -41,27 +40,26 @@ public final class UpdateChecker implements IUpdateChecker { VersionNumber value; @Override - public Observable process(boolean showMessage) { - return Observable.createWithEmptySubscription(t -> { - if (value == null) { - try { - versionString = NetUtils.get("http://huangyuhui.duapp.com/info.php?type=" + type); - } catch (Exception e) { - HMCLog.warn("Failed to get update url.", e); - return; - } - value = VersionNumber.check(versionString); - } + public OverridableSwingWorker process(boolean showMessage) { + return new OverridableSwingWorker() { + @Override + protected void work() throws Exception { - if (value == null) { - HMCLog.warn("Failed to check update..."); - if (showMessage) - MessageBox.Show(C.i18n("update.failed")); - } else if (VersionNumber.isOlder(base, value)) - OUT_DATED = true; - if (OUT_DATED) - t.onNext(value); - }); + if (value == null) { + versionString = NetUtils.get("http://huangyuhui.duapp.com/info.php?type=" + type); + value = VersionNumber.check(versionString); + } + + if (value == null) { + HMCLog.warn("Failed to check update..."); + if (showMessage) + MessageBox.Show(C.i18n("update.failed")); + } else if (VersionNumber.isOlder(base, value)) + OUT_DATED = true; + if (OUT_DATED) + publish(value); + } + }; } @Override @@ -70,16 +68,19 @@ public final class UpdateChecker implements IUpdateChecker { } @Override - public synchronized Observable> requestDownloadLink() { - return Observable.createWithEmptySubscription(t -> { - if (download_link == null) - try { - download_link = C.gson.fromJson(NetUtils.get("http://huangyuhui.duapp.com/update_link.php?type=" + type), Map.class); - } catch (Exception e) { - HMCLog.warn("Failed to get update link.", e); - } - t.onNext(download_link); - }); + public synchronized OverridableSwingWorker> requestDownloadLink() { + return new OverridableSwingWorker() { + @Override + protected void work() throws Exception { + if (download_link == null) + try { + download_link = C.gson.fromJson(NetUtils.get("http://huangyuhui.duapp.com/update_link.php?type=" + type), Map.class); + } catch (Exception e) { + HMCLog.warn("Failed to get update link.", e); + } + publish(download_link); + } + }; } public final EventHandler outdated = new EventHandler<>(this); diff --git a/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/tasks/TaskObservable.java b/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/tasks/TaskObservable.java deleted file mode 100755 index 0cdc8ee7e..000000000 --- a/HMCLAPI/src/main/java/org/jackhuang/hellominecraft/utils/tasks/TaskObservable.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Hello Minecraft! Launcher. - * Copyright (C) 2013 huangyuhui - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see {http://www.gnu.org/licenses/}. - */ -package org.jackhuang.hellominecraft.utils.tasks; - -import rx.Observable; - -/** - * - * @author huangyuhui - */ -public class TaskObservable extends TaskInfo { - - private final Observable r; - - public TaskObservable(String info, Observable r) { - super(info); - this.r = r; - } - - public TaskObservable(Observable r) { - this("TaskObservable", r); - } - - @Override - public void executeTask() { - r.subscribe(t -> { - }); - } - -} diff --git a/HMCLAPI/src/main/java/rx/Notification.java b/HMCLAPI/src/main/java/rx/Notification.java deleted file mode 100755 index 73c9a28c6..000000000 --- a/HMCLAPI/src/main/java/rx/Notification.java +++ /dev/null @@ -1,156 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx; - -/** - * An object representing a notification sent to an {@link Observable}. - * - * For the Microsoft Rx equivalent see: - * http://msdn.microsoft.com/en-us/library/hh229462(v=vs.103).aspx - */ -public class Notification { - - private final Kind kind; - private final Exception exception; - private final T value; - - /** - * A constructor used to represent an onNext notification. - * - * @param value The data passed to the onNext method. - */ - public Notification(T value) { - this.value = value; - this.exception = null; - this.kind = Kind.OnNext; - } - - /** - * A constructor used to represent an onError notification. - * - * @param exception The exception passed to the onError notification. - */ - public Notification(Exception exception) { - this.exception = exception; - this.value = null; - this.kind = Kind.OnError; - } - - /** - * A constructor used to represent an onCompleted notification. - */ - public Notification() { - this.exception = null; - this.value = null; - this.kind = Kind.OnCompleted; - } - - /** - * Retrieves the exception associated with an onError notification. - * - * @return The exception associated with an onError notification. - */ - public Exception getException() { - return exception; - } - - /** - * Retrieves the data associated with an onNext notification. - * - * @return The data associated with an onNext notification. - */ - public T getValue() { - return value; - } - - /** - * Retrieves a value indicating whether this notification has a value. - * - * @return a value indicating whether this notification has a value. - */ - public boolean hasValue() { - return isOnNext() && value != null; - } - - /** - * Retrieves a value indicating whether this notification has an exception. - * - * @return a value indicating whether this notification has an exception. - */ - public boolean hasException() { - return isOnError() && exception != null; - } - - /** - * The kind of notification: OnNext, OnError, OnCompleted - * - * @return - */ - public Kind getKind() { - return kind; - } - - public boolean isOnError() { - return getKind() == Kind.OnError; - } - - public boolean isOnCompleted() { - return getKind() == Kind.OnCompleted; - } - - public boolean isOnNext() { - return getKind() == Kind.OnNext; - } - - public static enum Kind { - OnNext, OnError, OnCompleted - } - - @Override - public String toString() { - StringBuilder str = new StringBuilder("[").append(super.toString()).append(" ").append(getKind()); - if (hasValue()) - str.append(" ").append(getValue()); - if (hasException()) - str.append(" ").append(getException().getMessage()); - str.append("]"); - return str.toString(); - } - - @Override - public int hashCode() { - int hash = getKind().hashCode(); - if (hasValue()) - hash = hash * 31 + getValue().hashCode(); - if (hasException()) - hash = hash * 31 + getException().hashCode(); - return hash; - } - - @Override - public boolean equals(Object obj) { - if (obj == null) - return false; - if (this == obj) - return true; - if (obj.getClass() != getClass()) - return false; - Notification notification = (Notification) obj; - if (notification.getKind() != getKind() || hasValue() && !getValue().equals(notification.getValue())) - return false; - return !(hasException() && !getException().equals(notification.getException())); - } -} diff --git a/HMCLAPI/src/main/java/rx/Observable.java b/HMCLAPI/src/main/java/rx/Observable.java deleted file mode 100755 index 56ae09f37..000000000 --- a/HMCLAPI/src/main/java/rx/Observable.java +++ /dev/null @@ -1,3662 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package rx; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; - -import rx.observables.GroupedObservable; -import rx.operators.OperationAll; -import rx.operators.OperationConcat; -import rx.operators.OperationDefer; -import rx.operators.OperationDematerialize; -import rx.operators.OperationFilter; -import rx.operators.OperationFinally; -import rx.operators.OperationMap; -import rx.operators.OperationMaterialize; -import rx.operators.OperationMerge; -import rx.operators.OperationMergeDelayError; -import rx.operators.OperationMostRecent; -import rx.operators.OperationNext; -import rx.operators.OperationObserveOn; -import rx.operators.OperationOnErrorResumeNextViaFunction; -import rx.operators.OperationOnErrorResumeNextViaObservable; -import rx.operators.OperationOnErrorReturn; -import rx.operators.OperationScan; -import rx.operators.OperationSkip; -import rx.operators.OperationSubscribeOn; -import rx.operators.OperationSynchronize; -import rx.operators.OperationTake; -import rx.operators.OperationTakeLast; -import rx.operators.OperationTakeWhile; -import rx.operators.OperationToObservableFuture; -import rx.operators.OperationToObservableIterable; -import rx.operators.OperationToObservableList; -import rx.operators.OperationToObservableSortedList; -import rx.operators.OperationWhere; -import rx.operators.OperationZip; -import rx.operators.OperatorGroupBy; -import rx.operators.OperatorTakeUntil; -import rx.operators.OperatorToIterator; -import rx.plugins.RxJavaErrorHandler; -import rx.plugins.RxJavaObservableExecutionHook; -import rx.plugins.RxJavaPlugins; -import rx.subscriptions.Subscriptions; -import rx.util.AtomicObservableSubscription; -import rx.util.AtomicObserver; -import rx.util.Range; -import rx.util.functions.Action0; -import rx.util.functions.Action1; -import rx.util.functions.Func0; -import rx.util.functions.Func1; -import rx.util.functions.Func2; -import rx.util.functions.Func3; -import rx.util.functions.Func4; -import rx.util.functions.FuncN; -import rx.util.functions.Function; -import rx.util.functions.FunctionLanguageAdaptor; -import rx.util.functions.Functions; - -/** - * The Observable interface that implements the Reactive Pattern. - *

- * It provides overloaded methods for subscribing as well as delegate methods to - * the various operators. - *

- * The documentation for this interface makes use of marble diagrams. The - * following legend explains these diagrams: - *

- * - *

- * For more information see the - * RxJava Wiki - * - * @param - */ -public class Observable { - - private final static RxJavaObservableExecutionHook HOOK = RxJavaPlugins.getInstance().getObservableExecutionHook(); - - private final Func1, Subscription> onSubscribe; - - protected Observable() { - this(null); - } - - /** - * Construct an Observable with Function to execute when subscribed to. - *

- * NOTE: Generally you're better off using {@link #create(Func1)} to create - * an Observable instead of using inheritance. - * - * @param onSubscribe {@link Func1} to be executed when - * {@link #subscribe(Observer)} is called. - */ - protected Observable(Func1, Subscription> onSubscribe) { - this.onSubscribe = onSubscribe; - } - - /** - * an {@link Observer} must call an Observable's subscribe - * method in order to register itself to receive push-based notifications - * from the Observable. A typical implementation of the - * subscribe method does the following: - *

- * It stores a reference to the Observer in a collection object, such as a - * List object. - *

- * It returns a reference to the {@link Subscription} interface. This - * enables Observers to unsubscribe (that is, to stop receiving - * notifications) before the Observable has finished sending them and has - * called the Observer's {@link Observer#onCompleted()} method. - *

- * At any given time, a particular instance of an Observable - * implementation is responsible for accepting all subscriptions and - * notifying all subscribers. Unless the documentation for a particular - * Observable implementation indicates otherwise, Observers - * should make no assumptions about the Observable - * implementation, such as the order of notifications that multiple - * Observers will receive. - *

- * For more information see the - * RxJava - * Wiki - * - * - * @param observer - * - * @return a {@link Subscription} reference that allows observers to stop - * receiving notifications before the provider has finished sending them - */ - public Subscription subscribe(Observer observer) { - // allow the hook to intercept and/or decorate - Func1, Subscription> onSubscribeFunction = HOOK.onSubscribeStart(this, onSubscribe); - // validate and proceed - if (onSubscribeFunction == null) - throw new IllegalStateException("onSubscribe function can not be null."); // the subscribe function can also be overridden but generally that's not the appropriate approach so I won't mention that in the exception - try { - /** - * See https://github.com/Netflix/RxJava/issues/216 for discussion - * on "Guideline 6.4: Protect calls to user code from within an - * operator" - */ - if (isInternalImplementation(observer)) { - Subscription s = onSubscribeFunction.call(observer); - if (s == null) - // this generally shouldn't be the case on a 'trusted' onSubscribe but in case it happens - // we want to gracefully handle it the same as AtomicObservableSubscription does - return HOOK.onSubscribeReturn(this, Subscriptions.empty()); - else - return HOOK.onSubscribeReturn(this, s); - } else { - AtomicObservableSubscription subscription = new AtomicObservableSubscription(); - subscription.wrap(onSubscribeFunction.call(new AtomicObserver<>(subscription, observer))); - return HOOK.onSubscribeReturn(this, subscription); - } - } catch (Exception e) { - // if an unhandled error occurs executing the onSubscribe we will propagate it - try { - observer.onError(HOOK.onSubscribeError(this, e)); - } catch (Exception e2) { - // if this happens it means the onError itself failed (perhaps an invalid function implementation) - // so we are unable to propagate the error correctly and will just throw - RuntimeException r = new RuntimeException("Error occurred attempting to subscribe [" + e.getMessage() + "] and then again while trying to pass to onError.", e2); - HOOK.onSubscribeError(this, r); - throw r; - } - return Subscriptions.empty(); - } - } - - /** - * an {@link Observer} must call an Observable's subscribe - * method in order to register itself to receive push-based notifications - * from the Observable. A typical implementation of the - * subscribe method does the following: - *

- * It stores a reference to the Observer in a collection object, such as a - * List object. - *

- * It returns a reference to the {@link Subscription} interface. This - * enables Observers to unsubscribe (that is, to stop receiving - * notifications) before the Observable has finished sending them and has - * called the Observer's {@link Observer#onCompleted()} method. - *

- * At any given time, a particular instance of an Observable - * implementation is responsible for accepting all subscriptions and - * notifying all subscribers. Unless the documentation for a particular - * Observable implementation indicates otherwise, Observers - * should make no assumptions about the Observable - * implementation, such as the order of notifications that multiple - * Observers will receive. - *

- * For more information see the - * RxJava - * Wiki - * - * - * @param observer - * @param scheduler The {@link Scheduler} that the sequence is subscribed to - * on. - * - * @return a {@link Subscription} reference that allows observers to stop - * receiving notifications before the provider has finished sending them - */ - public Subscription subscribe(Observer observer, Scheduler scheduler) { - return subscribeOn(scheduler).subscribe(observer); - } - - /** - * Used for protecting against errors being thrown from Observer - * implementations and ensuring onNext/onError/onCompleted contract - * compliance. - *

- * See https://github.com/Netflix/RxJava/issues/216 for discussion on - * "Guideline 6.4: Protect calls to user code from within an operator" - */ - private Subscription protectivelyWrapAndSubscribe(Observer o) { - AtomicObservableSubscription subscription = new AtomicObservableSubscription(); - return subscription.wrap(subscribe(new AtomicObserver<>(subscription, o))); - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - public Subscription subscribe(final Map callbacks) { - // lookup and memoize onNext - Object _onNext = callbacks.get("onNext"); - if (_onNext == null) - throw new RuntimeException("onNext must be implemented"); - final FuncN onNext = Functions.from(_onNext); - - /** - * Wrapping since raw functions provided by the user are being invoked. - *

- * See https://github.com/Netflix/RxJava/issues/216 for discussion on - * "Guideline 6.4: Protect calls to user code from within an operator" - */ - return protectivelyWrapAndSubscribe(new Observer() { - - @Override - public void onCompleted() { - Object onComplete = callbacks.get("onCompleted"); - if (onComplete != null) - Functions.from(onComplete).call(); - } - - @Override - public void onError(Exception e) { - handleError(e); - Object onError = callbacks.get("onError"); - if (onError != null) - Functions.from(onError).call(e); - } - - @Override - public void onNext(Object args) { - onNext.call(args); - } - - }); - } - - public Subscription subscribe(final Map callbacks, Scheduler scheduler) { - return subscribeOn(scheduler).subscribe(callbacks); - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - public Subscription subscribe(final Object o) { - if (o instanceof Observer) - // in case a dynamic language is not correctly handling the overloaded methods and we receive an Observer just forward to the correct method. - return subscribe((Observer) o); - - // lookup and memoize onNext - if (o == null) - throw new RuntimeException("onNext must be implemented"); - final FuncN onNext = Functions.from(o); - - /** - * Wrapping since raw functions provided by the user are being invoked. - *

- * See https://github.com/Netflix/RxJava/issues/216 for discussion on - * "Guideline 6.4: Protect calls to user code from within an operator" - */ - return protectivelyWrapAndSubscribe(new Observer() { - - @Override - public void onCompleted() { - // do nothing - } - - @Override - public void onError(Exception e) { - handleError(e); - // no callback defined - } - - @Override - public void onNext(Object args) { - onNext.call(args); - } - - }); - } - - public Subscription subscribe(final Object o, Scheduler scheduler) { - return subscribeOn(scheduler).subscribe(o); - } - - public Subscription subscribe(final Action1 onNext) { - - /** - * Wrapping since raw functions provided by the user are being invoked. - *

- * See https://github.com/Netflix/RxJava/issues/216 for discussion on - * "Guideline 6.4: Protect calls to user code from within an operator" - */ - return protectivelyWrapAndSubscribe(new Observer() { - - @Override - public void onCompleted() { - // do nothing - } - - @Override - public void onError(Exception e) { - handleError(e); - // no callback defined - } - - @Override - public void onNext(T args) { - if (onNext == null) - throw new RuntimeException("onNext must be implemented"); - onNext.call(args); - } - - }); - } - - public Subscription subscribe(final Action1 onNext, Scheduler scheduler) { - return subscribeOn(scheduler).subscribe(onNext); - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - public Subscription subscribe(final Object onNext, final Object onError) { - // lookup and memoize onNext - if (onNext == null) - throw new RuntimeException("onNext must be implemented"); - final FuncN onNextFunction = Functions.from(onNext); - - /** - * Wrapping since raw functions provided by the user are being invoked. - *

- * See https://github.com/Netflix/RxJava/issues/216 for discussion on - * "Guideline 6.4: Protect calls to user code from within an operator" - */ - return protectivelyWrapAndSubscribe(new Observer() { - - @Override - public void onCompleted() { - // do nothing - } - - @Override - public void onError(Exception e) { - handleError(e); - if (onError != null) - Functions.from(onError).call(e); - } - - @Override - public void onNext(Object args) { - onNextFunction.call(args); - } - - }); - } - - public Subscription subscribe(final Object onNext, final Object onError, Scheduler scheduler) { - return subscribeOn(scheduler).subscribe(onNext, onError); - } - - public Subscription subscribe(final Action1 onNext, final Action1 onError) { - - /** - * Wrapping since raw functions provided by the user are being invoked. - *

- * See https://github.com/Netflix/RxJava/issues/216 for discussion on - * "Guideline 6.4: Protect calls to user code from within an operator" - */ - return protectivelyWrapAndSubscribe(new Observer() { - - @Override - public void onCompleted() { - // do nothing - } - - @Override - public void onError(Exception e) { - handleError(e); - if (onError != null) - onError.call(e); - } - - @Override - public void onNext(T args) { - if (onNext == null) - throw new RuntimeException("onNext must be implemented"); - onNext.call(args); - } - - }); - } - - public Subscription subscribe(final Action1 onNext, final Action1 onError, Scheduler scheduler) { - return subscribeOn(scheduler).subscribe(onNext, onError); - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - public Subscription subscribe(final Object onNext, final Object onError, final Object onComplete) { - // lookup and memoize onNext - if (onNext == null) - throw new RuntimeException("onNext must be implemented"); - final FuncN onNextFunction = Functions.from(onNext); - - /** - * Wrapping since raw functions provided by the user are being invoked. - *

- * See https://github.com/Netflix/RxJava/issues/216 for discussion on - * "Guideline 6.4: Protect calls to user code from within an operator" - */ - return protectivelyWrapAndSubscribe(new Observer() { - - @Override - public void onCompleted() { - if (onComplete != null) - Functions.from(onComplete).call(); - } - - @Override - public void onError(Exception e) { - handleError(e); - if (onError != null) - Functions.from(onError).call(e); - } - - @Override - public void onNext(Object args) { - onNextFunction.call(args); - } - - }); - } - - public Subscription subscribe(final Object onNext, final Object onError, final Object onComplete, Scheduler scheduler) { - return subscribeOn(scheduler).subscribe(onNext, onError, onComplete); - } - - public Subscription subscribe(final Action1 onNext, final Action1 onError, final Action0 onComplete) { - - /** - * Wrapping since raw functions provided by the user are being invoked. - *

- * See https://github.com/Netflix/RxJava/issues/216 for discussion on - * "Guideline 6.4: Protect calls to user code from within an operator" - */ - return protectivelyWrapAndSubscribe(new Observer() { - - @Override - public void onCompleted() { - onComplete.call(); - } - - @Override - public void onError(Exception e) { - handleError(e); - if (onError != null) - onError.call(e); - } - - @Override - public void onNext(T args) { - if (onNext == null) - throw new RuntimeException("onNext must be implemented"); - onNext.call(args); - } - - }); - } - - public Subscription subscribe(final Action1 onNext, final Action1 onError, final Action0 onComplete, Scheduler scheduler) { - return subscribeOn(scheduler).subscribe(onNext, onError, onComplete); - } - - /** - * Invokes an action for each element in the observable sequence, and blocks - * until the sequence is terminated. - *

- * NOTE: This will block even if the Observable is asynchronous. - *

- * This is similar to {@link #subscribe(Observer)} but blocks. Because it - * blocks it does not need the {@link Observer#onCompleted()} or - * {@link Observer#onError(Exception)} methods. - * - * @param onNext {@link Action1} - * - * @throws RuntimeException if error occurs - */ - public void forEach(final Action1 onNext) { - final CountDownLatch latch = new CountDownLatch(1); - final AtomicReference exceptionFromOnError = new AtomicReference<>(); - - /** - * Wrapping since raw functions provided by the user are being invoked. - *

- * See https://github.com/Netflix/RxJava/issues/216 for discussion on - * "Guideline 6.4: Protect calls to user code from within an operator" - */ - protectivelyWrapAndSubscribe(new Observer() { - @Override - public void onCompleted() { - latch.countDown(); - } - - @Override - public void onError(Exception e) { - /* - * If we receive an onError event we set the reference on the - * outer thread - * so we can git it and throw after the latch.await(). - * - * We do this instead of throwing directly since this may be on - * a different thread and the latch is still waiting. - */ - exceptionFromOnError.set(e); - latch.countDown(); - } - - @Override - public void onNext(T args) { - onNext.call(args); - } - }); - // block until the subscription completes and then return - try { - latch.await(); - } catch (InterruptedException e) { - // set the interrupted flag again so callers can still get it - // for more information see https://github.com/Netflix/RxJava/pull/147#issuecomment-13624780 - Thread.currentThread().interrupt(); - // using Runtime so it is not checked - throw new RuntimeException("Interrupted while waiting for subscription to complete.", e); - } - - if (exceptionFromOnError.get() != null) - if (exceptionFromOnError.get() instanceof RuntimeException) - throw (RuntimeException) exceptionFromOnError.get(); - else - throw new RuntimeException(exceptionFromOnError.get()); - } - - /** - * Invokes an action for each element in the observable sequence, and blocks - * until the sequence is terminated. - *

- * NOTE: This will block even if the Observable is asynchronous. - *

- * This is similar to {@link #subscribe(Observer)} but blocks. Because it - * blocks it does not need the {@link Observer#onCompleted()} or - * {@link Observer#onError(Exception)} methods. - * - * @param o {@link Action1} - * - * @throws RuntimeException if error occurs - */ - @SuppressWarnings({ "rawtypes", "unchecked" }) - public void forEach(final Object o) { - if (o instanceof Action1) - // in case a dynamic language is not correctly handling the overloaded methods and we receive an Action1 just forward to the correct method. - forEach((Action1) o); - - // lookup and memoize onNext - if (o == null) - throw new RuntimeException("onNext must be implemented"); - final FuncN onNext = Functions.from(o); - - forEach(onNext::call); - } - - /** - * Returns the only element of an observable sequence and throws an - * exception if there is not exactly one element in the observable sequence. - * - * @return The single element in the observable sequence. - */ - public T single() { - return single(this); - } - - /** - * Returns the only element of an observable sequence that matches the - * predicate and throws an exception if there is not exactly one element in - * the observable sequence. - * - * @param predicate A predicate function to evaluate for elements in the - * sequence. - * - * @return The single element in the observable sequence. - */ - public T single(Func1 predicate) { - return single(this, predicate); - } - - /** - * Returns the only element of an observable sequence that matches the - * predicate and throws an exception if there is not exactly one element in - * the observable sequence. - * - * @param predicate A predicate function to evaluate for elements in the - * sequence. - * - * @return The single element in the observable sequence. - */ - public T single(Object predicate) { - return single(this, predicate); - } - - /** - * Returns the only element of an observable sequence, or a default value if - * the observable sequence is empty. - * - * @param defaultValue default value for a sequence. - * - * @return The single element in the observable sequence, or a default value - * if no value is found. - */ - public T singleOrDefault(T defaultValue) { - return singleOrDefault(this, defaultValue); - } - - /** - * Returns the only element of an observable sequence that matches the - * predicate, or a default value if no value is found. - * - * @param defaultValue default value for a sequence. - * @param predicate A predicate function to evaluate for elements in the - * sequence. - * - * @return The single element in the observable sequence, or a default value - * if no value is found. - */ - public T singleOrDefault(T defaultValue, Func1 predicate) { - return singleOrDefault(this, defaultValue, predicate); - } - - /** - * Returns the only element of an observable sequence that matches the - * predicate, or a default value if no value is found. - * - * @param defaultValue default value for a sequence. - * @param predicate A predicate function to evaluate for elements in the - * sequence. - * - * @return The single element in the observable sequence, or a default value - * if no value is found. - */ - public T singleOrDefault(T defaultValue, Object predicate) { - return singleOrDefault(this, defaultValue, predicate); - } - - /** - * Allow the {@link RxJavaErrorHandler} to receive the exception from - * onError. - * - * @param e - */ - private void handleError(Exception e) { - // onError should be rare so we'll only fetch when needed - RxJavaPlugins.getInstance().getErrorHandler().handleError(e); - } - - /** - * An Observable that never sends any information to an {@link Observer}. - *

- * This Observable is useful primarily for testing purposes. - * - * @param the type of item emitted by the Observable - */ - private static class NeverObservable extends Observable { - - public NeverObservable() { - super((Observer t1) -> Subscriptions.empty()); - } - } - - /** - * an Observable that calls {@link Observer#onError(Exception)} when the - * Observer subscribes. - * - * @param the type of object returned by the Observable - */ - private static class ThrowObservable extends Observable { - - public ThrowObservable(final Exception exception) { - /** - * Accepts an {@link Observer} and calls its onError - * method. - * - * @param observer an {@link Observer} of this Observable - * - * @return a reference to the subscription - */ - super((Observer observer) -> { - observer.onError(exception); - return Subscriptions.empty(); - }); - } - - } - - public static Observable createWithEmptySubscription(Action1> func) { - return new Observable<>(t -> { - func.call(t); - return Subscriptions.empty(); - }); - } - - /** - * Creates an Observable that will execute the given function when a - * {@link Observer} subscribes to it. - *

- * Write the function you pass to create so that it behaves as - * an Observable - calling the passed-in onNext, - * onError, and onCompleted methods appropriately. - *

- * A well-formed Observable must call either the {@link Observer}'s - * onCompleted method exactly once or its onError - * method exactly once. - *

- * See Rx Design - * Guidelines (PDF) for detailed information. - * - * @param the type emitted by the Observable sequence - * @param func a function that accepts an Observer and calls - * its onNext, onError, and - * onCompleted methods as appropriate, and returns a - * {@link Subscription} to allow canceling the subscription (if applicable) - * - * @return an Observable that, when an {@link Observer} subscribes to it, - * will execute the given function - */ - public static Observable create(Func1, Subscription> func) { - return new Observable<>(func); - } - - /** - * Creates an Observable that will execute the given function when a - * {@link Observer} subscribes to it. - *

- * This method accept {@link Object} to allow different languages to pass in - * closures using {@link FunctionLanguageAdaptor}. - *

- * Write the function you pass to create so that it behaves as - * an Observable - calling the passed-in onNext, - * onError, and onCompleted methods appropriately. - *

- * A well-formed Observable must call either the {@link Observer}'s - * onCompleted method exactly once or its onError - * method exactly once. - *

- * See Rx Design - * Guidelines (PDF) for detailed information. - * - * @param the type emitted by the Observable sequence - * @param func a function that accepts an Observer and calls - * its onNext, onError, and - * onCompleted methods as appropriate, and returns a - * {@link Subscription} to allow canceling the subscription (if applicable) - * - * @return an Observable that, when an {@link Observer} subscribes to it, - * will execute the given function - */ - public static Observable create(final Object func) { - final FuncN _f = Functions.from(func); - return create((Observer t1) -> (Subscription) _f.call(t1)); - } - - /** - * Returns an Observable that returns no data to the {@link Observer} and - * immediately invokes its onCompleted method. - *

- * - * - * @param the type of item emitted by the Observable - * - * @return an Observable that returns no data to the {@link Observer} and - * immediately invokes the {@link Observer}'s onCompleted - * method - */ - public static Observable empty() { - return toObservable(new ArrayList()); - } - - /** - * Returns an Observable that calls onError when an - * {@link Observer} subscribes to it. - *

- * - * @param exception the error to throw - * @param the type of object returned by the Observable - * - * @return an Observable object that calls onError when an - * {@link Observer} subscribes - */ - public static Observable error(Exception exception) { - return new ThrowObservable<>(exception); - } - - /** - * Filters an Observable by discarding any of its emissions that do not meet - * some test. - *

- * - * - * @param that the Observable to filter - * @param predicate a function that evaluates the items emitted by the - * source Observable, returning true if they pass the filter - * - * @return an Observable that emits only those items in the original - * Observable that the filter evaluates as true - */ - public static Observable filter(Observable that, Func1 predicate) { - return create(OperationFilter.filter(that, predicate)); - } - - /** - * Filters an Observable by discarding any of its emissions that do not meet - * some test. - *

- * - * - * @param that the Observable to filter - * @param function a function that evaluates the items emitted by the source - * Observable, returning true if they pass the filter - * - * @return an Observable that emits only those items in the original - * Observable that the filter evaluates as true - */ - public static Observable filter(Observable that, final Object function) { - final FuncN _f = Functions.from(function); - return filter(that, (T t1) -> (Boolean) _f.call(t1)); - } - - /** - * Filters an Observable by discarding any of its emissions that do not meet - * some test. - *

- * - * - * @param that the Observable to filter - * @param predicate a function that evaluates the items emitted by the - * source Observable, returning true if they pass the filter - * - * @return an Observable that emits only those items in the original - * Observable that the filter evaluates as true - */ - public static Observable where(Observable that, Func1 predicate) { - return create(OperationWhere.where(that, predicate)); - } - - /** - * Converts an {@link Iterable} sequence to an Observable sequence. - * - * @param iterable the source {@link Iterable} sequence - * @param the type of items in the {@link Iterable} sequence and - * the - * type emitted by the resulting Observable - * - * @return an Observable that emits each item in the source {@link Iterable} - * sequence - * - * @see {@link #toObservable(Iterable)} - */ - public static Observable from(Iterable iterable) { - return toObservable(iterable); - } - - /** - * Converts an Array to an Observable sequence. - * - * @param items the source Array - * @param the type of items in the Array, and the type of items - * emitted - * by the resulting Observable - * - * @return an Observable that emits each item in the source Array - * - * @see {@link #toObservable(Object...)} - */ - public static Observable from(T... items) { - return toObservable(items); - } - - /** - * Generates an observable sequence of integral numbers within a specified - * range. - * - * @param start The value of the first integer in the sequence - * @param count The number of sequential integers to generate. - * - * @return An observable sequence that contains a range of sequential - * integral numbers. - * - * @see - * Observable.Range - * Method (Int32, Int32) - */ - public static Observable range(int start, int count) { - return from(Range.createWithCount(start, count)); - } - - /** - * Asynchronously subscribes and unsubscribes observers on the specified - * scheduler. - * - * @param source the source observable. - * @param scheduler the scheduler to perform subscription and unsubscription - * actions on. - * @param the type of observable. - * - * @return the source sequence whose subscriptions and unsubscriptions - * happen on the specified scheduler. - */ - public static Observable subscribeOn(Observable source, Scheduler scheduler) { - return create(OperationSubscribeOn.subscribeOn(source, scheduler)); - } - - /** - * Asynchronously notify observers on the specified scheduler. - * - * @param source the source observable. - * @param scheduler the scheduler to notify observers on. - * @param the type of observable. - * - * @return the source sequence whose observations happen on the specified - * scheduler. - */ - public static Observable observeOn(Observable source, Scheduler scheduler) { - return create(OperationObserveOn.observeOn(source, scheduler)); - } - - /** - * Returns an observable sequence that invokes the observable factory - * whenever a new observer subscribes. The Defer operator allows you to - * defer or delay the creation of the sequence until the time when an - * observer subscribes to the sequence. This is useful to allow an observer - * to easily obtain an updates or refreshed version of the sequence. - * - * @param observableFactory the observable factory function to invoke for - * each observer that subscribes to the resulting sequence. - * @param the type of the observable. - * - * @return the observable sequence whose observers trigger an invocation of - * the given observable factory function. - */ - public static Observable defer(Func0> observableFactory) { - return create(OperationDefer.defer(observableFactory)); - } - - /** - * Returns an observable sequence that invokes the observable factory - * whenever a new observer subscribes. The Defer operator allows you to - * defer or delay the creation of the sequence until the time when an - * observer subscribes to the sequence. This is useful to allow an observer - * to easily obtain an updates or refreshed version of the sequence. - * - * @param observableFactory the observable factory function to invoke for - * each observer that subscribes to the resulting sequence. - * @param the type of the observable. - * - * @return the observable sequence whose observers trigger an invocation of - * the given observable factory function. - */ - public static Observable defer(Object observableFactory) { - final FuncN _f = Functions.from(observableFactory); - - return create(OperationDefer.defer(() -> (Observable) _f.call())); - } - - /** - * Returns an Observable that notifies an {@link Observer} of a single value - * and then completes. - *

- * To convert any object into an Observable that emits that object, pass - * that object into the just method. - *

- * This is similar to the {@link #toObservable} method, except that - * toObservable will convert an {@link Iterable} object into an - * Observable that emits each of the items in the {@link Iterable}, one at a - * time, while the just method would convert the - * {@link Iterable} into an Observable that emits the entire - * {@link Iterable} as a single item. - *

- * - * - * @param value the value to pass to the Observer's onNext - * method - * @param the type of the value - * - * @return an Observable that notifies an {@link Observer} of a single value - * and then completes - */ - public static Observable just(T value) { - List list = new ArrayList<>(); - list.add(value); - - return toObservable(list); - } - - /** - * Returns the last element of an observable sequence with a specified - * source. - * - * @param that the source Observable - * - * @return the last element in the observable sequence. - */ - public static T last(final Observable that) { - T result = null; - for (T value : that.toIterable()) - result = value; - return result; - } - - /** - * Returns the last element of an observable sequence that matches the - * predicate. - * - * @param that the source Observable - * @param predicate a predicate function to evaluate for elements in the - * sequence. - * - * @return the last element in the observable sequence. - */ - public static T last(final Observable that, final Func1 predicate) { - return last(that.filter(predicate)); - } - - /** - * Returns the last element of an observable sequence that matches the - * predicate. - * - * @param that the source Observable - * @param predicate a predicate function to evaluate for elements in the - * sequence. - * - * @return the last element in the observable sequence. - */ - public static T last(final Observable that, final Object predicate) { - return last(that.filter(predicate)); - } - - /** - * Returns the last element of an observable sequence, or a default value if - * no value is found. - * - * @param source the source observable. - * @param defaultValue a default value that would be returned if observable - * is empty. - * @param the type of source. - * - * @return the last element of an observable sequence that matches the - * predicate, or a default value if no value is found. - */ - public static T lastOrDefault(Observable source, T defaultValue) { - boolean found = false; - T result = null; - - for (T value : source.toIterable()) { - found = true; - result = value; - } - - if (!found) - return defaultValue; - - return result; - } - - /** - * Returns the last element of an observable sequence that matches the - * predicate, or a default value if no value is found. - * - * @param source the source observable. - * @param defaultValue a default value that would be returned if observable - * is empty. - * @param predicate a predicate function to evaluate for elements in the - * sequence. - * @param the type of source. - * - * @return the last element of an observable sequence that matches the - * predicate, or a default value if no value is found. - */ - public static T lastOrDefault(Observable source, T defaultValue, Func1 predicate) { - return lastOrDefault(source.filter(predicate), defaultValue); - } - - /** - * Returns the last element of an observable sequence that matches the - * predicate, or a default value if no value is found. - * - * @param source the source observable. - * @param defaultValue a default value that would be returned if observable - * is empty. - * @param predicate a predicate function to evaluate for elements in the - * sequence. - * @param the type of source. - * - * @return the last element of an observable sequence that matches the - * predicate, or a default value if no value is found. - */ - public static T lastOrDefault(Observable source, T defaultValue, Object predicate) { - final FuncN _f = Functions.from(predicate); - - return lastOrDefault(source, defaultValue, (T args) -> (Boolean) _f.call(args)); - } - - /** - * Applies a function of your choosing to every notification emitted by an - * Observable, and returns this transformation as a new Observable sequence. - *

- * - * - * @param sequence the source Observable - * @param func a function to apply to each item in the sequence emitted - * by - * the source Observable - * @param the type of items emitted by the the source Observable - * @param the type of items returned by map function - * - * @return an Observable that is the result of applying the transformation - * function to each item in the sequence emitted by the source Observable - */ - public static Observable map(Observable sequence, Func1 func) { - return create(OperationMap.map(sequence, func)); - } - - /** - * Applies a function of your choosing to every notification emitted by an - * Observable, and returns this transformation as a new Observable sequence. - *

- * - * - * @param sequence the source Observable - * @param func a function to apply to each item in the sequence emitted - * by - * the source Observable - * @param the type of items emitted by the the source Observable - * @param the type of items returned by map function - * - * @return an Observable that is the result of applying the transformation - * function to each item in the sequence emitted by the source Observable - */ - public static Observable map(Observable sequence, final Object func) { - final FuncN _f = Functions.from(func); - return map(sequence, (T t1) -> (R) _f.call(t1)); - } - - /** - * Creates a new Observable sequence by applying a function that you supply - * to each object in the original Observable sequence, where that function - * is itself an Observable that emits objects, and then merges the results - * of that function applied to every item emitted by the original - * Observable, emitting these merged results as its own sequence. - *

- * - * - * @param sequence the source Observable - * @param func a function to apply to each item emitted by the source - * Observable, generating a Observable - * @param the type emitted by the source Observable - * @param the type emitted by the Observables emitted by - * func - * - * @return an Observable that emits a sequence that is the result of - * applying the transformation function to each item emitted by the source - * Observable and merging the results of the Observables obtained from this - * transformation - */ - public static Observable mapMany(Observable sequence, Func1> func) { - return create(OperationMap.mapMany(sequence, func)); - } - - /** - * Creates a new Observable sequence by applying a function that you supply - * to each object in the original Observable sequence, where that function - * is itself an Observable that emits objects, and then merges the results - * of that function applied to every item emitted by the original - * Observable, emitting these merged results as its own sequence. - *

- * - * - * @param sequence the source Observable - * @param func a function to apply to each item emitted by the source - * Observable, generating a Observable - * @param the type emitted by the source Observable - * @param the type emitted by the Observables emitted by - * func - * - * @return an Observable that emits a sequence that is the result of - * applying the transformation function to each item emitted by the source - * Observable and merging the results of the Observables obtained from this - * transformation - */ - public static Observable mapMany(Observable sequence, final Object func) { - final FuncN _f = Functions.from(func); - return mapMany(sequence, (T t1) -> (Observable) _f.call(t1)); - } - - /** - * Materializes the implicit notifications of an observable sequence as - * explicit notification values. - *

- * - * - * @param sequence An observable sequence of elements to project. - * - * @return An observable sequence whose elements are the result of - * materializing the notifications of the given sequence. - * - * @see - * MSDN: - * Observable.Materialize - */ - public static Observable> materialize(final Observable sequence) { - return create(OperationMaterialize.materialize(sequence)); - } - - /** - * Dematerializes the explicit notification values of an observable sequence - * as implicit notifications. - * - * @param sequence An observable sequence containing explicit notification - * values which have to be turned into implicit notifications. - * - * @return An observable sequence exhibiting the behavior corresponding to - * the source sequence's notification values. - * - * @see - * MSDN: - * Observable.Dematerialize - */ - public static Observable dematerialize(final Observable> sequence) { - return create(OperationDematerialize.dematerialize(sequence)); - } - - /** - * Flattens the Observable sequences from a list of Observables into one - * Observable sequence without any transformation. You can combine the - * output of multiple Observables so that they act like a single Observable, - * by using the merge method. - *

- * - * - * @param source a list of Observables that emit sequences of items - * - * @return an Observable that emits a sequence of elements that are the - * result of flattening the output from the source list of - * Observables - * - * @see - * MSDN: - * Observable.Merge - */ - public static Observable merge(List> source) { - return create(OperationMerge.merge(source)); - } - - /** - * Flattens the Observable sequences emitted by a sequence of Observables - * that are emitted by a Observable into one Observable sequence without any - * transformation. You can combine the output of multiple Observables so - * that they act like a single Observable, by using the merge - * method. - *

- * - * - * @param source an Observable that emits Observables - * - * @return an Observable that emits a sequence of elements that are the - * result of flattening the output from the Observables emitted by the - * source Observable - * - * @see - * MSDN: - * Observable.Merge Method - */ - public static Observable merge(Observable> source) { - return create(OperationMerge.merge(source)); - } - - /** - * Flattens the Observable sequences from a series of Observables into one - * Observable sequence without any transformation. You can combine the - * output of multiple Observables so that they act like a single Observable, - * by using the merge method. - *

- * - * - * @param source a series of Observables that emit sequences of items - * - * @return an Observable that emits a sequence of elements that are the - * result of flattening the output from the source Observables - * - * @see - * MSDN: - * Observable.Merge Method - */ - public static Observable merge(Observable... source) { - return create(OperationMerge.merge(source)); - } - - /** - * Returns the values from the source observable sequence until the other - * observable sequence produces a value. - * - * @param source the source sequence to propagate elements for. - * @param other the observable sequence that terminates propagation of - * elements of the source sequence. - * @param the type of source. - * @param the other type. - * - * @return An observable sequence containing the elements of the source - * sequence up to the point the other sequence interrupted further - * propagation. - */ - public static Observable takeUntil(final Observable source, final Observable other) { - return OperatorTakeUntil.takeUntil(source, other); - } - - /** - * Combines the objects emitted by two or more Observables, and emits the - * result as a single Observable, by using the concat method. - *

- * - * - * @param source a series of Observables that emit sequences of items - * - * @return an Observable that emits a sequence of elements that are the - * result of combining the output from the source Observables - * - * @see - * MSDN: - * Observable.Concat Method - */ - public static Observable concat(Observable... source) { - return create(OperationConcat.concat(source)); - } - - /** - * Emits the same objects as the given Observable, calling the given action - * when it calls onComplete or onError. - * - * @param source an observable - * @param action an action to be called when the source completes or errors. - * - * @return an Observable that emits the same objects, then calls the action. - * - * @see - * MSDN: - * Observable.Finally Method - */ - public static Observable finallyDo(Observable source, Action0 action) { - return create(OperationFinally.finallyDo(source, action)); - } - - /** - * Groups the elements of an observable and selects the resulting elements - * by using a specified function. - * - * @param source an observable whose elements to group. - * @param keySelector a function to extract the key for each element. - * @param elementSelector a function to map each source element to an - * element in an observable group. - * @param the key type. - * @param the source type. - * @param the resulting observable type. - * - * @return an observable of observable groups, each of which corresponds to - * a unique key value, containing all elements that share that same key - * value. - */ - public static Observable> groupBy(Observable source, final Func1 keySelector, final Func1 elementSelector) { - return create(OperatorGroupBy.groupBy(source, keySelector, elementSelector)); - } - - /** - * Groups the elements of an observable according to a specified key - * selector function and - * - * @param source an observable whose elements to group. - * @param keySelector a function to extract the key for each element. - * @param the key type. - * @param the source type. - * - * @return an observable of observable groups, each of which corresponds to - * a unique key value, containing all elements that share that same key - * value. - */ - public static Observable> groupBy(Observable source, final Func1 keySelector) { - return create(OperatorGroupBy.groupBy(source, keySelector)); - } - - /** - * Same functionality as merge except that errors received to - * onError will be held until all sequences have finished - * (onComplete/onError) before sending the error. - *

- * Only the first onError received will be sent. - *

- * This enables receiving all successes from merged sequences without one - * onError from one sequence causing all onNext calls to be prevented. - *

- * - * - * @param source a list of Observables that emit sequences of items - * - * @return an Observable that emits a sequence of elements that are the - * result of flattening the output from the source list of - * Observables - * - * @see - * MSDN: - * Observable.Merge Method - */ - public static Observable mergeDelayError(List> source) { - return create(OperationMergeDelayError.mergeDelayError(source)); - } - - /** - * Same functionality as merge except that errors received to - * onError will be held until all sequences have finished - * (onComplete/onError) before sending the error. - *

- * Only the first onError received will be sent. - *

- * This enables receiving all successes from merged sequences without one - * onError from one sequence causing all onNext calls to be prevented. - *

- * - * - * @param source an Observable that emits Observables - * - * @return an Observable that emits a sequence of elements that are the - * result of flattening the output from the Observables emitted by the - * source Observable - * - * @see - * MSDN: - * Observable.Merge Method - */ - public static Observable mergeDelayError(Observable> source) { - return create(OperationMergeDelayError.mergeDelayError(source)); - } - - /** - * Same functionality as merge except that errors received to - * onError will be held until all sequences have finished - * (onComplete/onError) before sending the error. - *

- * Only the first onError received will be sent. - *

- * This enables receiving all successes from merged sequences without one - * onError from one sequence causing all onNext calls to be prevented. - *

- * - * - * @param source a series of Observables that emit sequences of items - * - * @return an Observable that emits a sequence of elements that are the - * result of flattening the output from the source Observables - * - * @see - * MSDN: - * Observable.Merge Method - */ - public static Observable mergeDelayError(Observable... source) { - return create(OperationMergeDelayError.mergeDelayError(source)); - } - - /** - * Returns an Observable that never sends any information to an - * {@link Observer}. - *

- * This observable is useful primarily for testing purposes. - * - * @param the type of item (not) emitted by the Observable - * - * @return an Observable that never sends any information to an - * {@link Observer} - */ - public static Observable never() { - return new NeverObservable<>(); - } - - /** - * Instruct an Observable to pass control to another Observable (the return - * value of a function) rather than calling onError if it - * encounters an error. - *

- * By default, when an Observable encounters an error that prevents it from - * emitting the expected item to its Observer, the Observable calls its - * {@link Observer}'s onError function, and then quits without - * calling any more of its {@link Observer}'s closures. The - * onErrorResumeNext method changes this behavior. If you pass - * a function that emits an Observable (resumeFunction) to an - * Observable's onErrorResumeNext method, if the original - * Observable encounters an error, instead of calling its {@link Observer}'s - * onError function, it will instead relinquish control to this - * new Observable, which will call the {@link Observer}'s - * onNext method if it is able to do so. In such a case, - * because no Observable necessarily invokes onError, the - * Observer may never know that an error happened. - *

- * You can use this to prevent errors from propagating or to supply fallback - * data should errors be encountered. - *

- * - * - * @param that the source Observable - * @param resumeFunction a function that returns an Observable that will - * take over if the source Observable encounters an error - * - * @return the source Observable, with its behavior modified as described - */ - public static Observable onErrorResumeNext(final Observable that, final Func1> resumeFunction) { - return create(OperationOnErrorResumeNextViaFunction.onErrorResumeNextViaFunction(that, resumeFunction)); - } - - /** - * Instruct an Observable to pass control to another Observable (the return - * value of a function) rather than calling onError if it - * encounters an error. - *

- * By default, when an Observable encounters an error that prevents it from - * emitting the expected item to its Observer, the Observable calls its - * {@link Observer}'s onError function, and then quits without - * calling any more of its {@link Observer}'s closures. The - * onErrorResumeNext method changes this behavior. If you pass - * a function that emits an Observable (resumeFunction) to an - * Observable's onErrorResumeNext method, if the original - * Observable encounters an error, instead of calling its {@link Observer}'s - * onError function, it will instead relinquish control to this - * new Observable, which will call the {@link Observer}'s - * onNext method if it is able to do so. In such a case, - * because no Observable necessarily invokes onError, the - * Observer may never know that an error happened. - *

- * You can use this to prevent errors from propagating or to supply fallback - * data should errors be encountered. - *

- * - * - * @param that the source Observable - * @param resumeFunction a function that returns an Observable that will - * take over if the source Observable encounters an error - * - * @return the source Observable, with its behavior modified as described - */ - public static Observable onErrorResumeNext(final Observable that, final Object resumeFunction) { - final FuncN _f = Functions.from(resumeFunction); - return onErrorResumeNext(that, (Exception e) -> (Observable) _f.call(e)); - } - - /** - * Instruct an Observable to pass control to another Observable rather than - * calling onError if it encounters an error. - *

- * By default, when an Observable encounters an error that prevents it from - * emitting the expected item to its Observer, the Observable calls its - * {@link Observer}'s onError function, and then quits without - * calling any more of its {@link Observer}'s closures. The - * onErrorResumeNext method changes this behavior. If you pass - * a function that emits an Observable (resumeFunction) to an - * Observable's onErrorResumeNext method, if the original - * Observable encounters an error, instead of calling its {@link Observer}'s - * onError function, it will instead relinquish control to this - * new Observable, which will call the {@link Observer}'s - * onNext method if it is able to do so. In such a case, - * because no Observable necessarily invokes onError, the - * Observer may never know that an error happened. - *

- * You can use this to prevent errors from propagating or to supply fallback - * data should errors be encountered. - *

- * - * - * @param that the source Observable - * @param resumeSequence a function that returns an Observable that will - * take over if the source Observable encounters an error - * - * @return the source Observable, with its behavior modified as described - */ - public static Observable onErrorResumeNext(final Observable that, final Observable resumeSequence) { - return create(OperationOnErrorResumeNextViaObservable.onErrorResumeNextViaObservable(that, resumeSequence)); - } - - /** - * Instruct an Observable to emit a particular item to its Observer's - * onNext function rather than calling onError if - * it encounters an error. - *

- * By default, when an Observable encounters an error that prevents it from - * emitting the expected item to its {@link Observer}, the Observable calls - * its {@link Observer}'s onError function, and then quits - * without calling any more of its {@link Observer}'s closures. The - * onErrorReturn method changes this behavior. If you pass a - * function (resumeFunction) to an Observable's - * onErrorReturn method, if the original Observable encounters - * an error, instead of calling its {@link Observer}'s onError - * function, it will instead pass the return value of - * resumeFunction to the {@link Observer}'s onNext - * method. - *

- * You can use this to prevent errors from propagating or to supply fallback - * data should errors be encountered. - * - * @param that the source Observable - * @param resumeFunction a function that returns a value that will be passed - * into an {@link Observer}'s onNext function if the Observable - * encounters an error that would otherwise cause it to call - * onError - * - * @return the source Observable, with its behavior modified as described - */ - public static Observable onErrorReturn(final Observable that, Func1 resumeFunction) { - return create(OperationOnErrorReturn.onErrorReturn(that, resumeFunction)); - } - - /** - * Returns an Observable that applies a function of your choosing to the - * first item emitted by a source Observable, then feeds the result of that - * function along with the second item emitted by an Observable into the - * same function, and so on until all items have been emitted by the source - * Observable, emitting the final result from the final call to your - * function as its sole output. - *

- * This technique, which is called "reduce" here, is sometimes called - * "fold," "accumulate," "compress," or "inject" in other programming - * contexts. Groovy, for instance, has an inject method that - * does a similar operation on lists. - *

- * - * - * @param the type item emitted by the source Observable - * @param sequence the source Observable - * @param accumulator an accumulator function to be invoked on each element - * from the sequence, whose result will be used in the next accumulator call - * (if applicable) - * - * @return an Observable that emits a single element that is the result of - * accumulating the output from applying the accumulator to the sequence of - * items emitted by the source Observable - * - * @see - * MSDN: - * Observable.Aggregate - * @see - * Wikipedia: - * Fold (higher-order function) - */ - public static Observable reduce(Observable sequence, Func2 accumulator) { - return takeLast(create(OperationScan.scan(sequence, accumulator)), 1); - } - - /** - * Returns an Observable that applies a function of your choosing to the - * first item emitted by a source Observable, then feeds the result of that - * function along with the second item emitted by an Observable into the - * same function, and so on until all items have been emitted by the source - * Observable, emitting the final result from the final call to your - * function as its sole output. - *

- * This technique, which is called "reduce" here, is sometimes called - * "fold," "accumulate," "compress," or "inject" in other programming - * contexts. Groovy, for instance, has an inject method that - * does a similar operation on lists. - *

- * - * - * @param the type item emitted by the source Observable - * @param sequence the source Observable - * @param accumulator an accumulator function to be invoked on each element - * from the sequence, whose result will be used in the next accumulator call - * (if applicable) - * - * @return an Observable that emits a single element that is the result of - * accumulating the output from applying the accumulator to the sequence of - * items emitted by the source Observable - * - * @see - * MSDN: - * Observable.Aggregate - * @see - * Wikipedia: - * Fold (higher-order function) - */ - public static Observable reduce(final Observable sequence, final Object accumulator) { - final FuncN _f = Functions.from(accumulator); - return reduce(sequence, (T t1, T t2) -> (T) _f.call(t1, t2)); - } - - /** - * Returns an Observable that applies a function of your choosing to the - * first item emitted by a source Observable, then feeds the result of that - * function along with the second item emitted by an Observable into the - * same function, and so on until all items have been emitted by the source - * Observable, emitting the final result from the final call to your - * function as its sole output. - *

- * This technique, which is called "reduce" here, is sometimes called - * "fold," "accumulate," "compress," or "inject" in other programming - * contexts. Groovy, for instance, has an inject method that - * does a similar operation on lists. - *

- * - * - * @param the type item emitted by the source Observable - * @param sequence the source Observable - * @param initialValue a seed passed into the first execution of the - * accumulator function - * @param accumulator an accumulator function to be invoked on each element - * from the sequence, whose result will be used in the next accumulator call - * (if applicable) - * - * @return an Observable that emits a single element that is the result of - * accumulating the output from applying the accumulator to the sequence of - * items emitted by the source Observable - * - * @see - * MSDN: - * Observable.Aggregate - * @see - * Wikipedia: - * Fold (higher-order function) - */ - public static Observable reduce(Observable sequence, T initialValue, Func2 accumulator) { - return takeLast(create(OperationScan.scan(sequence, initialValue, accumulator)), 1); - } - - /** - * Returns an Observable that applies a function of your choosing to the - * first item emitted by a source Observable, then feeds the result of that - * function along with the second item emitted by an Observable into the - * same function, and so on until all items have been emitted by the source - * Observable, emitting the final result from the final call to your - * function as its sole output. - *

- * This technique, which is called "reduce" here, is sometimes called - * "fold," "accumulate," "compress," or "inject" in other programming - * contexts. Groovy, for instance, has an inject method that - * does a similar operation on lists. - *

- * - * - * @param the type item emitted by the source Observable - * @param sequence the source Observable - * @param initialValue a seed passed into the first execution of the - * accumulator function - * @param accumulator an accumulator function to be invoked on each element - * from the sequence, whose result will be used in the next accumulator call - * (if applicable) - * - * @return an Observable that emits a single element that is the result of - * accumulating the output from applying the accumulator to the sequence of - * items emitted by the source Observable - * - * @see - * MSDN: - * Observable.Aggregate - * @see - * Wikipedia: - * Fold (higher-order function) - */ - public static Observable reduce(final Observable sequence, final T initialValue, final Object accumulator) { - final FuncN _f = Functions.from(accumulator); - return reduce(sequence, initialValue, (T t1, T t2) -> (T) _f.call(t1, t2)); - } - - /** - * Returns an Observable that applies a function of your choosing to the - * first item emitted by a source Observable, then feeds the result of that - * function along with the second item emitted by an Observable into the - * same function, and so on until all items have been emitted by the source - * Observable, emitting the result of each of these iterations as its own - * sequence. - *

- * - * - * @param the type item emitted by the source Observable - * @param sequence the source Observable - * @param accumulator an accumulator function to be invoked on each element - * from the sequence, whose result will be emitted and used in the next - * accumulator call (if applicable) - * - * @return an Observable that emits a sequence of items that are the result - * of accumulating the output from the sequence emitted by the source - * Observable - * - * @see - * MSDN: - * Observable.Scan - */ - public static Observable scan(Observable sequence, Func2 accumulator) { - return create(OperationScan.scan(sequence, accumulator)); - } - - /** - * Returns an Observable that applies a function of your choosing to the - * first item emitted by a source Observable, then feeds the result of that - * function along with the second item emitted by an Observable into the - * same function, and so on until all items have been emitted by the source - * Observable, emitting the result of each of these iterations as its own - * sequence. - *

- * - * - * @param the type item emitted by the source Observable - * @param sequence the source Observable - * @param accumulator an accumulator function to be invoked on each element - * from the sequence, whose result will be emitted and used in the next - * accumulator call (if applicable) - * - * @return an Observable that emits a sequence of items that are the result - * of accumulating the output from the sequence emitted by the source - * Observable - * - * @see - * MSDN: - * Observable.Scan - */ - public static Observable scan(final Observable sequence, final Object accumulator) { - final FuncN _f = Functions.from(accumulator); - return scan(sequence, (T t1, T t2) -> (T) _f.call(t1, t2)); - } - - /** - * Returns an Observable that applies a function of your choosing to the - * first item emitted by a source Observable, then feeds the result of that - * function along with the second item emitted by an Observable into the - * same function, and so on until all items have been emitted by the source - * Observable, emitting the result of each of these iterations as its own - * sequence. - *

- * - * - * @param the type item emitted by the source Observable - * @param sequence the source Observable - * @param initialValue the initial (seed) accumulator value - * @param accumulator an accumulator function to be invoked on each element - * from the sequence, whose result will be emitted and used in the next - * accumulator call (if applicable) - * - * @return an Observable that emits a sequence of items that are the result - * of accumulating the output from the sequence emitted by the source - * Observable - * - * @see - * MSDN: - * Observable.Scan - */ - public static Observable scan(Observable sequence, T initialValue, Func2 accumulator) { - return create(OperationScan.scan(sequence, initialValue, accumulator)); - } - - /** - * Returns an Observable that applies a function of your choosing to the - * first item emitted by a source Observable, then feeds the result of that - * function along with the second item emitted by an Observable into the - * same function, and so on until all items have been emitted by the source - * Observable, emitting the result of each of these iterations as its own - * sequence. - *

- * - * - * @param the type item emitted by the source Observable - * @param sequence the source Observable - * @param initialValue the initial (seed) accumulator value - * @param accumulator an accumulator function to be invoked on each element - * from the sequence, whose result will be emitted and used in the next - * accumulator call (if applicable) - * - * @return an Observable that emits a sequence of items that are the result - * of accumulating the output from the sequence emitted by the source - * Observable - * - * @see - * MSDN: - * Observable.Scan - */ - public static Observable scan(final Observable sequence, final T initialValue, final Object accumulator) { - final FuncN _f = Functions.from(accumulator); - return scan(sequence, initialValue, (T t1, T t2) -> (T) _f.call(t1, t2)); - } - - /** - * Determines whether all elements of an observable sequence satisfies a - * condition. - * - * @param sequence an observable sequence whose elements to apply the - * predicate to. - * @param predicate a function to test each element for a condition. - * @param the type of observable. - * - * @return true if all elements of an observable sequence satisfies a - * condition; otherwise, false. - */ - public static Observable all(final Observable sequence, final Func1 predicate) { - return create(OperationAll.all(sequence, predicate)); - } - - /** - * Determines whether all elements of an observable sequence satisfies a - * condition. - * - * @param sequence an observable sequence whose elements to apply the - * predicate to. - * @param predicate a function to test each element for a condition. - * @param the type of observable. - * - * @return true if all elements of an observable sequence satisfies a - * condition; otherwise, false. - */ - public static Observable all(final Observable sequence, Object predicate) { - final FuncN _f = Functions.from(predicate); - return all(sequence, (T t) -> (Boolean) _f.call(t)); - } - - /** - * Returns an Observable that skips the first num items emitted - * by the source Observable. You can ignore the first num items - * emitted by an Observable and attend only to those items that come after, - * by modifying the Observable with the skip method. - *

- * - * - * @param items the source Observable - * @param num the number of items to skip - * - * @return an Observable that emits the same sequence of items emitted by - * the source Observable, except for the first num items - * - * @see - * MSDN: - * Observable.Skip Method - */ - public static Observable skip(final Observable items, int num) { - return create(OperationSkip.skip(items, num)); - } - - /** - * Accepts an Observable and wraps it in another Observable that ensures - * that the resulting Observable is chronologically well-behaved. - *

- * A well-behaved observable ensures onNext, - * onCompleted, or onError calls to its - * subscribers are not interleaved, onCompleted and - * onError are only called once respectively, and no - * onNext calls follow onCompleted and - * onError calls. - * - * @param observable the source Observable - * @param the type of item emitted by the source Observable - * - * @return an Observable that is a chronologically well-behaved version of - * the source Observable - */ - public static Observable synchronize(Observable observable) { - return create(OperationSynchronize.synchronize(observable)); - } - - /** - * Returns an Observable that emits the first num items emitted - * by the source Observable. - *

- * You can choose to pay attention only to the first num values - * emitted by an Observable by calling its take method. This - * method returns an Observable that will call a subscribing Observer's - * onNext function a maximum of num times before - * calling onCompleted. - *

- * - * - * @param items the source Observable - * @param num the number of items from the start of the sequence emitted - * by - * the source Observable to emit - * - * @return an Observable that only emits the first num items - * emitted by the source Observable - */ - public static Observable take(final Observable items, final int num) { - return create(OperationTake.take(items, num)); - } - - /** - * Returns an Observable that emits the last count items - * emitted by the source Observable. - * - * @param items the source Observable - * @param count the number of items from the end of the sequence emitted by - * the source Observable to emit - * - * @return an Observable that only emits the last count items - * emitted by the source Observable - */ - public static Observable takeLast(final Observable items, final int count) { - return create(OperationTakeLast.takeLast(items, count)); - } - - /** - * Returns a specified number of contiguous values from the start of an - * observable sequence. - * - * @param items - * @param predicate a function to test each source element for a condition - * - * @return - */ - public static Observable takeWhile(final Observable items, Func1 predicate) { - return create(OperationTakeWhile.takeWhile(items, predicate)); - } - - /** - * Returns a specified number of contiguous values from the start of an - * observable sequence. - * - * @param items - * @param predicate a function to test each source element for a condition - * - * @return - */ - public static Observable takeWhile(final Observable items, Object predicate) { - final FuncN _f = Functions.from(predicate); - - return takeWhile(items, (T t) -> (Boolean) _f.call(t)); - } - - /** - * Returns values from an observable sequence as long as a specified - * condition is true, and then skips the remaining values. - * - * @param items - * @param predicate a function to test each element for a condition; the - * second parameter of the function represents the index of the source - * element; otherwise, false. - * - * @return - */ - public static Observable takeWhileWithIndex(final Observable items, Func2 predicate) { - return create(OperationTakeWhile.takeWhileWithIndex(items, predicate)); - } - - public static Observable takeWhileWithIndex(final Observable items, Object predicate) { - final FuncN _f = Functions.from(predicate); - - return create(OperationTakeWhile.takeWhileWithIndex(items, (T t, Integer integer) -> (Boolean) _f.call(t, integer))); - } - - /** - * Returns an Observable that emits a single item, a list composed of all - * the items emitted by the source Observable. - *

- * Normally, an Observable that returns multiple items will do so by calling - * its Observer's onNext function for each such item. You can - * change this behavior, instructing the Observable to compose a list of all - * of these multiple items and then to call the Observer's - * onNext function once, passing it the entire list, by calling - * the Observable object's toList method prior to calling its - * subscribe method. - *

- * - * - * @param that the source Observable - * - * @return an Observable that emits a single item: a List - * containing all of the items emitted by the source Observable - */ - public static Observable> toList(final Observable that) { - return create(OperationToObservableList.toObservableList(that)); - } - - /** - * Converts an observable sequence to an Iterable. - * - * @param that the source Observable - * - * @return Observable converted to Iterable. - */ - public static Iterable toIterable(final Observable that) { - - return new Iterable() { - @Override - public Iterator iterator() { - return getIterator(that); - } - }; - } - - /** - * Returns an iterator that iterates all values of the observable. - * - * @param that an observable sequence to get an iterator for. - * @param the type of source. - * - * @return the iterator that could be used to iterate over the elements of - * the observable. - */ - public static Iterator getIterator(Observable that) { - return OperatorToIterator.toIterator(that); - } - - /** - * Samples the next value (blocking without buffering) from in an observable - * sequence. - * - * @param items the source observable sequence. - * @param the type of observable. - * - * @return iterable that blocks upon each iteration until the next element - * in the observable source sequence becomes available. - */ - public static Iterable next(Observable items) { - return OperationNext.next(items); - } - - /** - * Samples the most recent value in an observable sequence. - * - * @param source the source observable sequence. - * @param the type of observable. - * @param initialValue the initial value that will be yielded by the - * enumerable sequence if no element has been sampled yet. - * - * @return the iterable that returns the last sampled element upon each - * iteration. - */ - public static Iterable mostRecent(Observable source, T initialValue) { - return OperationMostRecent.mostRecent(source, initialValue); - } - - /** - * Returns the only element of an observable sequence and throws an - * exception if there is not exactly one element in the observable sequence. - * - * @param that the source Observable - * - * @return The single element in the observable sequence. - * - * @throws IllegalStateException if there is not exactly one element in the - * observable sequence - */ - public static T single(Observable that) { - return singleOrDefault(that, false, null); - } - - /** - * Returns the only element of an observable sequence that matches the - * predicate and throws an exception if there is not exactly one element in - * the observable sequence. - * - * @param that the source Observable - * @param predicate A predicate function to evaluate for elements in the - * sequence. - * - * @return The single element in the observable sequence. - * - * @throws IllegalStateException if there is not exactly one element in the - * observable sequence that matches the predicate - */ - public static T single(Observable that, Func1 predicate) { - return single(that.filter(predicate)); - } - - /** - * Returns the only element of an observable sequence that matches the - * predicate and throws an exception if there is not exactly one element in - * the observable sequence. - * - * @param that the source Observable - * @param predicate A predicate function to evaluate for elements in the - * sequence. - * - * @return The single element in the observable sequence. - * - * @throws IllegalStateException if there is not exactly one element in the - * observable sequence that matches the predicate - */ - public static T single(Observable that, Object predicate) { - final FuncN _f = Functions.from(predicate); - - return single(that, (T t) -> (Boolean) _f.call(t)); - } - - /** - * Returns the only element of an observable sequence, or a default value if - * the observable sequence is empty. - * - * @param that the source Observable - * @param defaultValue default value for a sequence. - * - * @return The single element in the observable sequence, or a default value - * if no value is found. - */ - public static T singleOrDefault(Observable that, T defaultValue) { - return singleOrDefault(that, true, defaultValue); - } - - /** - * Returns the only element of an observable sequence that matches the - * predicate, or a default value if no value is found. - * - * @param that the source Observable - * @param defaultValue default value for a sequence. - * @param predicate A predicate function to evaluate for elements in the - * sequence. - * - * @return The single element in the observable sequence, or a default value - * if no value is found. - */ - public static T singleOrDefault(Observable that, T defaultValue, Func1 predicate) { - return singleOrDefault(that.filter(predicate), defaultValue); - } - - /** - * Returns the only element of an observable sequence that matches the - * predicate, or a default value if no value is found. - * - * @param that the source Observable - * @param defaultValue default value for a sequence. - * @param predicate A predicate function to evaluate for elements in the - * sequence. - * - * @return The single element in the observable sequence, or a default value - * if no value is found. - */ - public static T singleOrDefault(Observable that, T defaultValue, Object predicate) { - final FuncN _f = Functions.from(predicate); - - return singleOrDefault(that, defaultValue, (T t) -> (Boolean) _f.call(t)); - } - - private static T singleOrDefault(Observable that, boolean hasDefault, T defaultVal) { - Iterator it = that.toIterable().iterator(); - - if (!it.hasNext()) { - if (hasDefault) - return defaultVal; - throw new IllegalStateException("Expected single entry. Actually empty stream."); - } - - T result = it.next(); - - if (it.hasNext()) - throw new IllegalStateException("Expected single entry. Actually more than one entry."); - - return result; - } - - /** - * Converts an Iterable sequence to an Observable sequence. - *

- * Any object that supports the Iterable interface can be converted into an - * Observable that emits each iterable item in the object, by passing the - * object into the toObservable method. - *

- * - * - * @param iterable the source Iterable sequence - * @param the type of items in the iterable sequence and the type - * emitted by the resulting Observable - * - * @return an Observable that emits each item in the source Iterable - * sequence - */ - public static Observable toObservable(Iterable iterable) { - return create(OperationToObservableIterable.toObservableIterable(iterable)); - } - - /** - * Converts an Future to an Observable sequence. - *

- * Any object that supports the {@link Future} interface can be converted - * into an Observable that emits the return value of the get() method in the - * object, by passing the object into the toObservable method. - *

- * This is blocking so the Subscription returned when calling - * {@link #subscribe(Observer)} does nothing. - * - * @param future the source {@link Future} - * @param the type of of object that the future's returns and the - * type - * emitted by the resulting Observable - * - * @return an Observable that emits the item from the source Future - */ - public static Observable toObservable(Future future) { - return create(OperationToObservableFuture.toObservableFuture(future)); - } - - /** - * Converts an Future to an Observable sequence. - *

- * Any object that supports the {@link Future} interface can be converted - * into an Observable that emits the return value of the get() method in the - * object, by passing the object into the toObservable method. - * The subscribe method on this synchronously so the Subscription returned - * doesn't nothing. - *

- * This is blocking so the Subscription returned when calling - * {@link #subscribe(Observer)} does nothing. - * - * @param future the source {@link Future} - * @param timeout the maximum time to wait - * @param unit the time unit of the time argument - * @param the type of of object that the future's returns and the - * type - * emitted by the resulting Observable - * - * @return an Observable that emits the item from the source Future - */ - public static Observable toObservable(Future future, long timeout, TimeUnit unit) { - return create(OperationToObservableFuture.toObservableFuture(future, timeout, unit)); - } - - /** - * Converts an Array sequence to an Observable sequence. - *

- * An Array can be converted into an Observable that emits each item in the - * Array, by passing the Array into the toObservable method. - *

- * - * - * @param items the source Array - * @param the type of items in the Array, and the type of items - * emitted - * by the resulting Observable - * - * @return an Observable that emits each item in the source Array - */ - public static Observable toObservable(T... items) { - return toObservable(Arrays.asList(items)); - } - - /** - * Sort T objects by their natural order (object must implement Comparable). - *

- * - * - * @param sequence - * - * @throws ClassCastException if T objects do not implement Comparable - * @return - */ - public static Observable> toSortedList(Observable sequence) { - return create(OperationToObservableSortedList.toSortedList(sequence)); - } - - /** - * Sort T objects using the defined sort function. - *

- * - * - * @param sequence - * @param sortFunction - * - * @return - */ - public static Observable> toSortedList(Observable sequence, Func2 sortFunction) { - return create(OperationToObservableSortedList.toSortedList(sequence, sortFunction)); - } - - /** - * Sort T objects using the defined sort function. - *

- * - * - * @param sequence - * @param sortFunction - * - * @return - */ - public static Observable> toSortedList(Observable sequence, final Object sortFunction) { - final FuncN _f = Functions.from(sortFunction); - return create(OperationToObservableSortedList.toSortedList(sequence, (T t1, T t2) -> (Integer) _f.call(t1, t2))); - } - - /** - * Returns an Observable that applies a function of your choosing to the - * combination of items emitted, in sequence, by two other Observables, with - * the results of this function becoming the sequence emitted by the - * returned Observable. - *

- * zip applies this function in strict sequence, so the first - * item emitted by the new Observable will be the result of the function - * applied to the first item emitted by w0 and the first item - * emitted by w1; the second item emitted by the new Observable - * will be the result of the function applied to the second item emitted by - * w0 and the second item emitted by w1; and so - * forth. - *

- * The resulting Observable returned from zip - * will call onNext as many times as the number - * onNext calls of the source Observable with the shortest - * sequence. - *

- * - * - * @param w0 one source Observable - * @param w1 another source Observable - * @param reduceFunction a function that, when applied to an item emitted by - * each of the source Observables, results in a value that will be emitted - * by the resulting Observable - * - * @return an Observable that emits the zipped results - */ - public static Observable zip(Observable w0, Observable w1, Func2 reduceFunction) { - return create(OperationZip.zip(w0, w1, reduceFunction)); - } - - /** - * Determines whether two sequences are equal by comparing the elements - * pairwise. - * - * @param first observable to compare - * @param second observable to compare - * @param type of sequence - * - * @return sequence of booleans, true if two sequences are equal by - * comparing the elements pairwise; otherwise, false. - */ - public static Observable sequenceEqual(Observable first, Observable second) { - return sequenceEqual(first, second, Object::equals); - } - - /** - * Determines whether two sequences are equal by comparing the elements - * pairwise using a specified equality function. - * - * @param first observable sequence to compare - * @param second observable sequence to compare - * @param equality a function used to compare elements of both sequences - * @param type of sequence - * - * @return sequence of booleans, true if two sequences are equal by - * comparing the elements pairwise; otherwise, false. - */ - public static Observable sequenceEqual(Observable first, Observable second, Func2 equality) { - return zip(first, second, equality); - } - - /** - * Determines whether two sequences are equal by comparing the elements - * pairwise using a specified equality function. - * - * @param first observable sequence to compare - * @param second observable sequence to compare - * @param equality a function used to compare elements of both sequences - * @param type of sequence - * - * @return sequence of booleans, true if two sequences are equal by - * comparing the elements pairwise; otherwise, false. - */ - public static Observable sequenceEqual(Observable first, Observable second, Object equality) { - return zip(first, second, equality); - } - - /** - * Returns an Observable that applies a function of your choosing to the - * combination of items emitted, in sequence, by two other Observables, with - * the results of this function becoming the sequence emitted by the - * returned Observable. - *

- * zip applies this function in strict sequence, so the first - * item emitted by the new Observable will be the result of the function - * applied to the first item emitted by w0 and the first item - * emitted by w1; the second item emitted by the new Observable - * will be the result of the function applied to the second item emitted by - * w0 and the second item emitted by w1; and so - * forth. - *

- * The resulting Observable returned from zip - * will call onNext as many times as the number - * onNext calls of the source Observable with the shortest - * sequence. - *

- * - * - * @param w0 one source Observable - * @param w1 another source Observable - * @param function a function that, when applied to an item emitted by each - * of the source Observables, results in a value that will be emitted by the - * resulting Observable - * - * @return an Observable that emits the zipped results - */ - public static Observable zip(Observable w0, Observable w1, final Object function) { - final FuncN _f = Functions.from(function); - return zip(w0, w1, (T0 t0, T1 t1) -> (R) _f.call(t0, t1)); - } - - /** - * Returns an Observable that applies a function of your choosing to the - * combination of items emitted, in sequence, by three other Observables, - * with the results of this function becoming the sequence emitted by the - * returned Observable. - *

- * zip applies this function in strict sequence, so the first - * item emitted by the new Observable will be the result of the function - * applied to the first item emitted by w0, the first item - * emitted by w1, and the first item emitted by - * w2; the second item emitted by the new Observable will be - * the result of the function applied to the second item emitted by - * w0, the second item emitted by w1, and the - * second item emitted by w2; and so forth. - *

- * The resulting Observable returned from zip - * will call onNext as many times as the number - * onNext calls of the source Observable with the shortest - * sequence. - *

- * - * - * @param w0 one source Observable - * @param w1 another source Observable - * @param w2 a third source Observable - * @param function a function that, when applied to an item emitted by each - * of the source Observables, results in a value that will be emitted by the - * resulting Observable - * - * @return an Observable that emits the zipped results - */ - public static Observable zip(Observable w0, Observable w1, Observable w2, Func3 function) { - return create(OperationZip.zip(w0, w1, w2, function)); - } - - /** - * Returns an Observable that applies a function of your choosing to the - * combination of items emitted, in sequence, by three other Observables, - * with the results of this function becoming the sequence emitted by the - * returned Observable. - *

- * zip applies this function in strict sequence, so the first - * item emitted by the new Observable will be the result of the function - * applied to the first item emitted by w0, the first item - * emitted by w1, and the first item emitted by - * w2; the second item emitted by the new Observable will be - * the result of the function applied to the second item emitted by - * w0, the second item emitted by w1, and the - * second item emitted by w2; and so forth. - *

- * The resulting Observable returned from zip - * will call onNext as many times as the number - * onNext calls of the source Observable with the shortest - * sequence. - *

- * - * - * @param w0 one source Observable - * @param w1 another source Observable - * @param w2 a third source Observable - * @param function a function that, when applied to an item emitted by each - * of the source Observables, results in a value that will be emitted by the - * resulting Observable - * - * @return an Observable that emits the zipped results - */ - public static Observable zip(Observable w0, Observable w1, Observable w2, final Object function) { - final FuncN _f = Functions.from(function); - return zip(w0, w1, w2, (T0 t0, T1 t1, T2 t2) -> (R) _f.call(t0, t1, t2)); - } - - /** - * Returns an Observable that applies a function of your choosing to the - * combination of items emitted, in sequence, by four other Observables, - * with the results of this function becoming the sequence emitted by the - * returned Observable. - *

- * zip applies this function in strict sequence, so the first - * item emitted by the new Observable will be the result of the function - * applied to the first item emitted by w0, the first item - * emitted by w1, the first item emitted by w2, - * and the first item emitted by w3; the second item emitted by - * the new Observable will be the result of the function applied to the - * second item emitted by each of those Observables; and so forth. - *

- * The resulting Observable returned from zip - * will call onNext as many times as the number - * onNext calls of the source Observable with the shortest - * sequence. - *

- * - * - * @param w0 one source Observable - * @param w1 another source Observable - * @param w2 a third source Observable - * @param w3 a fourth source Observable - * @param reduceFunction a function that, when applied to an item emitted by - * each of the source Observables, results in a value that will be emitted - * by the resulting Observable - * - * @return an Observable that emits the zipped results - */ - public static Observable zip(Observable w0, Observable w1, Observable w2, Observable w3, Func4 reduceFunction) { - return create(OperationZip.zip(w0, w1, w2, w3, reduceFunction)); - } - - /** - * Returns an Observable that applies a function of your choosing to the - * combination of items emitted, in sequence, by four other Observables, - * with the results of this function becoming the sequence emitted by the - * returned Observable. - *

- * zip applies this function in strict sequence, so the first - * item emitted by the new Observable will be the result of the function - * applied to the first item emitted by w0, the first item - * emitted by w1, the first item emitted by w2, - * and the first item emitted by w3; the second item emitted by - * the new Observable will be the result of the function applied to the - * second item emitted by each of those Observables; and so forth. - *

- * The resulting Observable returned from zip - * will call onNext as many times as the number - * onNext calls of the source Observable with the shortest - * sequence. - *

- * - * - * @param w0 one source Observable - * @param w1 another source Observable - * @param w2 a third source Observable - * @param w3 a fourth source Observable - * @param function a function that, when applied to an item emitted by each - * of the source Observables, results in a value that will be emitted by the - * resulting Observable - * - * @return an Observable that emits the zipped results - */ - public static Observable zip(Observable w0, Observable w1, Observable w2, Observable w3, final Object function) { - final FuncN _f = Functions.from(function); - return zip(w0, w1, w2, w3, (T0 t0, T1 t1, T2 t2, T3 t3) -> (R) _f.call(t0, t1, t2, t3)); - } - - /** - * Filters an Observable by discarding any of its emissions that do not meet - * some test. - *

- * - * - * @param predicate a function that evaluates the items emitted by the - * source Observable, returning true if they pass the filter - * - * @return an Observable that emits only those items in the original - * Observable that the filter evaluates as true - */ - public Observable filter(Func1 predicate) { - return filter(this, predicate); - } - - /** - * Registers an action to be called when this observable calls - * onComplete or onError. - * - * @param action an action to be called when this observable completes or - * errors. - * - * @return an Observable that emits the same objects as this observable, - * then calls the action. - * - * @see - * MSDN: - * Observable.Finally Method - */ - public Observable finallyDo(Action0 action) { - return create(OperationFinally.finallyDo(this, action)); - } - - /** - * Filters an Observable by discarding any of its emissions that do not meet - * some test. - *

- * - * - * @param callback a function that evaluates the items emitted by the source - * Observable, returning true if they pass the filter - * - * @return an Observable that emits only those items in the original - * Observable that the filter evaluates as "true" - */ - public Observable filter(final Object callback) { - final FuncN _f = Functions.from(callback); - return filter(this, (T t1) -> (Boolean) _f.call(t1)); - } - - /** - * Filters an Observable by discarding any of its emissions that do not meet - * some test. - *

- * - * - * @param predicate a function that evaluates the items emitted by the - * source Observable, returning true if they pass the filter - * - * @return an Observable that emits only those items in the original - * Observable that the filter evaluates as true - */ - public Observable where(Func1 predicate) { - return where(this, predicate); - } - - public final Observable flatMap(Func1> func) { - return merge(map(func)); - } - - /** - * Returns the last element of an observable sequence with a specified - * source. - * - * @return the last element in the observable sequence. - */ - public T last() { - return last(this); - } - - /** - * Returns the last element of an observable sequence that matches the - * predicate. - * - * @param predicate a predicate function to evaluate for elements in the - * sequence. - * - * @return the last element in the observable sequence. - */ - public T last(final Func1 predicate) { - return last(this, predicate); - } - - /** - * Returns the last element of an observable sequence that matches the - * predicate. - * - * @param predicate a predicate function to evaluate for elements in the - * sequence. - * - * @return the last element in the observable sequence. - */ - public T last(final Object predicate) { - final FuncN _f = Functions.from(predicate); - - return last(this, (T args) -> (Boolean) _f.call(args)); - } - - /** - * Returns the last element, or a default value if no value is found. - * - * @param defaultValue a default value that would be returned if observable - * is empty. - * - * @return the last element of an observable sequence that matches the - * predicate, or a default value if no value is found. - */ - public T lastOrDefault(T defaultValue) { - return lastOrDefault(this, defaultValue); - } - - /** - * Returns the last element that matches the predicate, or a default value - * if no value is found. - * - * @param defaultValue a default value that would be returned if observable - * is empty. - * @param predicate a predicate function to evaluate for elements in the - * sequence. - * - * @return the last element of an observable sequence that matches the - * predicate, or a default value if no value is found. - */ - public T lastOrDefault(T defaultValue, Func1 predicate) { - return lastOrDefault(this, defaultValue, predicate); - } - - /** - * Returns the last element that matches the predicate, or a default value - * if no value is found. - * - * @param defaultValue a default value that would be returned if observable - * is empty. - * @param predicate a predicate function to evaluate for elements in the - * sequence. - * - * @return the last element of an observable sequence that matches the - * predicate, or a default value if no value is found. - */ - public T lastOrDefault(T defaultValue, Object predicate) { - return lastOrDefault(this, defaultValue, predicate); - } - - /** - * Applies a function of your choosing to every item emitted by an - * Observable, and returns this transformation as a new Observable sequence. - *

- * - * - * @param func a function to apply to each item in the sequence. - * - * @return an Observable that emits a sequence that is the result of - * applying the transformation function to each item in the sequence emitted - * by the input Observable. - */ - public Observable map(Func1 func) { - return map(this, func); - } - - /** - * Applies a function of your choosing to every item emitted by an - * Observable, and returns this transformation as a new Observable sequence. - *

- * - * - * @param callback a function to apply to each item in the sequence. - * - * @return an Observable that emits a sequence that is the result of - * applying the transformation function to each item in the sequence emitted - * by the input Observable. - */ - public Observable map(final Object callback) { - final FuncN _f = Functions.from(callback); - return map(this, (T t1) -> (R) _f.call(t1)); - } - - /** - * Creates a new Observable sequence by applying a function that you supply - * to each item in the original Observable sequence, where that function is - * itself an Observable that emits items, and then merges the results of - * that function applied to every item emitted by the original Observable, - * emitting these merged results as its own sequence. - *

- * - * - * @param func a function to apply to each item in the sequence, that - * returns an Observable. - * - * @return an Observable that emits a sequence that is the result of - * applying the transformation function to each item in the input sequence - * and merging the results of the Observables obtained from this - * transformation. - */ - public Observable mapMany(Func1> func) { - return mapMany(this, func); - } - - /** - * Creates a new Observable sequence by applying a function that you supply - * to each item in the original Observable sequence, where that function is - * itself an Observable that emits items, and then merges the results of - * that function applied to every item emitted by the original Observable, - * emitting these merged results as its own sequence. - *

- * - * - * @param callback a function to apply to each item in the sequence that - * returns an Observable. - * - * @return an Observable that emits a sequence that is the result of - * applying the transformation' function to each item in the input sequence - * and merging the results of the Observables obtained from this - * transformation. - */ - public Observable mapMany(final Object callback) { - final FuncN _f = Functions.from(callback); - return mapMany(this, (T t1) -> (Observable) _f.call(t1)); - } - - /** - * Materializes the implicit notifications of this observable sequence as - * explicit notification values. - *

- * - * - * @return An observable sequence whose elements are the result of - * materializing the notifications of the given sequence. - * - * @see - * MSDN: - * Observable.materialize - */ - public Observable> materialize() { - return materialize(this); - } - - /** - * Asynchronously subscribes and unsubscribes observers on the specified - * scheduler. - * - * @param scheduler the scheduler to perform subscription and unsubscription - * actions on. - * - * @return the source sequence whose subscriptions and unsubscriptions - * happen on the specified scheduler. - */ - public Observable subscribeOn(Scheduler scheduler) { - return subscribeOn(this, scheduler); - } - - /** - * Asynchronously notify observers on the specified scheduler. - * - * @param scheduler the scheduler to notify observers on. - * - * @return the source sequence whose observations happen on the specified - * scheduler. - */ - public Observable observeOn(Scheduler scheduler) { - return observeOn(this, scheduler); - } - - /** - * Dematerializes the explicit notification values of an observable sequence - * as implicit notifications. - * - * @return An observable sequence exhibiting the behavior corresponding to - * the source sequence's notification values. - * - * @see - * MSDN: - * Observable.dematerialize - * @throws Exception if attempted on Observable not of type - * {@code Observable>}. - */ - public Observable dematerialize() { - return dematerialize((Observable>) this); - } - - /** - * Instruct an Observable to pass control to another Observable rather than - * calling onError if it encounters an error. - *

- * By default, when an Observable encounters an error that prevents it from - * emitting the expected item to its Observer, the Observable calls its - * Observer's onError function, and then quits without calling - * any more of its Observer's closures. The onErrorResumeNext - * method changes this behavior. If you pass another Observable - * (resumeFunction) to an Observable's - * onErrorResumeNext method, if the original Observable - * encounters an error, instead of calling its Observer's - * onErrort function, it will instead relinquish control to - * resumeFunction which will call the Observer's - * onNext method if it is able to do so. In such a case, - * because no Observable necessarily invokes onError, the - * Observer may never know that an error happened. - *

- * You can use this to prevent errors from propagating or to supply fallback - * data should errors be encountered. - *

- * - * - * @param resumeFunction - * - * @return the original Observable, with appropriately modified behavior - */ - public Observable onErrorResumeNext(final Func1> resumeFunction) { - return onErrorResumeNext(this, resumeFunction); - } - - /** - * Instruct an Observable to emit a particular item rather than calling - * onError if it encounters an error. - *

- * By default, when an Observable encounters an error that prevents it from - * emitting the expected item to its Observer, the Observable calls its - * Observer's onError function, and then quits without calling - * any more of its Observer's closures. The onErrorResumeNext - * method changes this behavior. If you pass another Observable - * (resumeFunction) to an Observable's - * onErrorResumeNext method, if the original Observable - * encounters an error, instead of calling its Observer's - * onError function, it will instead relinquish control to - * resumeFunction which will call the Observer's - * onNext method if it is able to do so. In such a case, - * because no Observable necessarily invokes onError, the - * Observer may never know that an error happened. - *

- * You can use this to prevent errors from propagating or to supply fallback - * data should errors be encountered. - *

- * - * - * @param resumeFunction - * - * @return the original Observable with appropriately modified behavior - */ - public Observable onErrorResumeNext(final Object resumeFunction) { - final FuncN _f = Functions.from(resumeFunction); - return onErrorResumeNext(this, (Exception e) -> (Observable) _f.call(e)); - } - - /** - * Instruct an Observable to pass control to another Observable rather than - * calling onError if it encounters an error. - *

- * By default, when an Observable encounters an error that prevents it from - * emitting the expected item to its Observer, the Observable calls its - * Observer's onError function, and then quits without calling - * any more of its Observer's closures. The onErrorResumeNext - * method changes this behavior. If you pass another Observable - * (resumeSequence) to an Observable's - * onErrorResumeNext method, if the original Observable - * encounters an error, instead of calling its Observer's - * onError function, it will instead relinquish control to - * resumeSequence which will call the Observer's - * onNext method if it is able to do so. In such a case, - * because no Observable necessarily invokes onError, the - * Observer may never know that an error happened. - *

- * You can use this to prevent errors from propagating or to supply fallback - * data should errors be encountered. - *

- * - * - * @param resumeSequence - * - * @return the original Observable, with appropriately modified behavior - */ - public Observable onErrorResumeNext(final Observable resumeSequence) { - return onErrorResumeNext(this, resumeSequence); - } - - /** - * Instruct an Observable to emit a particular item rather than calling - * onError if it encounters an error. - *

- * By default, when an Observable encounters an error that prevents it from - * emitting the expected object to its Observer, the Observable calls its - * Observer's onError function, and then quits without calling - * any more of its Observer's closures. The onErrorReturn - * method changes this behavior. If you pass a function - * (resumeFunction) to an Observable's - * onErrorReturn method, if the original Observable encounters - * an error, instead of calling its Observer's onError - * function, it will instead call pass the return value of - * resumeFunction to the Observer's onNext method. - *

- * You can use this to prevent errors from propagating or to supply fallback - * data should errors be encountered. - * - * @param resumeFunction - * - * @return the original Observable with appropriately modified behavior - */ - public Observable onErrorReturn(Func1 resumeFunction) { - return onErrorReturn(this, resumeFunction); - } - - /** - * Instruct an Observable to emit a particular item rather than calling - * onError if it encounters an error. - *

- * By default, when an Observable encounters an error that prevents it from - * emitting the expected object to its Observer, the Observable calls its - * Observer's onError function, and then quits without calling - * any more of its Observer's closures. The onErrorReturn - * method changes this behavior. If you pass a function - * (resumeFunction) to an Observable's - * onErrorReturn method, if the original Observable encounters - * an error, instead of calling its Observer's onError - * function, it will instead call pass the return value of - * resumeFunction to the Observer's onNext method. - *

- * You can use this to prevent errors from propagating or to supply fallback - * data should errors be encountered. - * - * @param resumeFunction - * - * @return the original Observable with appropriately modified behavior - */ - public Observable onErrorReturn(final Object resumeFunction) { - final FuncN _f = Functions.from(resumeFunction); - return onErrorReturn(this, (Exception e) -> (T) _f.call(e)); - } - - /** - * Returns an Observable that applies a function of your choosing to the - * first item emitted by a source Observable, then feeds the result of that - * function along with the second item emitted by an Observable into the - * same function, and so on until all items have been emitted by the source - * Observable, emitting the final result from the final call to your - * function as its sole output. - *

- * This technique, which is called "reduce" here, is sometimes called - * "fold," "accumulate," "compress," or "inject" in other programming - * contexts. Groovy, for instance, has an inject method that - * does a similar operation on lists. - *

- * - * - * @param accumulator An accumulator function to be invoked on each element - * from the sequence, whose result will be used in the next accumulator call - * (if applicable). - * - * @return An observable sequence with a single element from the result of - * accumulating the output from the list of Observables. - * - * @see - * MSDN: - * Observable.Aggregate - * @see - * Wikipedia: - * Fold (higher-order function) - */ - public Observable reduce(Func2 accumulator) { - return reduce(this, accumulator); - } - - /** - * Returns an Observable that applies a function of your choosing to the - * first item emitted by a source Observable, then feeds the result of that - * function along with the second item emitted by an Observable into the - * same function, and so on until all items have been emitted by the source - * Observable, emitting the final result from the final call to your - * function as its sole output. - *

- * This technique, which is called "reduce" here, is sometimes called - * "fold," "accumulate," "compress," or "inject" in other programming - * contexts. Groovy, for instance, has an inject method that - * does a similar operation on lists. - *

- * - * - * @param accumulator An accumulator function to be invoked on each element - * from the sequence, whose result will be used in the next accumulator call - * (if applicable). - * - * @return an Observable that emits a single element from the result of - * accumulating the output from the list of Observables. - * - * @see - * MSDN: - * Observable.Aggregate - * @see - * Wikipedia: - * Fold (higher-order function) - */ - public Observable reduce(Object accumulator) { - return reduce(this, accumulator); - } - - /** - * Returns an Observable that applies a function of your choosing to the - * first item emitted by a source Observable, then feeds the result of that - * function along with the second item emitted by an Observable into the - * same function, and so on until all items have been emitted by the source - * Observable, emitting the final result from the final call to your - * function as its sole output. - *

- * This technique, which is called "reduce" here, is sometimes called - * "fold," "accumulate," "compress," or "inject" in other programming - * contexts. Groovy, for instance, has an inject method that - * does a similar operation on lists. - *

- * - * - * @param initialValue The initial (seed) accumulator value. - * @param accumulator An accumulator function to be invoked on each element - * from the sequence, whose result will be used in the next accumulator call - * (if applicable). - * - * @return an Observable that emits a single element from the result of - * accumulating the output from the list of Observables. - * - * @see - * MSDN: - * Observable.Aggregate - * @see - * Wikipedia: - * Fold (higher-order function) - */ - public Observable reduce(T initialValue, Func2 accumulator) { - return reduce(this, initialValue, accumulator); - } - - /** - * Returns an Observable that applies a function of your choosing to the - * first item emitted by a source Observable, then feeds the result of that - * function along with the second item emitted by an Observable into the - * same function, and so on until all items have been emitted by the source - * Observable, emitting the final result from the final call to your - * function as its sole output. - *

- * This technique, which is called "reduce" here, is sometimes called - * "fold," "accumulate," "compress," or "inject" in other programming - * contexts. Groovy, for instance, has an inject method that - * does a similar operation on lists. - *

- * - * - * @param initialValue The initial (seed) accumulator value. - * @param accumulator An accumulator function to be invoked on each element - * from the sequence, whose result will be used in the next accumulator call - * (if applicable). - * - * @return an Observable that emits a single element from the result of - * accumulating the output from the list of Observables. - * - * @see - * MSDN: - * Observable.Aggregate - * @see - * Wikipedia: - * Fold (higher-order function) - */ - public Observable reduce(T initialValue, Object accumulator) { - return reduce(this, initialValue, accumulator); - } - - /** - * Returns an Observable that applies a function of your choosing to the - * first item emitted by a source Observable, then feeds the result of that - * function along with the second item emitted by an Observable into the - * same function, and so on until all items have been emitted by the source - * Observable, emitting the result of each of these iterations. It emits the - * result of each of these iterations as a sequence from the returned - * Observable. This sort of function is sometimes called an accumulator. - *

- * - * - * @param accumulator An accumulator function to be invoked on each element - * from the sequence whose result will be sent via onNext and - * used in the next accumulator call (if applicable). - * - * @return an Observable sequence whose elements are the result of - * accumulating the output from the list of Observables. - * - * @see - * MSDN: - * Observable.Scan - */ - public Observable scan(Func2 accumulator) { - return scan(this, accumulator); - } - - /** - * Returns an Observable that applies a function of your choosing to the - * first item emitted by a source Observable, then feeds the result of that - * function along with the second item emitted by an Observable into the - * same function, and so on until all items have been emitted by the source - * Observable, emitting the result of each of these iterations. It emits the - * result of each of these iterations as a sequence from the returned - * Observable. This sort of function is sometimes called an accumulator. - *

- * - * - * @param accumulator An accumulator function to be invoked on each element - * from the sequence whose result will be sent via onNext and - * used in the next accumulator call (if applicable). - * - * @return an Observable sequence whose elements are the result of - * accumulating the output from the list of Observables. - * - * @see - * MSDN: - * Observable.Scan - */ - public Observable scan(final Object accumulator) { - return scan(this, accumulator); - } - - /** - * Returns an Observable that applies a function of your choosing to the - * first item emitted by a source Observable, then feeds the result of that - * function along with the second item emitted by an Observable into the - * same function, and so on until all items have been emitted by the source - * Observable, emitting the result of each of these iterations. This sort of - * function is sometimes called an accumulator. - *

- * - * - * @param initialValue The initial (seed) accumulator value. - * @param accumulator An accumulator function to be invoked on each element - * from the sequence whose result will be sent via onNext and - * used in the next accumulator call (if applicable). - * - * @return an Observable sequence whose elements are the result of - * accumulating the output from the list of Observables. - * - * @see - * MSDN: - * Observable.Scan - */ - public Observable scan(T initialValue, Func2 accumulator) { - return scan(this, initialValue, accumulator); - } - - /** - * Returns an Observable that applies a function of your choosing to the - * first item emitted by a source Observable, then feeds the result of that - * function along with the second item emitted by an Observable into the - * same function, then feeds the result of that function along with the - * third item into the same function, and so on, emitting the result of each - * of these iterations. This sort of function is sometimes called an - * accumulator. - *

- * - * - * @param initialValue The initial (seed) accumulator value. - * @param accumulator An accumulator function to be invoked on each element - * from the sequence whose result will be sent via onNext and - * used in the next accumulator call (if applicable). - * - * @return an Observable sequence whose elements are the result of - * accumulating the output from the list of Observables. - * - * @see - * MSDN: - * Observable.Scan - */ - public Observable scan(final T initialValue, final Object accumulator) { - return scan(this, initialValue, accumulator); - } - - /** - * Determines whether all elements of an observable sequence satisfies a - * condition. - * - * @param predicate a function to test each element for a condition. - * - * @return true if all elements of an observable sequence satisfies a - * condition; otherwise, false. - */ - public Observable all(Func1 predicate) { - return all(this, predicate); - } - - /** - * Determines whether all elements of an observable sequence satisfies a - * condition. - * - * @param predicate a function to test each element for a condition. - * - * @return true if all elements of an observable sequence satisfies a - * condition; otherwise, false. - */ - public Observable all(Object predicate) { - return all(this, predicate); - } - - /** - * Returns an Observable that skips the first num items emitted - * by the source Observable. You can ignore the first num items - * emitted by an Observable and attend only to those items that come after, - * by modifying the Observable with the skip method. - *

- * - * - * @param num The number of items to skip - * - * @return an Observable sequence that is identical to the source Observable - * except that it does not emit the first num items from that - * sequence. - */ - public Observable skip(int num) { - return skip(this, num); - } - - /** - * Returns an Observable that emits the first num items emitted - * by the source Observable. - *

- * You can choose to pay attention only to the first num values - * emitted by a Observable by calling its take method. This - * method returns an Observable that will call a subscribing Observer's - * onNext function a maximum of num times before - * calling onCompleted. - *

- * - * - * @param num - * - * @return an Observable that emits only the first num items - * from the source Observable, or all of the items from the source - * Observable if that Observable emits fewer than num items. - */ - public Observable take(final int num) { - return take(this, num); - } - - /** - * Returns an Observable that items emitted by the source Observable as long - * as a specified condition is true. - * - * @param predicate a function to test each source element for a condition - * - * @return - */ - public Observable takeWhile(final Func1 predicate) { - return takeWhile(this, predicate); - } - - /** - * Returns a specified number of contiguous values from the start of an - * observable sequence. - * - * @param predicate a function to test each source element for a condition - * - * @return - */ - public Observable takeWhile(final Object predicate) { - return takeWhile(this, predicate); - } - - /** - * Returns values from an observable sequence as long as a specified - * condition is true, and then skips the remaining values. - * - * @param predicate a function to test each element for a condition; the - * second parameter of the function represents the index of the source - * element; otherwise, false. - * - * @return - */ - public Observable takeWhileWithIndex(final Func2 predicate) { - return takeWhileWithIndex(this, predicate); - } - - /** - * Returns values from an observable sequence as long as a specified - * condition is true, and then skips the remaining values. - * - * @param predicate a function to test each element for a condition; the - * second parameter of the function represents the index of the source - * element; otherwise, false. - * - * @return - */ - public Observable takeWhileWithIndex(final Object predicate) { - return takeWhileWithIndex(this, predicate); - } - - /** - * Returns an Observable that emits the last count items - * emitted by the source Observable. - * - * @param count the number of items from the end of the sequence emitted by - * the source Observable to emit - * - * @return an Observable that only emits the last count items - * emitted by the source Observable - */ - public Observable takeLast(final int count) { - return takeLast(this, count); - } - - /** - * Returns the values from the source observable sequence until the other - * observable sequence produces a value. - * - * @param other the observable sequence that terminates propagation of - * elements of the source sequence. - * @param the other type. - * - * @return An observable sequence containing the elements of the source - * sequence up to the point the other sequence interrupted further - * propagation. - */ - public Observable takeUntil(Observable other) { - return takeUntil(this, other); - } - - /** - * Returns an Observable that emits a single item, a list composed of all - * the items emitted by the source Observable. - *

- * Normally, an Observable that returns multiple items will do so by calling - * its Observer's onNext function for each such item. You can - * change this behavior, instructing the Observable to compose a list of all - * of these multiple items and then to call the Observer's - * onNext function once, passing it the entire list, by calling - * the Observable object's toList method prior to calling its - * subscribe method. - *

- * - * - * @return an Observable that emits a single item: a List containing all of - * the items emitted by the source Observable. - */ - public Observable> toList() { - return toList(this); - } - - /** - * Sort T objects by their natural order (object must implement Comparable). - *

- * - * - * @throws ClassCastException if T objects do not implement Comparable - * @return - */ - public Observable> toSortedList() { - return toSortedList(this); - } - - /** - * Sort T objects using the defined sort function. - *

- * - * - * @param sortFunction - * - * @return - */ - public Observable> toSortedList(Func2 sortFunction) { - return toSortedList(this, sortFunction); - } - - /** - * Sort T objects using the defined sort function. - *

- * - * - * @param sortFunction - * - * @return - */ - public Observable> toSortedList(final Object sortFunction) { - return toSortedList(this, sortFunction); - } - - /** - * Converts an observable sequence to an Iterable. - * - * @return Observable converted to Iterable. - */ - public Iterable toIterable() { - return toIterable(this); - } - - @SuppressWarnings("unchecked") - public Observable startWith(T... values) { - return concat(Observable.from(values), this); - } - - /** - * Groups the elements of an observable and selects the resulting elements - * by using a specified function. - * - * @param keySelector a function to extract the key for each element. - * @param elementSelector a function to map each source element to an - * element in an observable group. - * @param the key type. - * @param the resulting observable type. - * - * @return an observable of observable groups, each of which corresponds to - * a unique key value, containing all elements that share that same key - * value. - */ - public Observable> groupBy(final Func1 keySelector, final Func1 elementSelector) { - return groupBy(this, keySelector, elementSelector); - } - - /** - * Groups the elements of an observable according to a specified key - * selector function and - * - * @param keySelector a function to extract the key for each element. - * @param the key type. - * - * @return an observable of observable groups, each of which corresponds to - * a unique key value, containing all elements that share that same key - * value. - */ - public Observable> groupBy(final Func1 keySelector) { - return groupBy(this, keySelector); - } - - /** - * Returns an iterator that iterates all values of the observable. - * - * @return the iterator that could be used to iterate over the elements of - * the observable. - */ - public Iterator getIterator() { - return getIterator(this); - } - - /** - * Samples the next value (blocking without buffering) from in an observable - * sequence. - * - * @return iterable that blocks upon each iteration until the next element - * in the observable source sequence becomes available. - */ - public Iterable next() { - return next(this); - } - - /** - * Samples the most recent value in an observable sequence. - * - * @param initialValue the initial value that will be yielded by the - * enumerable sequence if no element has been sampled yet. - * - * @return the iterable that returns the last sampled element upon each - * iteration. - */ - public Iterable mostRecent(T initialValue) { - return mostRecent(this, initialValue); - } - - /** - * Whether a given {@link Function} is an internal implementation inside - * rx.* packages or not. - *

- * For why this is being used see - * https://github.com/Netflix/RxJava/issues/216 for discussion on "Guideline - * 6.4: Protect calls to user code from within an operator" - *

- * NOTE: If strong reasons for not depending on package names comes up then - * the implementation of this method can change to looking for a marker - * interface. - * - * @param f - * - * @return - */ - private boolean isInternalImplementation(Object o) { - if (o == null) - return true; - // prevent double-wrapping (yeah it happens) - if (o instanceof AtomicObserver) - return true; - // we treat the following package as "internal" and don't wrap it - return o.getClass().getPackage().getName().startsWith("rx.operators"); - } - -} diff --git a/HMCLAPI/src/main/java/rx/Observer.java b/HMCLAPI/src/main/java/rx/Observer.java deleted file mode 100755 index a8e688ec4..000000000 --- a/HMCLAPI/src/main/java/rx/Observer.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx; - -/** - * Provides a mechanism for receiving push-based notifications. - *

- * After an Observer calls an {@link Observable}'s - * Observable.subscribe method, the {@link Observable} calls the - * Observer's onNext method to provide notifications. A - * well-behaved {@link Observable} will call an Observer's - * onCompleted closure exactly once or the Observer's - * onError closure exactly once. - *

- * For more information see the - * RxJava Wiki - * - * @param - */ -public interface Observer { - - /** - * Notifies the Observer that the {@link Observable} has finished sending - * push-based notifications. - *

- * The {@link Observable} will not call this closure if it calls - * onError. - */ - public void onCompleted(); - - /** - * Notifies the Observer that the {@link Observable} has experienced an - * error condition. - *

- * If the {@link Observable} calls this closure, it will not thereafter call - * onNext or onCompleted. - * - * @param e - */ - public void onError(Exception e); - - /** - * Provides the Observer with new data. - *

- * The {@link Observable} calls this closure 1 or more times, unless it - * calls onError in which case this closure may never be - * called. - *

- * The {@link Observable} will not call this closure again after it calls - * either onCompleted or onError. - * - * @param args - */ - public void onNext(T args); -} diff --git a/HMCLAPI/src/main/java/rx/Scheduler.java b/HMCLAPI/src/main/java/rx/Scheduler.java deleted file mode 100755 index 6d455c060..000000000 --- a/HMCLAPI/src/main/java/rx/Scheduler.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx; - -import java.util.concurrent.TimeUnit; - -import rx.util.functions.Action0; -import rx.util.functions.Func0; - -/** - * Represents an object that schedules units of work. - */ -public interface Scheduler { - - /** - * Schedules a cancelable action to be executed. - * - * @param action action - * - * @return a subscription to be able to unsubscribe from action. - */ - Subscription schedule(Func0 action); - - /** - * Schedules an action to be executed. - * - * @param action action - * - * @return a subscription to be able to unsubscribe from action. - */ - Subscription schedule(Action0 action); - - /** - * Schedules an action to be executed in dueTime. - * - * @param action action - * - * @return a subscription to be able to unsubscribe from action. - */ - Subscription schedule(Action0 action, long dueTime, TimeUnit unit); - - /** - * Schedules a cancelable action to be executed in dueTime. - * - * @param action action - * - * @return a subscription to be able to unsubscribe from action. - */ - Subscription schedule(Func0 action, long dueTime, TimeUnit unit); - - /** - * Returns the scheduler's notion of current time. - */ - long now(); - -} diff --git a/HMCLAPI/src/main/java/rx/Subscription.java b/HMCLAPI/src/main/java/rx/Subscription.java deleted file mode 100755 index 0ee662126..000000000 --- a/HMCLAPI/src/main/java/rx/Subscription.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx; - -import rx.subscriptions.Subscriptions; - -/** - * Subscription returns from {@link Observable#subscribe(Observer)} to allow - * unsubscribing. - *

- * See utilities in {@link Subscriptions} and implementations in the - * {@link rx.subscriptions} package. - */ -public interface Subscription { - - /** - * Stop receiving notifications on the {@link Observer} that was registered - * when this Subscription was received. - *

- * This allows unregistering an {@link Observer} before it has finished - * receiving all events (ie. before onCompleted is called). - */ - public void unsubscribe(); - -} diff --git a/HMCLAPI/src/main/java/rx/concurrency/AbstractScheduler.java b/HMCLAPI/src/main/java/rx/concurrency/AbstractScheduler.java deleted file mode 100755 index 2800f672c..000000000 --- a/HMCLAPI/src/main/java/rx/concurrency/AbstractScheduler.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.concurrency; - -import java.util.concurrent.TimeUnit; - -import rx.Scheduler; -import rx.Subscription; -import rx.subscriptions.Subscriptions; -import rx.util.functions.Action0; -import rx.util.functions.Func0; - -/* - * package - */ -abstract class AbstractScheduler implements Scheduler { - - @Override - public Subscription schedule(Action0 action) { - return schedule(asFunc0(action)); - } - - @Override - public Subscription schedule(Action0 action, long dueTime, TimeUnit unit) { - return schedule(asFunc0(action), dueTime, unit); - } - - @Override - public long now() { - return System.nanoTime(); - } - - private static Func0 asFunc0(final Action0 action) { - return () -> { - action.call(); - return Subscriptions.empty(); - }; - } - -} diff --git a/HMCLAPI/src/main/java/rx/concurrency/CurrentThreadScheduler.java b/HMCLAPI/src/main/java/rx/concurrency/CurrentThreadScheduler.java deleted file mode 100755 index d9ac2c8a9..000000000 --- a/HMCLAPI/src/main/java/rx/concurrency/CurrentThreadScheduler.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.concurrency; - -import java.util.LinkedList; -import java.util.Queue; -import java.util.concurrent.TimeUnit; - -import rx.Subscription; -import rx.util.functions.Func0; - -/** - * Schedules work on the current thread but does not execute immediately. Work - * is put in a queue and executed after the current unit of work is completed. - */ -public class CurrentThreadScheduler extends AbstractScheduler { - - private static final CurrentThreadScheduler INSTANCE = new CurrentThreadScheduler(); - - public static CurrentThreadScheduler getInstance() { - return INSTANCE; - } - - private static final ThreadLocal> QUEUE = new ThreadLocal<>(); - - private CurrentThreadScheduler() { - } - - @Override - public Subscription schedule(Func0 action) { - DiscardableAction discardableAction = new DiscardableAction(action); - enqueue(discardableAction); - return discardableAction; - } - - @Override - public Subscription schedule(Func0 action, long dueTime, TimeUnit unit) { - return schedule(new SleepingAction(action, this, dueTime, unit)); - } - - private void enqueue(DiscardableAction action) { - Queue queue = QUEUE.get(); - boolean exec = queue == null; - - if (exec) { - queue = new LinkedList<>(); - QUEUE.set(queue); - } - - queue.add(action); - - if (exec) { - while (!queue.isEmpty()) - queue.poll().call(); - - QUEUE.set(null); - } - } -} diff --git a/HMCLAPI/src/main/java/rx/concurrency/DiscardableAction.java b/HMCLAPI/src/main/java/rx/concurrency/DiscardableAction.java deleted file mode 100755 index 416eeacf1..000000000 --- a/HMCLAPI/src/main/java/rx/concurrency/DiscardableAction.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.concurrency; - -import java.util.concurrent.atomic.AtomicBoolean; - -import rx.Subscription; -import rx.util.AtomicObservableSubscription; -import rx.util.functions.Func0; - -/** - * Combines standard {@link Subscription#unsubscribe()} functionality with - * ability to skip execution if an unsubscribe occurs before the {@link #call()} - * method is invoked. - */ -/* - * package - */ -class DiscardableAction implements Func0, Subscription { - - private final Func0 underlying; - - private final AtomicObservableSubscription wrapper = new AtomicObservableSubscription(); - private final AtomicBoolean ready = new AtomicBoolean(true); - - public DiscardableAction(Func0 underlying) { - this.underlying = underlying; - } - - @Override - public Subscription call() { - if (ready.compareAndSet(true, false)) { - Subscription subscription = underlying.call(); - wrapper.wrap(subscription); - return subscription; - } - return wrapper; - } - - @Override - public void unsubscribe() { - ready.set(false); - wrapper.unsubscribe(); - } -} diff --git a/HMCLAPI/src/main/java/rx/concurrency/EventQueueScheduler.java b/HMCLAPI/src/main/java/rx/concurrency/EventQueueScheduler.java deleted file mode 100755 index 2d70ac138..000000000 --- a/HMCLAPI/src/main/java/rx/concurrency/EventQueueScheduler.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Hello Minecraft! Launcher. - * Copyright (C) 2013 huangyuhui - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see {http://www.gnu.org/licenses/}. - */ -package rx.concurrency; - -import java.awt.EventQueue; -import java.util.concurrent.TimeUnit; -import rx.Subscription; -import rx.util.functions.Func0; - -/** - * - * @author huangyuhui - */ -public class EventQueueScheduler extends AbstractScheduler { - - private static final EventQueueScheduler INSTANCE = new EventQueueScheduler(); - - public static EventQueueScheduler getInstance() { - return INSTANCE; - } - - @Override - public Subscription schedule(Func0 action) { - final DiscardableAction discardableAction = new DiscardableAction(action); - - EventQueue.invokeLater(discardableAction::call); - - return discardableAction; - } - - @Override - public Subscription schedule(Func0 action, long dueTime, TimeUnit unit) { - return schedule(new SleepingAction(action, this, dueTime, unit)); - } - -} diff --git a/HMCLAPI/src/main/java/rx/concurrency/ExecutorScheduler.java b/HMCLAPI/src/main/java/rx/concurrency/ExecutorScheduler.java deleted file mode 100755 index 610849360..000000000 --- a/HMCLAPI/src/main/java/rx/concurrency/ExecutorScheduler.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.concurrency; - -import java.util.concurrent.Executor; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -import rx.Scheduler; -import rx.Subscription; -import rx.util.functions.Func0; - -/** - * A {@link Scheduler} implementation that uses an {@link Executor} or - * {@link ScheduledExecutorService} implementation. - *

- * Note that if an {@link Executor} implementation is used instead of - * {@link ScheduledExecutorService} then a system-wide Timer will be used to - * handle delayed events. - */ -public class ExecutorScheduler extends AbstractScheduler { - - private final Executor executor; - - /** - * Setup a ScheduledExecutorService that we can use if someone provides an - * Executor instead of ScheduledExecutorService. - */ - private final static ScheduledExecutorService SYSTEM_SCHEDULED_EXECUTOR; - - static { - int count = Runtime.getRuntime().availableProcessors(); - if (count > 8) - count = count / 2; - // we don't need more than 8 to handle just scheduling and doing no work - if (count > 8) - count = 8; - SYSTEM_SCHEDULED_EXECUTOR = Executors.newScheduledThreadPool(count, new ThreadFactory() { - - final AtomicInteger counter = new AtomicInteger(); - - @Override - public Thread newThread(Runnable r) { - Thread t = new Thread(r, "RxScheduledExecutorPool-" + counter.incrementAndGet()); - t.setDaemon(true); - return t; - } - - }); - - } - - public ExecutorScheduler(Executor executor) { - this.executor = executor; - } - - public ExecutorScheduler(ScheduledExecutorService executor) { - this.executor = executor; - } - - @Override - public Subscription schedule(Func0 action, long dueTime, TimeUnit unit) { - final DiscardableAction discardableAction = new DiscardableAction(action); - - if (executor instanceof ScheduledExecutorService) - ((ScheduledExecutorService) executor).schedule(discardableAction::call, dueTime, unit); - else if (dueTime == 0) - // no delay so put on the thread-pool right now - return (schedule(action)); - else - // there is a delay and this isn't a ScheduledExecutorService so we'll use a system-wide ScheduledExecutorService - // to handle the scheduling and once it's ready then execute on this Executor - SYSTEM_SCHEDULED_EXECUTOR.schedule(() -> { - // now execute on the real Executor - executor.execute(discardableAction::call); - }, dueTime, unit); - return discardableAction; - } - - @Override - public Subscription schedule(Func0 action) { - final DiscardableAction discardableAction = new DiscardableAction(action); - - executor.execute(discardableAction::call); - - return discardableAction; - - } - -} diff --git a/HMCLAPI/src/main/java/rx/concurrency/ImmediateScheduler.java b/HMCLAPI/src/main/java/rx/concurrency/ImmediateScheduler.java deleted file mode 100755 index b0f7de54d..000000000 --- a/HMCLAPI/src/main/java/rx/concurrency/ImmediateScheduler.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.concurrency; - -import java.util.concurrent.TimeUnit; - -import rx.Subscription; -import rx.util.functions.Func0; - -/** - * Executes work immediately on the current thread. - */ -public final class ImmediateScheduler extends AbstractScheduler { - - private static final ImmediateScheduler INSTANCE = new ImmediateScheduler(); - - public static ImmediateScheduler getInstance() { - return INSTANCE; - } - - private ImmediateScheduler() { - } - - @Override - public Subscription schedule(Func0 action) { - return action.call(); - } - - @Override - public Subscription schedule(Func0 action, long dueTime, TimeUnit unit) { - return schedule(new SleepingAction(action, this, dueTime, unit)); - } - -} diff --git a/HMCLAPI/src/main/java/rx/concurrency/NewThreadScheduler.java b/HMCLAPI/src/main/java/rx/concurrency/NewThreadScheduler.java deleted file mode 100755 index e8a4b9150..000000000 --- a/HMCLAPI/src/main/java/rx/concurrency/NewThreadScheduler.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.concurrency; - -import java.util.concurrent.TimeUnit; - -import rx.Subscription; -import rx.util.functions.Func0; - -/** - * Schedules work on a new thread. - */ -public class NewThreadScheduler extends AbstractScheduler { - - private static final NewThreadScheduler INSTANCE = new NewThreadScheduler(); - - public static NewThreadScheduler getInstance() { - return INSTANCE; - } - - @Override - public Subscription schedule(Func0 action) { - final DiscardableAction discardableAction = new DiscardableAction(action); - - Thread t = new Thread(discardableAction::call, "RxNewThreadScheduler"); - - t.start(); - - return discardableAction; - } - - @Override - public Subscription schedule(Func0 action, long dueTime, TimeUnit unit) { - return schedule(new SleepingAction(action, this, dueTime, unit)); - } - -} diff --git a/HMCLAPI/src/main/java/rx/concurrency/Schedulers.java b/HMCLAPI/src/main/java/rx/concurrency/Schedulers.java deleted file mode 100755 index 666a2e3d8..000000000 --- a/HMCLAPI/src/main/java/rx/concurrency/Schedulers.java +++ /dev/null @@ -1,162 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.concurrency; - -import java.util.concurrent.Executor; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; - -import rx.Scheduler; - -/** - * Static factory methods for creating Schedulers. - */ -public class Schedulers { - - private static final ScheduledExecutorService COMPUTATION_EXECUTOR = createComputationExecutor(); - private static final Executor IO_EXECUTOR = createIOExecutor(); - - private Schedulers() { - - } - - /** - * {@link Scheduler} that executes work immediately on the current thread. - * - * @return {@link ImmediateScheduler} instance - */ - public static Scheduler immediate() { - return ImmediateScheduler.getInstance(); - } - - /** - * {@link Scheduler} that queues work on the current thread to be executed - * after the current work completes. - * - * @return {@link CurrentThreadScheduler} instance - */ - public static Scheduler currentThread() { - return CurrentThreadScheduler.getInstance(); - } - - /** - * {@link Scheduler} that creates a new {@link Thread} for each unit of - * work. - * - * @return {@link NewThreadScheduler} instance - */ - public static Scheduler newThread() { - return NewThreadScheduler.getInstance(); - } - - /** - * {@link Scheduler} that queues work on the EventQueue thread to be - * executed on the Swing UI Thread. - * - * @return {@link NewThreadScheduler} instance - */ - public static Scheduler eventQueue() { - return EventQueueScheduler.getInstance(); - } - - /** - * {@link Scheduler} that queues work on an {@link Executor}. - *

- * Note that this does not support scheduled actions with a delay. - * - * @return {@link ExecutorScheduler} instance - */ - public static Scheduler executor(Executor executor) { - return new ExecutorScheduler(executor); - } - - /** - * {@link Scheduler} that queues work on an - * {@link ScheduledExecutorService}. - * - * @return {@link ExecutorScheduler} instance - */ - public static Scheduler executor(ScheduledExecutorService executor) { - return new ExecutorScheduler(executor); - } - - /** - * {@link Scheduler} intended for computational work. - *

- * The implementation is backed by a {@link ScheduledExecutorService} - * thread-pool sized to the number of CPU cores. - *

- * This can be used for event-loops, processing callbacks and other - * computational work. - *

- * Do not perform IO-bound work on this scheduler. Use - * {@link #threadPoolForComputation()} instead. - * - * @return {@link ExecutorScheduler} for computation-bound work. - */ - public static Scheduler threadPoolForComputation() { - return executor(COMPUTATION_EXECUTOR); - } - - /** - * {@link Scheduler} intended for IO-bound work. - *

- * The implementation is backed by an {@link Executor} thread-pool that will - * grow as needed. - *

- * This can be used for asynchronously performing blocking IO. - *

- * Do not perform computational work on this scheduler. Use - * {@link #threadPoolForComputation()} instead. - * - * @return {@link ExecutorScheduler} for IO-bound work. - */ - public static Scheduler threadPoolForIO() { - return executor(IO_EXECUTOR); - } - - private static ScheduledExecutorService createComputationExecutor() { - int cores = Runtime.getRuntime().availableProcessors(); - return Executors.newScheduledThreadPool(cores, new ThreadFactory() { - final AtomicInteger counter = new AtomicInteger(); - - @Override - public Thread newThread(Runnable r) { - Thread t = new Thread(r, "RxComputationThreadPool-" + counter.incrementAndGet()); - t.setDaemon(true); - return t; - } - }); - } - - private static Executor createIOExecutor() { - Executor result = Executors.newCachedThreadPool(new ThreadFactory() { - final AtomicLong counter = new AtomicLong(); - - @Override - public Thread newThread(Runnable r) { - Thread t = new Thread(r, "RxIOThreadPool-" + counter.incrementAndGet()); - t.setDaemon(true); - return t; - } - }); - - return result; - } -} diff --git a/HMCLAPI/src/main/java/rx/concurrency/SleepingAction.java b/HMCLAPI/src/main/java/rx/concurrency/SleepingAction.java deleted file mode 100755 index 0eeca1288..000000000 --- a/HMCLAPI/src/main/java/rx/concurrency/SleepingAction.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.concurrency; - -import java.util.concurrent.TimeUnit; - -import rx.Scheduler; -import rx.Subscription; -import rx.util.functions.Func0; - -/* - * package - */ -class SleepingAction implements Func0 { - - private final Func0 underlying; - private final Scheduler scheduler; - private final long execTime; - - public SleepingAction(Func0 underlying, Scheduler scheduler, long timespan, TimeUnit timeUnit) { - this.underlying = underlying; - this.scheduler = scheduler; - this.execTime = scheduler.now() + timeUnit.toMillis(timespan); - } - - @Override - public Subscription call() { - if (execTime < scheduler.now()) - try { - Thread.sleep(scheduler.now() - execTime); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - throw new RuntimeException(e); - } - - return underlying.call(); - - } -} diff --git a/HMCLAPI/src/main/java/rx/observables/GroupedObservable.java b/HMCLAPI/src/main/java/rx/observables/GroupedObservable.java deleted file mode 100755 index 96c702575..000000000 --- a/HMCLAPI/src/main/java/rx/observables/GroupedObservable.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.observables; - -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.functions.Func1; - -/** - * An {@link Observable} that has been grouped by a key whose value can be - * obtained using {@link #getKey()} - *

- * - * @see {@link Observable#groupBy(Observable, Func1)} - * - * @param - * @param - */ -public class GroupedObservable extends Observable { - - private final K key; - - public GroupedObservable(K key, Func1, Subscription> onSubscribe) { - super(onSubscribe); - this.key = key; - } - - public K getKey() { - return key; - } - -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationAll.java b/HMCLAPI/src/main/java/rx/operators/OperationAll.java deleted file mode 100755 index 09187a961..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationAll.java +++ /dev/null @@ -1,60 +0,0 @@ -package rx.operators; - -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.AtomicObservableSubscription; -import rx.util.functions.Func1; - -import java.util.concurrent.atomic.AtomicBoolean; - -public class OperationAll { - - public static Func1, Subscription> all(Observable sequence, Func1 predicate) { - return new AllObservable<>(sequence, predicate); - } - - private static class AllObservable implements Func1, Subscription> { - - private final Observable sequence; - private final Func1 predicate; - - private final AtomicBoolean status = new AtomicBoolean(true); - private final AtomicObservableSubscription subscription = new AtomicObservableSubscription(); - - private AllObservable(Observable sequence, Func1 predicate) { - this.sequence = sequence; - this.predicate = predicate; - } - - @Override - public Subscription call(final Observer observer) { - return subscription.wrap(sequence.subscribe(new Observer() { - @Override - public void onCompleted() { - if (status.get()) { - observer.onNext(true); - observer.onCompleted(); - } - } - - @Override - public void onError(Exception e) { - observer.onError(e); - } - - @Override - public void onNext(T args) { - boolean result = predicate.call(args); - boolean changed = status.compareAndSet(true, result); - - if (changed && !result) { - observer.onNext(false); - observer.onCompleted(); - subscription.unsubscribe(); - } - } - })); - } - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationCombineLatest.java b/HMCLAPI/src/main/java/rx/operators/OperationCombineLatest.java deleted file mode 100755 index aa80e468e..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationCombineLatest.java +++ /dev/null @@ -1,293 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.atomic.AtomicBoolean; - -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.functions.Func1; -import rx.util.functions.Func2; -import rx.util.functions.Func3; -import rx.util.functions.Func4; -import rx.util.functions.FuncN; -import rx.util.functions.Functions; - -public class OperationCombineLatest { - - /** - * Combines the two given observables, emitting an event containing an - * aggregation of the latest values of each of the source observables each - * time an event is received from one of the source observables, where the - * aggregation is defined by the given function. - * - * @param w0 The first source observable. - * @param w1 The second source observable. - * @param combineLatestFunction The aggregation function used to combine the - * source observable values. - * - * @return A function from an observer to a subscription. This can be used - * to create an observable from. - */ - public static Func1, Subscription> combineLatest(Observable w0, Observable w1, Func2 combineLatestFunction) { - Aggregator a = new Aggregator<>(Functions.fromFunc(combineLatestFunction)); - a.addObserver(new CombineObserver(a, w0)); - a.addObserver(new CombineObserver(a, w1)); - return a; - } - - /** - * @see #combineLatest(Observable w0, Observable w1, Func2 - * combineLatestFunction) - */ - public static Func1, Subscription> combineLatest(Observable w0, Observable w1, Observable w2, Func3 combineLatestFunction) { - Aggregator a = new Aggregator<>(Functions.fromFunc(combineLatestFunction)); - a.addObserver(new CombineObserver(a, w0)); - a.addObserver(new CombineObserver(a, w1)); - a.addObserver(new CombineObserver(a, w2)); - return a; - } - - /** - * @see #combineLatest(Observable w0, Observable w1, Func2 - * combineLatestFunction) - */ - public static Func1, Subscription> combineLatest(Observable w0, Observable w1, Observable w2, Observable w3, Func4 combineLatestFunction) { - Aggregator a = new Aggregator<>(Functions.fromFunc(combineLatestFunction)); - a.addObserver(new CombineObserver(a, w0)); - a.addObserver(new CombineObserver(a, w1)); - a.addObserver(new CombineObserver(a, w2)); - a.addObserver(new CombineObserver(a, w3)); - return a; - } - - private static class CombineObserver implements Observer { - - final Observable w; - final Aggregator a; - private Subscription subscription; - - public CombineObserver(Aggregator a, Observable w) { - this.a = a; - this.w = w; - } - - public synchronized void startWatching() { - if (subscription != null) - throw new RuntimeException("This should only be called once."); - subscription = w.subscribe(this); - } - - @Override - public void onCompleted() { - a.complete(this); - } - - @Override - public void onError(Exception e) { - a.error(e); - } - - @Override - public void onNext(T args) { - a.next(this, args); - } - } - - /** - * Receive notifications from each of the observables we are reducing and - * execute the combineLatestFunction whenever we have received an event from - * one of the observables, as soon as each Observable has received at least - * one event. - */ - private static class Aggregator implements Func1, Subscription> { - - private Observer observer; - - private final FuncN combineLatestFunction; - private final AtomicBoolean running = new AtomicBoolean(true); - - // used as an internal lock for handling the latest values and the completed state of each observer - private final Object lockObject = new Object(); - - /** - * Store when an observer completes. - *

- * Note that access to this set MUST BE SYNCHRONIZED via 'lockObject' - * above. - * - */ - private final Set> completed = new HashSet<>(); - - /** - * The latest value from each observer - *

- * Note that access to this set MUST BE SYNCHRONIZED via 'lockObject' - * above. - * - */ - private final Map, Object> latestValue = new HashMap<>(); - - /** - * Whether each observer has a latest value at all. - *

- * Note that access to this set MUST BE SYNCHRONIZED via 'lockObject' - * above. - * - */ - private final Set> hasLatestValue = new HashSet<>(); - - /** - * Ordered list of observers to combine. No synchronization is necessary - * as these can not be added or changed asynchronously. - */ - private final List> observers = new LinkedList<>(); - - public Aggregator(FuncN combineLatestFunction) { - this.combineLatestFunction = combineLatestFunction; - } - - /** - * Receive notification of a Observer starting (meaning we should - * require it for aggregation) - * - * @param w The observer to add. - */ - void addObserver(CombineObserver w) { - observers.add(w); - } - - /** - * Receive notification of a Observer completing its iterations. - * - * @param w The observer that has completed. - */ - void complete(CombineObserver w) { - synchronized (lockObject) { - // store that this CombineLatestObserver is completed - completed.add(w); - // if all CombineObservers are completed, we mark the whole thing as completed - if (completed.size() == observers.size()) - if (running.get()) { - // mark ourselves as done - observer.onCompleted(); - // just to ensure we stop processing in case we receive more onNext/complete/error calls after this - running.set(false); - } - } - } - - /** - * Receive error for a Observer. Throw the error up the chain and stop - * processing. - */ - void error(Exception e) { - observer.onError(e); - /* - * tell all observers to unsubscribe since we had an error - */ - stop(); - } - - /** - * Receive the next value from an observer. - *

- * If we have received values from all observers, trigger the - * combineLatest function, otherwise store the value and keep waiting. - * - * @param w - * @param arg - */ - void next(CombineObserver w, T arg) { - if (observer == null) - throw new RuntimeException("This shouldn't be running if an Observer isn't registered"); - - /* - * if we've been 'unsubscribed' don't process anything further even - * if the things we're watching keep sending (likely because they - * are not responding to the unsubscribe call) - */ - if (!running.get()) - return; - - // define here so the variable is out of the synchronized scope - Object[] argsToCombineLatest = new Object[observers.size()]; - - // we synchronize everything that touches latest values - synchronized (lockObject) { - // remember this as the latest value for this observer - latestValue.put(w, arg); - - // remember that this observer now has a latest value set - hasLatestValue.add(w); - - // if all observers in the 'observers' list have a value, invoke the combineLatestFunction - for (CombineObserver rw : observers) - if (!hasLatestValue.contains(rw)) - // we don't have a value yet for each observer to combine, so we don't have a combined value yet either - return; - // if we get to here this means all the queues have data - int i = 0; - for (CombineObserver _w : observers) - argsToCombineLatest[i++] = latestValue.get(_w); - } - // if we did not return above from the synchronized block we can now invoke the combineLatestFunction with all of the args - // we do this outside the synchronized block as it is now safe to call this concurrently and don't need to block other threads from calling - // this 'next' method while another thread finishes calling this combineLatestFunction - observer.onNext(combineLatestFunction.call(argsToCombineLatest)); - } - - @Override - public Subscription call(Observer observer) { - if (this.observer != null) - throw new IllegalStateException("Only one Observer can subscribe to this Observable."); - this.observer = observer; - - /* - * start the observers - */ - for (CombineObserver rw : observers) - rw.startWatching(); - - return new Subscription() { - @Override - public void unsubscribe() { - stop(); - } - }; - } - - private void stop() { - /* - * tell ourselves to stop processing onNext events - */ - running.set(false); - /* - * propogate to all observers to unsubscribe - */ - for (CombineObserver rw : observers) - if (rw.subscription != null) - rw.subscription.unsubscribe(); - } - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationConcat.java b/HMCLAPI/src/main/java/rx/operators/OperationConcat.java deleted file mode 100755 index e1577bb81..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationConcat.java +++ /dev/null @@ -1,130 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import java.lang.reflect.Array; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CountDownLatch; - -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.AtomicObservableSubscription; -import rx.util.functions.Action1; -import rx.util.functions.Func1; - -public final class OperationConcat { - - /** - * Combine the observable sequences from the list of Observables into one - * observable sequence without any transformation. - * - * @param sequences An observable sequence of elements to project. - * - * @return An observable sequence whose elements are the result of combining - * the output from the list of Observables. - */ - public static Func1, Subscription> concat(final Observable... sequences) { - return new Func1, Subscription>() { - - @Override - public Subscription call(Observer observer) { - return new Concat(sequences).call(observer); - } - }; - } - - public static Func1, Subscription> concat(final List> sequences) { - @SuppressWarnings("unchecked") - Observable[] o = sequences.toArray((Observable[]) Array.newInstance(Observable.class, sequences.size())); - return concat(o); - } - - public static Func1, Subscription> concat(final Observable> sequences) { - final List> list = new ArrayList>(); - sequences.toList().subscribe(new Action1>>() { - @Override - public void call(List> t1) { - list.addAll(t1); - } - - }); - - return concat(list); - } - - private static class Concat implements Func1, Subscription> { - - private final Observable[] sequences; - private int num = 0; - private int count = 0; - private Subscription s; - - Concat(final Observable... sequences) { - this.sequences = sequences; - this.num = sequences.length - 1; - } - - private final AtomicObservableSubscription Subscription = new AtomicObservableSubscription(); - - private final Subscription actualSubscription = new Subscription() { - - @Override - public void unsubscribe() { - if (null != s) - s.unsubscribe(); - } - }; - - public Subscription call(Observer observer) { - s = sequences[count].subscribe(new ConcatObserver(observer)); - - return Subscription.wrap(actualSubscription); - } - - private class ConcatObserver implements Observer { - - private final Observer observer; - - ConcatObserver(Observer observer) { - this.observer = observer; - } - - @Override - public void onCompleted() { - if (num == count) - observer.onCompleted(); - else { - count++; - s = sequences[count].subscribe(this); - } - } - - @Override - public void onError(Exception e) { - observer.onError(e); - - } - - @Override - public void onNext(T args) { - observer.onNext(args); - - } - } - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationDefer.java b/HMCLAPI/src/main/java/rx/operators/OperationDefer.java deleted file mode 100755 index 45abd1a38..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationDefer.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.functions.Func0; -import rx.util.functions.Func1; - -public final class OperationDefer { - - public static Func1, Subscription> defer(final Func0> observableFactory) { - return observableFactory.call()::subscribe; - } - -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationDematerialize.java b/HMCLAPI/src/main/java/rx/operators/OperationDematerialize.java deleted file mode 100755 index fa5eca845..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationDematerialize.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import rx.Notification; -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.functions.Func1; - -/** - * Dematerializes the explicit notification values of an observable sequence as - * implicit notifications. See - * http://msdn.microsoft.com/en-us/library/hh229047(v=vs.103).aspx for the - * Microsoft Rx equivalent. - */ -public final class OperationDematerialize { - - /** - * Dematerializes the explicit notification values of an observable sequence - * as implicit notifications. - * - * @param sequence An observable sequence containing explicit notification - * values which have to be turned into implicit notifications. - * - * @return An observable sequence exhibiting the behavior corresponding to - * the source sequence's notification values. - * - * @see http://msdn.microsoft.com/en-us/library/hh229047(v=vs.103).aspx - */ - public static Func1, Subscription> dematerialize(final Observable> sequence) { - return new DematerializeObservable<>(sequence); - } - - private static class DematerializeObservable implements Func1, Subscription> { - - private final Observable> sequence; - - public DematerializeObservable(Observable> sequence) { - this.sequence = sequence; - } - - @Override - public Subscription call(final Observer observer) { - return sequence.subscribe(new Observer>() { - @Override - public void onCompleted() { - } - - @Override - public void onError(Exception e) { - } - - @Override - public void onNext(Notification value) { - switch (value.getKind()) { - case OnNext: - observer.onNext(value.getValue()); - break; - case OnError: - observer.onError(value.getException()); - break; - case OnCompleted: - observer.onCompleted(); - break; - } - } - }); - } - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationFilter.java b/HMCLAPI/src/main/java/rx/operators/OperationFilter.java deleted file mode 100755 index 5447d302e..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationFilter.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.AtomicObservableSubscription; -import rx.util.functions.Func1; - -public final class OperationFilter { - - public static Func1, Subscription> filter(Observable that, Func1 predicate) { - return new Filter<>(that, predicate); - } - - private static class Filter implements Func1, Subscription> { - - private final Observable that; - private final Func1 predicate; - private final AtomicObservableSubscription subscription = new AtomicObservableSubscription(); - - public Filter(Observable that, Func1 predicate) { - this.that = that; - this.predicate = predicate; - } - - @Override - public Subscription call(final Observer observer) { - return subscription.wrap(that.subscribe(new Observer() { - @Override - public void onNext(T value) { - try { - if (predicate.call(value)) - observer.onNext(value); - } catch (Exception ex) { - observer.onError(ex); - // this will work if the sequence is asynchronous, it will have no effect on a synchronous observable - subscription.unsubscribe(); - } - } - - @Override - public void onError(Exception ex) { - observer.onError(ex); - } - - @Override - public void onCompleted() { - observer.onCompleted(); - } - })); - } - - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationFinally.java b/HMCLAPI/src/main/java/rx/operators/OperationFinally.java deleted file mode 100755 index 1d4fc9d94..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationFinally.java +++ /dev/null @@ -1,98 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.functions.Action0; -import rx.util.functions.Func1; - -public final class OperationFinally { - - /** - * Call a given action when a sequence completes (with or without an - * exception). The returned observable is exactly as threadsafe as the - * source observable. - *

- * Note that "finally" is a Java reserved word and cannot be an identifier, - * so we use "finallyDo". - * - * @param sequence An observable sequence of elements - * @param action An action to be taken when the sequence is complete or - * throws an exception - * - * @return An observable sequence with the same elements as the input. After - * the last element is consumed (and {@link Observer#onCompleted} has been - * called), or after an exception is thrown (and {@link Observer#onError} - * has been called), the given action will be called. - * - * @see - * MSDN - * Observable.Finally method - */ - public static Func1, Subscription> finallyDo(final Observable sequence, final Action0 action) { - return new Finally<>(sequence, action)::call; - } - - private static class Finally implements Func1, Subscription> { - - private final Observable sequence; - private final Action0 finalAction; - - Finally(final Observable sequence, Action0 finalAction) { - this.sequence = sequence; - this.finalAction = finalAction; - } - - @Override - public Subscription call(Observer observer) { - return sequence.subscribe(new FinallyObserver(observer)); - } - - private class FinallyObserver implements Observer { - - private final Observer observer; - - FinallyObserver(Observer observer) { - this.observer = observer; - } - - @Override - public void onCompleted() { - try { - observer.onCompleted(); - } finally { - finalAction.call(); - } - } - - @Override - public void onError(Exception e) { - try { - observer.onError(e); - } finally { - finalAction.call(); - } - } - - @Override - public void onNext(T args) { - observer.onNext(args); - } - } - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationMap.java b/HMCLAPI/src/main/java/rx/operators/OperationMap.java deleted file mode 100755 index 1a80237c0..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationMap.java +++ /dev/null @@ -1,123 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.functions.Func1; - -public final class OperationMap { - - /** - * Accepts a sequence and a transformation function. Returns a sequence that - * is the result of applying the transformation function to each item in the - * sequence. - * - * @param sequence the input sequence. - * @param func a function to apply to each item in the sequence. - * @param the type of the input sequence. - * @param the type of the output sequence. - * - * @return a sequence that is the result of applying the transformation - * function to each item in the input sequence. - */ - public static Func1, Subscription> map(Observable sequence, Func1 func) { - return new MapObservable<>(sequence, func); - } - - /** - * Accepts a sequence of observable sequences and a transformation function. - * Returns a flattened sequence that is the result of applying the - * transformation function to each item in the sequence of each observable - * sequence. - *

- * The closure should return an Observable which will then be merged. - * - * @param sequence the input sequence. - * @param func a function to apply to each item in the sequence. - * @param the type of the input sequence. - * @param the type of the output sequence. - * - * @return a sequence that is the result of applying the transformation - * function to each item in the input sequence. - */ - public static Func1, Subscription> mapMany(Observable sequence, Func1> func) { - return OperationMerge.merge(Observable.create(map(sequence, func))); - } - - /** - * An observable sequence that is the result of applying a transformation to - * each item in an input sequence. - * - * @param the type of the input sequence. - * @param the type of the output sequence. - */ - private static class MapObservable implements Func1, Subscription> { - - public MapObservable(Observable sequence, Func1 func) { - this.sequence = sequence; - this.func = func; - } - - private final Observable sequence; - - private final Func1 func; - - @Override - public Subscription call(Observer observer) { - return sequence.subscribe(new MapObserver<>(observer, func)); - } - } - - /** - * An observer that applies a transformation function to each item and - * forwards the result to an inner observer. - * - * @param the type of the observer items. - * @param the type of the inner observer items. - */ - private static class MapObserver implements Observer { - - public MapObserver(Observer observer, Func1 func) { - this.observer = observer; - this.func = func; - } - - Observer observer; - - Func1 func; - - @Override - public void onNext(T value) { - try { - observer.onNext(func.call(value)); - } catch (Exception ex) { - observer.onError(ex); - } - } - - @Override - public void onError(Exception ex) { - observer.onError(ex); - } - - @Override - public void onCompleted() { - observer.onCompleted(); - } - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationMaterialize.java b/HMCLAPI/src/main/java/rx/operators/OperationMaterialize.java deleted file mode 100755 index 252acf542..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationMaterialize.java +++ /dev/null @@ -1,85 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import rx.Notification; -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.functions.Func1; - -/** - * Materializes the implicit notifications of an observable sequence as explicit - * notification values. - *

- * In other words, converts a sequence of OnNext, OnError and OnCompleted events - * into a sequence of ObservableNotifications containing the OnNext, OnError and - * OnCompleted values. - *

- * See http://msdn.microsoft.com/en-us/library/hh229453(v=VS.103).aspx for the - * Microsoft Rx equivalent. - */ -public final class OperationMaterialize { - - /** - * Materializes the implicit notifications of an observable sequence as - * explicit notification values. - * - * @param sequence An observable sequence of elements to project. - * - * @return An observable sequence whose elements are the result of - * materializing the notifications of the given sequence. - * - * @see http://msdn.microsoft.com/en-us/library/hh229453(v=VS.103).aspx - */ - public static Func1>, Subscription> materialize(final Observable sequence) { - return new MaterializeObservable<>(sequence); - } - - private static class MaterializeObservable implements Func1>, Subscription> { - - private final Observable sequence; - - public MaterializeObservable(Observable sequence) { - this.sequence = sequence; - } - - @Override - public Subscription call(final Observer> observer) { - return sequence.subscribe(new Observer() { - - @Override - public void onCompleted() { - observer.onNext(new Notification<>()); - observer.onCompleted(); - } - - @Override - public void onError(Exception e) { - observer.onNext(new Notification<>(e)); - observer.onCompleted(); - } - - @Override - public void onNext(T value) { - observer.onNext(new Notification<>(value)); - } - - }); - } - - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationMerge.java b/HMCLAPI/src/main/java/rx/operators/OperationMerge.java deleted file mode 100755 index f9ca27f63..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationMerge.java +++ /dev/null @@ -1,261 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicBoolean; - -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.AtomicObservableSubscription; -import rx.util.SynchronizedObserver; -import rx.util.functions.Func1; - -public final class OperationMerge { - - /** - * Flattens the observable sequences from the list of Observables into one - * observable sequence without any transformation. - * - * @param source An observable sequence of elements to project. - * - * @return An observable sequence whose elements are the result of - * flattening the output from the list of Observables. - * - * @see http://msdn.microsoft.com/en-us/library/hh229099(v=vs.103).aspx - */ - public static Func1, Subscription> merge(final Observable> source) { - // wrap in a Func so that if a chain is built up, then asynchronously subscribed to twice we will have 2 instances of Take rather than 1 handing both, which is not thread-safe. - return new MergeObservable(source)::call; - } - - public static Func1, Subscription> merge(final Observable... sequences) { - return merge(Arrays.asList(sequences)); - } - - public static Func1, Subscription> merge(final List> sequences) { - return merge(Observable.create(new Func1>, Subscription>() { - - private volatile boolean unsubscribed = false; - - @Override - public Subscription call(Observer> observer) { - for (Observable o : sequences) - if (!unsubscribed) - observer.onNext(o); - else - // break out of the loop if we are unsubscribed - break; - if (!unsubscribed) - observer.onCompleted(); - - return () -> { - unsubscribed = true; - }; - } - })); - } - - /** - * This class is NOT thread-safe if invoked and referenced multiple times. - * In other words, don't subscribe to it multiple times from different - * threads. - *

- * It IS thread-safe from within it while receiving onNext events from - * multiple threads. - *

- * This should all be fine as long as it's kept as a private class and a new - * instance created from static factory method above. - *

- * Note how the take() factory method above protects us from a single - * instance being exposed with the Observable wrapper handling the subscribe - * flow. - * - * @param - */ - private static final class MergeObservable implements Func1, Subscription> { - - private final Observable> sequences; - private final MergeSubscription ourSubscription = new MergeSubscription(); - private final AtomicBoolean stopped = new AtomicBoolean(false); - private volatile boolean parentCompleted = false; - private final ConcurrentHashMap childObservers = new ConcurrentHashMap<>(); - private final ConcurrentHashMap childSubscriptions = new ConcurrentHashMap<>(); - - private MergeObservable(Observable> sequences) { - this.sequences = sequences; - } - - @Override - public Subscription call(Observer actualObserver) { - - /** - * We must synchronize a merge because we subscribe to multiple - * sequences in parallel that will each be emitting. - *

- * The calls from each sequence must be serialized. - *

- * Bug report: https://github.com/Netflix/RxJava/issues/200 - */ - AtomicObservableSubscription subscription = new AtomicObservableSubscription(ourSubscription); - SynchronizedObserver synchronizedObserver = new SynchronizedObserver<>(actualObserver, subscription); - - /** - * Subscribe to the parent Observable to get to the children - * Observables - */ - sequences.subscribe(new ParentObserver(synchronizedObserver)); - - /* - * return our subscription to allow unsubscribing - */ - return subscription; - } - - /** - * Manage the internal subscription with a thread-safe means of - * stopping/unsubscribing so we don't unsubscribe twice. - *

- * Also has the stop() method returning a boolean so callers know if - * their thread "won" and should perform further actions. - */ - private class MergeSubscription implements Subscription { - - @Override - public void unsubscribe() { - stop(); - } - - public boolean stop() { - // try setting to false unless another thread beat us - boolean didSet = stopped.compareAndSet(false, true); - if (didSet) { - // this thread won the race to stop, so unsubscribe from the actualSubscription - for (Subscription _s : childSubscriptions.values()) - _s.unsubscribe(); - return true; - } else - // another thread beat us - return false; - } - } - - /** - * Subscribe to the top level Observable to receive the sequence of - * Observable children. - * - * @param - */ - private class ParentObserver implements Observer> { - - private final Observer actualObserver; - - public ParentObserver(Observer actualObserver) { - this.actualObserver = actualObserver; - } - - @Override - public void onCompleted() { - parentCompleted = true; - // this *can* occur before the children are done, so if it does we won't send onCompleted - // but will let the child worry about it - // if however this completes and there are no children processing, then we will send onCompleted - - if (childObservers.isEmpty()) - if (!stopped.get()) - if (ourSubscription.stop()) - actualObserver.onCompleted(); - } - - @Override - public void onError(Exception e) { - actualObserver.onError(e); - } - - @Override - public void onNext(Observable childObservable) { - if (stopped.get()) - // we won't act on any further items - return; - - if (childObservable == null) - throw new IllegalArgumentException("Observable can not be null."); - - /** - * For each child Observable we receive we'll subscribe with a - * separate Observer that will each then forward their sequences - * to the actualObserver. - *

- * We use separate child Observers for each sequence to simplify - * the onComplete/onError handling so each sequence has its own - * lifecycle. - */ - ChildObserver _w = new ChildObserver(actualObserver); - childObservers.put(_w, _w); - Subscription _subscription = childObservable.subscribe(_w); - // remember this Observer and the subscription from it - childSubscriptions.put(_w, _subscription); - } - } - - /** - * Subscribe to each child Observable and forward their sequence of - * data to the actualObserver - * - */ - private class ChildObserver implements Observer { - - private final Observer actualObserver; - - public ChildObserver(Observer actualObserver) { - this.actualObserver = actualObserver; - } - - @Override - public void onCompleted() { - // remove self from map of Observers - childObservers.remove(this); - // if there are now 0 Observers left, so if the parent is also completed we send the onComplete to the actualObserver - // if the parent is not complete that means there is another sequence (and child Observer) to come - if (!stopped.get()) - if (childObservers.isEmpty() && parentCompleted) - if (ourSubscription.stop()) - // this thread 'won' the race to unsubscribe/stop so let's send onCompleted - actualObserver.onCompleted(); - } - - @Override - public void onError(Exception e) { - if (!stopped.get()) - if (ourSubscription.stop()) - // this thread 'won' the race to unsubscribe/stop so let's send the error - actualObserver.onError(e); - } - - @Override - public void onNext(T args) { - // in case the Observable is poorly behaved and doesn't listen to the unsubscribe request - // we'll ignore anything that comes in after we've unsubscribed - if (!stopped.get()) - actualObserver.onNext(args); - } - - } - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationMergeDelayError.java b/HMCLAPI/src/main/java/rx/operators/OperationMergeDelayError.java deleted file mode 100755 index 4a2e26bfc..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationMergeDelayError.java +++ /dev/null @@ -1,337 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.atomic.AtomicBoolean; - -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.CompositeException; -import rx.util.functions.Func1; - -/** - * Same functionality as OperationMerge except that onError events will be - * skipped so that all onNext calls are passed on until all sequences finish - * with onComplete or onError, and then the first onError received (if any) will - * be passed on. - *

- * This allows retrieving all successful onNext calls without being blocked by - * an onError early in a sequence. - *

- * NOTE: If this is used on an infinite stream it will never call onError and - * effectively will swallow errors. - */ -public final class OperationMergeDelayError { - - /** - * Flattens the observable sequences from the list of Observables into one - * observable sequence without any transformation and delays any onError - * calls until after all sequences have called onError or onComplete so as - * to allow all successful onNext calls to be received. - * - * @param source An observable sequence of elements to project. - * - * @return An observable sequence whose elements are the result of - * flattening the output from the list of Observables. - * - * @see http://msdn.microsoft.com/en-us/library/hh229099(v=vs.103).aspx - */ - public static Func1, Subscription> mergeDelayError(final Observable> sequences) { - // wrap in a Func so that if a chain is built up, then asynchronously subscribed to twice we will have 2 instances of Take rather than 1 handing both, which is not thread-safe. - return new Func1, Subscription>() { - - @Override - public Subscription call(Observer observer) { - return new MergeDelayErrorObservable(sequences).call(observer); - } - }; - } - - public static Func1, Subscription> mergeDelayError(final Observable... sequences) { - return mergeDelayError(Observable.create(new Func1>, Subscription>() { - private volatile boolean unsubscribed = false; - - @Override - public Subscription call(Observer> observer) { - for (Observable o : sequences) - if (!unsubscribed) - observer.onNext(o); - else - // break out of the loop if we are unsubscribed - break; - if (!unsubscribed) - observer.onCompleted(); - return new Subscription() { - - @Override - public void unsubscribe() { - unsubscribed = true; - } - - }; - } - })); - } - - public static Func1, Subscription> mergeDelayError(final List> sequences) { - return mergeDelayError(Observable.create(new Func1>, Subscription>() { - - private volatile boolean unsubscribed = false; - - @Override - public Subscription call(Observer> observer) { - for (Observable o : sequences) - if (!unsubscribed) - observer.onNext(o); - else - // break out of the loop if we are unsubscribed - break; - if (!unsubscribed) - observer.onCompleted(); - - return new Subscription() { - - @Override - public void unsubscribe() { - unsubscribed = true; - } - - }; - } - })); - } - - /** - * This class is NOT thread-safe if invoked and referenced multiple times. - * In other words, don't subscribe to it multiple times from different - * threads. - *

- * It IS thread-safe from within it while receiving onNext events from - * multiple threads. - *

- * This should all be fine as long as it's kept as a private class and a new - * instance created from static factory method above. - *

- * Note how the take() factory method above protects us from a single - * instance being exposed with the Observable wrapper handling the subscribe - * flow. - * - * @param - */ - private static final class MergeDelayErrorObservable implements Func1, Subscription> { - - private final Observable> sequences; - private final MergeSubscription ourSubscription = new MergeSubscription(); - private AtomicBoolean stopped = new AtomicBoolean(false); - private volatile boolean parentCompleted = false; - private final ConcurrentHashMap childObservers = new ConcurrentHashMap(); - private final ConcurrentHashMap childSubscriptions = new ConcurrentHashMap(); - // onErrors we received that will be delayed until everything is completed and then sent - private ConcurrentLinkedQueue onErrorReceived = new ConcurrentLinkedQueue(); - - private MergeDelayErrorObservable(Observable> sequences) { - this.sequences = sequences; - } - - public Subscription call(Observer actualObserver) { - /** - * Subscribe to the parent Observable to get to the children - * Observables - */ - sequences.subscribe(new ParentObserver(actualObserver)); - - /* - * return our subscription to allow unsubscribing - */ - return ourSubscription; - } - - /** - * Manage the internal subscription with a thread-safe means of - * stopping/unsubscribing so we don't unsubscribe twice. - *

- * Also has the stop() method returning a boolean so callers know if - * their thread "won" and should perform further actions. - */ - private class MergeSubscription implements Subscription { - - @Override - public void unsubscribe() { - stop(); - } - - public boolean stop() { - // try setting to false unless another thread beat us - boolean didSet = stopped.compareAndSet(false, true); - if (didSet) { - // this thread won the race to stop, so unsubscribe from the actualSubscription - for (Subscription _s : childSubscriptions.values()) - _s.unsubscribe(); - return true; - } else - // another thread beat us - return false; - } - } - - /** - * Subscribe to the top level Observable to receive the sequence of - * Observable children. - * - * @param - */ - private class ParentObserver implements Observer> { - - private final Observer actualObserver; - - public ParentObserver(Observer actualObserver) { - this.actualObserver = actualObserver; - } - - @Override - public void onCompleted() { - parentCompleted = true; - // this *can* occur before the children are done, so if it does we won't send onCompleted - // but will let the child worry about it - // if however this completes and there are no children processing, then we will send onCompleted - - if (childObservers.size() == 0) - if (!stopped.get()) - if (ourSubscription.stop()) - if (onErrorReceived.size() == 1) - // an onError was received from 1 ChildObserver so we now send it as a delayed error - actualObserver.onError(onErrorReceived.peek()); - else if (onErrorReceived.size() > 1) - // an onError was received from more than 1 ChildObserver so we now send it as a delayed error - actualObserver.onError(new CompositeException(onErrorReceived)); - else - // no delayed error so send onCompleted - actualObserver.onCompleted(); - } - - @Override - public void onError(Exception e) { - actualObserver.onError(e); - } - - @Override - public void onNext(Observable childObservable) { - if (stopped.get()) - // we won't act on any further items - return; - - if (childObservable == null) - throw new IllegalArgumentException("Observable can not be null."); - - /** - * For each child Observable we receive we'll subscribe with a - * separate Observer that will each then forward their sequences - * to the actualObserver. - *

- * We use separate child Observers for each sequence to simplify - * the onComplete/onError handling so each sequence has its own - * lifecycle. - */ - ChildObserver _w = new ChildObserver(actualObserver); - childObservers.put(_w, _w); - Subscription _subscription = childObservable.subscribe(_w); - // remember this Observer and the subscription from it - childSubscriptions.put(_w, _subscription); - } - } - - /** - * Subscribe to each child Observable and forward their sequence of - * data to the actualObserver - * - */ - private class ChildObserver implements Observer { - - private final Observer actualObserver; - private volatile boolean finished = false; - - public ChildObserver(Observer actualObserver) { - this.actualObserver = actualObserver; - } - - @Override - public void onCompleted() { - // remove self from map of Observers - childObservers.remove(this); - // if there are now 0 Observers left, so if the parent is also completed we send the onComplete to the actualObserver - // if the parent is not complete that means there is another sequence (and child Observer) to come - if (!stopped.get()) - finishObserver(); - } - - @Override - public void onError(Exception e) { - if (!stopped.get()) { - onErrorReceived.add(e); - // mark this ChildObserver as done - childObservers.remove(this); - // but do NOT forward to actualObserver as we want other ChildObservers to continue until completion - // and we'll delay the sending of onError until all others are done - - // we mark finished==true as a safety to ensure that if further calls to onNext occur we ignore them - finished = true; - - // check for whether the parent is completed and if so then perform the 'finishing' actions - finishObserver(); - } - } - - /** - * onComplete and onError when called need to check for the parent - * being complete and if so send the onCompleted or onError to the - * actualObserver. - *

- * This does NOT get invoked if synchronous execution occurs, but - * will when asynchronously executing. - *

- * TestCase testErrorDelayed4WithThreading specifically tests this - * use case. - */ - private void finishObserver() { - if (childObservers.size() == 0 && parentCompleted) - if (ourSubscription.stop()) - // this thread 'won' the race to unsubscribe/stop so let's send onError or onCompleted - if (onErrorReceived.size() == 1) - // an onError was received from 1 ChildObserver so we now send it as a delayed error - actualObserver.onError(onErrorReceived.peek()); - else if (onErrorReceived.size() > 1) - // an onError was received from more than 1 ChildObserver so we now send it as a delayed error - actualObserver.onError(new CompositeException(onErrorReceived)); - else - // no delayed error so send onCompleted - actualObserver.onCompleted(); - } - - @Override - public void onNext(T args) { - // in case the Observable is poorly behaved and doesn't listen to the unsubscribe request - // we'll ignore anything that comes in after we've unsubscribed or an onError has been received and delayed - if (!stopped.get() && !finished) - actualObserver.onNext(args); - } - - } - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationMostRecent.java b/HMCLAPI/src/main/java/rx/operators/OperationMostRecent.java deleted file mode 100755 index 6d37a0e47..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationMostRecent.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import java.util.Iterator; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicReference; - -import rx.Observable; -import rx.Observer; -import rx.util.Exceptions; - -/** - * Samples the most recent value in an observable sequence. - */ -public final class OperationMostRecent { - - public static Iterable mostRecent(final Observable source, T initialValue) { - - MostRecentObserver mostRecentObserver = new MostRecentObserver<>(initialValue); - MostRecentIterator nextIterator = new MostRecentIterator<>(mostRecentObserver); - - source.subscribe(mostRecentObserver); - - return () -> nextIterator; - - } - - private static class MostRecentIterator implements Iterator { - - private final MostRecentObserver observer; - - private MostRecentIterator(MostRecentObserver observer) { - this.observer = observer; - } - - @Override - public boolean hasNext() { - return !observer.isCompleted(); - } - - @Override - public T next() { - if (observer.getException() != null) - throw Exceptions.propagate(observer.getException()); - return observer.getRecentValue(); - } - - @Override - public void remove() { - throw new UnsupportedOperationException("Read only iterator"); - } - } - - private static class MostRecentObserver implements Observer { - - private final AtomicBoolean completed = new AtomicBoolean(false); - private final AtomicReference value; - private final AtomicReference exception = new AtomicReference<>(); - - private MostRecentObserver(T value) { - this.value = new AtomicReference<>(value); - } - - @Override - public void onCompleted() { - completed.set(true); - } - - @Override - public void onError(Exception e) { - exception.set(e); - } - - @Override - public void onNext(T args) { - value.set(args); - } - - public boolean isCompleted() { - return completed.get(); - } - - public Exception getException() { - return exception.get(); - } - - public T getRecentValue() { - return value.get(); - } - - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationNext.java b/HMCLAPI/src/main/java/rx/operators/OperationNext.java deleted file mode 100755 index 0204b6f91..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationNext.java +++ /dev/null @@ -1,143 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import java.util.Iterator; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.atomic.AtomicBoolean; - -import rx.Notification; -import rx.Observable; -import rx.Observer; -import rx.util.Exceptions; - -/** - * Samples the next value (blocking without buffering) from in an observable - * sequence. - */ -public final class OperationNext { - - public static Iterable next(final Observable items) { - - NextObserver nextObserver = new NextObserver<>(); - final NextIterator nextIterator = new NextIterator<>(nextObserver); - - items.materialize().subscribe(nextObserver); - - return () -> nextIterator; - - } - - private static class NextIterator implements Iterator { - - private final NextObserver observer; - - private NextIterator(NextObserver observer) { - this.observer = observer; - } - - @Override - public boolean hasNext() { - return !observer.isCompleted(false); - } - - @Override - public T next() { - if (observer.isCompleted(true)) - throw new IllegalStateException("Observable is completed"); - - observer.await(); - - try { - return observer.takeNext(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - throw Exceptions.propagate(e); - } - - } - - @Override - public void remove() { - throw new UnsupportedOperationException("Read only iterator"); - } - } - - private static class NextObserver implements Observer> { - - private final BlockingQueue> buf = new ArrayBlockingQueue<>(1); - private final AtomicBoolean waiting = new AtomicBoolean(false); - - @Override - public void onCompleted() { - // ignore - } - - @Override - public void onError(Exception e) { - // ignore - } - - @Override - public void onNext(Notification args) { - - if (waiting.getAndSet(false) || !args.isOnNext()) { - Notification toOffer = args; - while (!buf.offer(toOffer)) { - Notification concurrentItem = buf.poll(); - - // in case if we won race condition with onComplete/onError method - if (!concurrentItem.isOnNext()) - toOffer = concurrentItem; - } - } - - } - - public void await() { - waiting.set(true); - } - - public boolean isCompleted(boolean rethrowExceptionIfExists) { - Notification lastItem = buf.peek(); - if (lastItem == null) - return false; - - if (lastItem.isOnError()) - if (rethrowExceptionIfExists) - throw Exceptions.propagate(lastItem.getException()); - else - return true; - - return lastItem.isOnCompleted(); - } - - public T takeNext() throws InterruptedException { - Notification next = buf.take(); - - if (next.isOnError()) - throw Exceptions.propagate(next.getException()); - - if (next.isOnCompleted()) - throw new IllegalStateException("Observable is completed"); - - return next.getValue(); - - } - - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationObserveOn.java b/HMCLAPI/src/main/java/rx/operators/OperationObserveOn.java deleted file mode 100755 index 176d880e1..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationObserveOn.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import rx.Observable; -import rx.Observer; -import rx.Scheduler; -import rx.Subscription; -import rx.util.functions.Func1; - -public class OperationObserveOn { - - public static Func1, Subscription> observeOn(Observable source, Scheduler scheduler) { - return new ObserveOn<>(source, scheduler); - } - - private static class ObserveOn implements Func1, Subscription> { - - private final Observable source; - private final Scheduler scheduler; - - public ObserveOn(Observable source, Scheduler scheduler) { - this.source = source; - this.scheduler = scheduler; - } - - @Override - public Subscription call(final Observer observer) { - return source.subscribe(new ScheduledObserver<>(observer, scheduler)); - } - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationOnErrorResumeNextViaFunction.java b/HMCLAPI/src/main/java/rx/operators/OperationOnErrorResumeNextViaFunction.java deleted file mode 100755 index 1f3758fa0..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationOnErrorResumeNextViaFunction.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import java.util.Arrays; -import java.util.concurrent.atomic.AtomicReference; - -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.AtomicObservableSubscription; -import rx.util.CompositeException; -import rx.util.functions.Func1; - -public final class OperationOnErrorResumeNextViaFunction { - - public static Func1, Subscription> onErrorResumeNextViaFunction(Observable originalSequence, Func1> resumeFunction) { - return new OnErrorResumeNextViaFunction<>(originalSequence, resumeFunction); - } - - private static class OnErrorResumeNextViaFunction implements Func1, Subscription> { - - private final Func1> resumeFunction; - private final Observable originalSequence; - - public OnErrorResumeNextViaFunction(Observable originalSequence, Func1> resumeFunction) { - this.resumeFunction = resumeFunction; - this.originalSequence = originalSequence; - } - - @Override - public Subscription call(final Observer observer) { - // AtomicReference since we'll be accessing/modifying this across threads so we can switch it if needed - final AtomicReference subscriptionRef = new AtomicReference<>(new AtomicObservableSubscription()); - - // subscribe to the original Observable and remember the subscription - subscriptionRef.get().wrap(new AtomicObservableSubscription(originalSequence.subscribe(new Observer() { - @Override - public void onNext(T value) { - // forward the successful calls - observer.onNext(value); - } - - /** - * Instead of passing the onError forward, we intercept and - * "resume" with the resumeSequence. - */ - @Override - public void onError(Exception ex) { - /* - * remember what the current subscription is so we can - * determine if someone unsubscribes concurrently - */ - AtomicObservableSubscription currentSubscription = subscriptionRef.get(); - // check that we have not been unsubscribed before we can process the error - if (currentSubscription != null) - try { - Observable resumeSequence = resumeFunction.call(ex); - /* - * error occurred, so switch subscription to the - * 'resumeSequence' - */ - AtomicObservableSubscription innerSubscription = new AtomicObservableSubscription(resumeSequence.subscribe(observer)); - /* - * we changed the sequence, so also change the - * subscription to the one of the 'resumeSequence' - * instead - */ - if (!subscriptionRef.compareAndSet(currentSubscription, innerSubscription)) - // we failed to set which means 'subscriptionRef' was set to NULL via the unsubscribe below - // so we want to immediately unsubscribe from the resumeSequence we just subscribed to - innerSubscription.unsubscribe(); - } catch (Exception e) { - // the resume function failed so we need to call onError - // I am using CompositeException so that both exceptions can be seen - observer.onError(new CompositeException("OnErrorResume function failed", Arrays.asList(ex, e))); - } - } - - @Override - public void onCompleted() { - // forward the successful calls - observer.onCompleted(); - } - }))); - - return () -> { - // this will get either the original, or the resumeSequence one and unsubscribe on it - Subscription s = subscriptionRef.getAndSet(null); - if (s != null) - s.unsubscribe(); - }; - } - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationOnErrorResumeNextViaObservable.java b/HMCLAPI/src/main/java/rx/operators/OperationOnErrorResumeNextViaObservable.java deleted file mode 100755 index adce8687c..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationOnErrorResumeNextViaObservable.java +++ /dev/null @@ -1,101 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import java.util.concurrent.atomic.AtomicReference; - -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.AtomicObservableSubscription; -import rx.util.functions.Func1; - -public final class OperationOnErrorResumeNextViaObservable { - - public static Func1, Subscription> onErrorResumeNextViaObservable(Observable originalSequence, Observable resumeSequence) { - return new OnErrorResumeNextViaObservable<>(originalSequence, resumeSequence); - } - - private static class OnErrorResumeNextViaObservable implements Func1, Subscription> { - - private final Observable resumeSequence; - private final Observable originalSequence; - - public OnErrorResumeNextViaObservable(Observable originalSequence, Observable resumeSequence) { - this.resumeSequence = resumeSequence; - this.originalSequence = originalSequence; - } - - public Subscription call(final Observer observer) { - final AtomicObservableSubscription subscription = new AtomicObservableSubscription(); - - // AtomicReference since we'll be accessing/modifying this across threads so we can switch it if needed - final AtomicReference subscriptionRef = new AtomicReference<>(subscription); - - // subscribe to the original Observable and remember the subscription - subscription.wrap(originalSequence.subscribe(new Observer() { - @Override - public void onNext(T value) { - // forward the successful calls - observer.onNext(value); - } - - /** - * Instead of passing the onError forward, we intercept and - * "resume" with the resumeSequence. - */ - @Override - public void onError(Exception ex) { - /* - * remember what the current subscription is so we can - * determine if someone unsubscribes concurrently - */ - AtomicObservableSubscription currentSubscription = subscriptionRef.get(); - // check that we have not been unsubscribed before we can process the error - if (currentSubscription != null) { - /* - * error occurred, so switch subscription to the - * 'resumeSequence' - */ - AtomicObservableSubscription innerSubscription = new AtomicObservableSubscription(resumeSequence.subscribe(observer)); - /* - * we changed the sequence, so also change the - * subscription to the one of the 'resumeSequence' - * instead - */ - if (!subscriptionRef.compareAndSet(currentSubscription, innerSubscription)) - // we failed to set which means 'subscriptionRef' was set to NULL via the unsubscribe below - // so we want to immediately unsubscribe from the resumeSequence we just subscribed to - innerSubscription.unsubscribe(); - } - } - - @Override - public void onCompleted() { - // forward the successful calls - observer.onCompleted(); - } - })); - - return () -> { - // this will get either the original, or the resumeSequence one and unsubscribe on it - Subscription s = subscriptionRef.getAndSet(null); - if (s != null) - s.unsubscribe(); - }; - } - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationOnErrorReturn.java b/HMCLAPI/src/main/java/rx/operators/OperationOnErrorReturn.java deleted file mode 100755 index 1771f0cb4..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationOnErrorReturn.java +++ /dev/null @@ -1,125 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import java.util.Arrays; -import java.util.concurrent.atomic.AtomicReference; - -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.AtomicObservableSubscription; -import rx.util.CompositeException; -import rx.util.functions.Func1; - -/** - * When an onError occurs the resumeFunction will be executed and it's response - * passed to onNext instead of calling onError. - */ -public final class OperationOnErrorReturn { - - public static Func1, Subscription> onErrorReturn(Observable originalSequence, Func1 resumeFunction) { - return new OnErrorReturn<>(originalSequence, resumeFunction); - } - - private static class OnErrorReturn implements Func1, Subscription> { - - private final Func1 resumeFunction; - private final Observable originalSequence; - - public OnErrorReturn(Observable originalSequence, Func1 resumeFunction) { - this.resumeFunction = resumeFunction; - this.originalSequence = originalSequence; - } - - @Override - public Subscription call(final Observer observer) { - final AtomicObservableSubscription subscription = new AtomicObservableSubscription(); - - // AtomicReference since we'll be accessing/modifying this across threads so we can switch it if needed - final AtomicReference subscriptionRef = new AtomicReference<>(subscription); - - // subscribe to the original Observable and remember the subscription - subscription.wrap(originalSequence.subscribe(new Observer() { - @Override - public void onNext(T value) { - // forward the successful calls - observer.onNext(value); - } - - /** - * Instead of passing the onError forward, we intercept and - * "resume" with the resumeSequence. - */ - @Override - public void onError(Exception ex) { - /* - * remember what the current subscription is so we can - * determine if someone unsubscribes concurrently - */ - AtomicObservableSubscription currentSubscription = subscriptionRef.get(); - // check that we have not been unsubscribed before we can process the error - if (currentSubscription != null) - try { - /* - * error occurred, so execute the function, give it - * the exception and call onNext with the response - */ - onNext(resumeFunction.call(ex)); - /* - * we are not handling an exception thrown from this - * function ... should we do something? - * error handling within an error handler is a weird - * one to determine what we should do - * right now I'm going to just let it throw whatever - * exceptions occur (such as NPE) - * but I'm considering calling the original - * Observer.onError to act as if this OnErrorReturn - * operator didn't happen - */ - - /* - * we are now completed - */ - onCompleted(); - - /* - * unsubscribe since it blew up - */ - currentSubscription.unsubscribe(); - } catch (Exception e) { - // the return function failed so we need to call onError - // I am using CompositeException so that both exceptions can be seen - observer.onError(new CompositeException("OnErrorReturn function failed", Arrays.asList(ex, e))); - } - } - - @Override - public void onCompleted() { - // forward the successful calls - observer.onCompleted(); - } - })); - - return () -> { - // this will get either the original, or the resumeSequence one and unsubscribe on it - Subscription s = subscriptionRef.getAndSet(null); - if (s != null) - s.unsubscribe(); - }; - } - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationScan.java b/HMCLAPI/src/main/java/rx/operators/OperationScan.java deleted file mode 100755 index 5f1140914..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationScan.java +++ /dev/null @@ -1,136 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.AtomicObservableSubscription; -import rx.util.functions.Func1; -import rx.util.functions.Func2; - -public final class OperationScan { - - /** - * Applies an accumulator function over an observable sequence and returns - * each intermediate result with the specified source and accumulator. - * - * @param sequence An observable sequence of elements to project. - * @param initialValue The initial (seed) accumulator value. - * @param accumulator An accumulator function to be invoked on each element - * from the sequence. - * - * @return An observable sequence whose elements are the result of - * accumulating the output from the list of Observables. - * - * @see http://msdn.microsoft.com/en-us/library/hh211665(v=vs.103).aspx - */ - public static Func1, Subscription> scan(Observable sequence, T initialValue, Func2 accumulator) { - return new Accumulator<>(sequence, initialValue, accumulator); - } - - /** - * Applies an accumulator function over an observable sequence and returns - * each intermediate result with the specified source and accumulator. - * - * @param sequence An observable sequence of elements to project. - * @param accumulator An accumulator function to be invoked on each element - * from the sequence. - * - * @return An observable sequence whose elements are the result of - * accumulating the output from the list of Observables. - * - * @see http://msdn.microsoft.com/en-us/library/hh211665(v=vs.103).aspx - */ - public static Func1, Subscription> scan(Observable sequence, Func2 accumulator) { - return new Accumulator<>(sequence, null, accumulator); - } - - private static class Accumulator implements Func1, Subscription> { - - private final Observable sequence; - private final T initialValue; - private final Func2 accumlatorFunction; - private final AtomicObservableSubscription subscription = new AtomicObservableSubscription(); - - private Accumulator(Observable sequence, T initialValue, Func2 accumulator) { - this.sequence = sequence; - this.initialValue = initialValue; - this.accumlatorFunction = accumulator; - } - - @Override - public Subscription call(final Observer observer) { - - return subscription.wrap(sequence.subscribe(new Observer() { - private T acc = initialValue; - private boolean hasSentInitialValue = false; - - /** - * We must synchronize this because we can't allow multiple - * threads to execute the 'accumulatorFunction' at the same time - * because the accumulator code very often will be doing - * mutation of the 'acc' object such as a non-threadsafe HashMap - * - * Because it's synchronized it's using non-atomic variables - * since everything in this method is single-threaded - */ - @Override - public synchronized void onNext(T value) { - if (acc == null) { - // we assume that acc is not allowed to be returned from accumulatorValue - // so it's okay to check null as being the state we initialize on - acc = value; - // this is all we do for this first value if we didn't have an initialValue - return; - } - if (!hasSentInitialValue) { - hasSentInitialValue = true; - observer.onNext(acc); - } - - try { - - acc = accumlatorFunction.call(acc, value); - if (acc == null) { - onError(new IllegalArgumentException("Null is an unsupported return value for an accumulator.")); - return; - } - observer.onNext(acc); - } catch (Exception ex) { - observer.onError(ex); - // this will work if the sequence is asynchronous, it will have no effect on a synchronous observable - subscription.unsubscribe(); - } - } - - @Override - public void onError(Exception ex) { - observer.onError(ex); - } - - // synchronized because we access 'hasSentInitialValue' - @Override - public synchronized void onCompleted() { - // if only one sequence value existed, we send it without any accumulation - if (!hasSentInitialValue) - observer.onNext(acc); - observer.onCompleted(); - } - })); - } - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationSkip.java b/HMCLAPI/src/main/java/rx/operators/OperationSkip.java deleted file mode 100755 index 45e371b83..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationSkip.java +++ /dev/null @@ -1,105 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import java.util.concurrent.atomic.AtomicInteger; - -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.functions.Func1; - -/** - * Skips a specified number of contiguous values from the start of a Observable - * sequence and then returns the remaining values. - */ -public final class OperationSkip { - - /** - * Skips a specified number of contiguous values from the start of a - * Observable sequence and then returns the remaining values. - * - * @param items - * @param num - * - * @return - * - * @see http://msdn.microsoft.com/en-us/library/hh229847(v=vs.103).aspx - */ - public static Func1, Subscription> skip(final Observable items, final int num) { - // wrap in a Observable so that if a chain is built up, then asynchronously subscribed to twice we will have 2 instances of Take rather than 1 handing both, which is not thread-safe. - return new Skip<>(items, num)::call; - } - - /** - * This class is NOT thread-safe if invoked and referenced multiple times. - * In other words, don't subscribe to it multiple times from different - * threads. - *

- * It IS thread-safe from within it while receiving onNext events from - * multiple threads. - * - * @param - */ - private static class Skip implements Func1, Subscription> { - - private final int num; - private final Observable items; - - Skip(final Observable items, final int num) { - this.num = num; - this.items = items; - } - - @Override - public Subscription call(Observer observer) { - return items.subscribe(new ItemObserver(observer)); - } - - /** - * Used to subscribe to the 'items' Observable sequence and forward to - * the actualObserver up to 'num' count. - */ - private class ItemObserver implements Observer { - - private AtomicInteger counter = new AtomicInteger(); - private final Observer observer; - - public ItemObserver(Observer observer) { - this.observer = observer; - } - - @Override - public void onCompleted() { - observer.onCompleted(); - } - - @Override - public void onError(Exception e) { - observer.onError(e); - } - - @Override - public void onNext(T args) { - // skip them until we reach the 'num' value - if (counter.incrementAndGet() > num) - observer.onNext(args); - } - - } - - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationSubscribeOn.java b/HMCLAPI/src/main/java/rx/operators/OperationSubscribeOn.java deleted file mode 100755 index 6946fb40b..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationSubscribeOn.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import rx.Observable; -import rx.Observer; -import rx.Scheduler; -import rx.Subscription; -import rx.util.functions.Func1; - -public class OperationSubscribeOn { - - public static Func1, Subscription> subscribeOn(Observable source, Scheduler scheduler) { - return new SubscribeOn<>(source, scheduler); - } - - private static class SubscribeOn implements Func1, Subscription> { - - private final Observable source; - private final Scheduler scheduler; - - public SubscribeOn(Observable source, Scheduler scheduler) { - this.source = source; - this.scheduler = scheduler; - } - - @Override - public Subscription call(final Observer observer) { - return scheduler.schedule(() -> new ScheduledSubscription(source.subscribe(observer), scheduler)); - } - } - - private static class ScheduledSubscription implements Subscription { - - private final Subscription underlying; - private final Scheduler scheduler; - - private ScheduledSubscription(Subscription underlying, Scheduler scheduler) { - this.underlying = underlying; - this.scheduler = scheduler; - } - - @Override - public void unsubscribe() { - scheduler.schedule(underlying::unsubscribe); - } - } - -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationSynchronize.java b/HMCLAPI/src/main/java/rx/operators/OperationSynchronize.java deleted file mode 100755 index ea3118873..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationSynchronize.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.AtomicObservableSubscription; -import rx.util.SynchronizedObserver; -import rx.util.functions.Func1; - -/** - * An observable that wraps an observable of the same type and then enforces the - * semantics expected of a well-behaved observable. - *

- * An observable that ensures onNext, onCompleted, or onError calls on its - * subscribers are not interleaved, onCompleted and onError are only called once - * respectively, and no onNext calls follow onCompleted and onError calls. - *

- * NOTE: {@link Observable#create} already wraps Observables so this is - * generally redundant. - * - * @param The type of the observable sequence. - */ -public final class OperationSynchronize { - - /** - * Accepts an observable and wraps it in another observable which ensures - * that the resulting observable is well-behaved. - * - * A well-behaved observable ensures onNext, onCompleted, or onError calls - * to its subscribers are not interleaved, onCompleted and onError are only - * called once respectively, and no onNext calls follow onCompleted and - * onError calls. - * - * @param observable - * @param - * - * @return - */ - public static Func1, Subscription> synchronize(Observable observable) { - return new Synchronize<>(observable); - } - - private static class Synchronize implements Func1, Subscription> { - - public Synchronize(Observable innerObservable) { - this.innerObservable = innerObservable; - } - - private final Observable innerObservable; - private SynchronizedObserver atomicObserver; - - @Override - public Subscription call(Observer observer) { - AtomicObservableSubscription subscription = new AtomicObservableSubscription(); - atomicObserver = new SynchronizedObserver<>(observer, subscription); - return subscription.wrap(innerObservable.subscribe(atomicObserver)); - } - - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationTake.java b/HMCLAPI/src/main/java/rx/operators/OperationTake.java deleted file mode 100755 index 4ebc51a17..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationTake.java +++ /dev/null @@ -1,135 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import java.util.concurrent.atomic.AtomicInteger; - -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.subscriptions.Subscriptions; -import rx.util.AtomicObservableSubscription; -import rx.util.functions.Func1; - -/** - * Returns a specified number of contiguous values from the start of an - * observable sequence. - */ -public final class OperationTake { - - /** - * Returns a specified number of contiguous values from the start of an - * observable sequence. - * - * @param items - * @param num - * - * @return - */ - public static Func1, Subscription> take(final Observable items, final int num) { - // wrap in a Func so that if a chain is built up, then asynchronously subscribed to twice we will have 2 instances of Take rather than 1 handing both, which is not thread-safe. - return new Take<>(items, num)::call; - } - - /** - * This class is NOT thread-safe if invoked and referenced multiple times. - * In other words, don't subscribe to it multiple times from different - * threads. - *

- * It IS thread-safe from within it while receiving onNext events from - * multiple threads. - *

- * This should all be fine as long as it's kept as a private class and a new - * instance created from static factory method above. - *

- * Note how the take() factory method above protects us from a single - * instance being exposed with the Observable wrapper handling the subscribe - * flow. - * - * @param - */ - private static class Take implements Func1, Subscription> { - - private final AtomicInteger counter = new AtomicInteger(); - private final Observable items; - private final int num; - private final AtomicObservableSubscription subscription = new AtomicObservableSubscription(); - - private Take(Observable items, int num) { - this.items = items; - this.num = num; - } - - @Override - public Subscription call(Observer observer) { - if (num < 1) { - items.subscribe(new Observer() { - @Override - public void onCompleted() { - } - - @Override - public void onError(Exception e) { - } - - @Override - public void onNext(T args) { - } - }).unsubscribe(); - observer.onCompleted(); - return Subscriptions.empty(); - } - - return subscription.wrap(items.subscribe(new ItemObserver(observer))); - } - - private class ItemObserver implements Observer { - - private final Observer observer; - - public ItemObserver(Observer observer) { - this.observer = observer; - } - - @Override - public void onCompleted() { - if (counter.getAndSet(num) < num) - observer.onCompleted(); - } - - @Override - public void onError(Exception e) { - if (counter.getAndSet(num) < num) - observer.onError(e); - } - - @Override - public void onNext(T args) { - final int count = counter.incrementAndGet(); - if (count <= num) { - observer.onNext(args); - if (count == num) - observer.onCompleted(); - } - if (count >= num) - // this will work if the sequence is asynchronous, it will have no effect on a synchronous observable - subscription.unsubscribe(); - } - - } - - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationTakeLast.java b/HMCLAPI/src/main/java/rx/operators/OperationTakeLast.java deleted file mode 100755 index 52164046e..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationTakeLast.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import java.util.Iterator; -import java.util.concurrent.LinkedBlockingDeque; - -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.AtomicObservableSubscription; -import rx.util.functions.Func1; - -/** - * Returns a specified number of contiguous elements from the end of an - * observable sequence. - */ -public final class OperationTakeLast { - - public static Func1, Subscription> takeLast(final Observable items, final int count) { - return new TakeLast<>(items, count)::call; - } - - private static class TakeLast implements Func1, Subscription> { - - private final int count; - private final Observable items; - private final AtomicObservableSubscription subscription = new AtomicObservableSubscription(); - - TakeLast(final Observable items, final int count) { - this.count = count; - this.items = items; - } - - @Override - public Subscription call(Observer observer) { - return subscription.wrap(items.subscribe(new ItemObserver(observer))); - } - - private class ItemObserver implements Observer { - - private LinkedBlockingDeque deque = new LinkedBlockingDeque<>(count); - private final Observer observer; - - public ItemObserver(Observer observer) { - this.observer = observer; - } - - @Override - public void onCompleted() { - Iterator reverse = deque.descendingIterator(); - while (reverse.hasNext()) - observer.onNext(reverse.next()); - observer.onCompleted(); - } - - @Override - public void onError(Exception e) { - observer.onError(e); - } - - @Override - public void onNext(T args) { - while (!deque.offerFirst(args)) - deque.removeLast(); - } - - } - - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationTakeWhile.java b/HMCLAPI/src/main/java/rx/operators/OperationTakeWhile.java deleted file mode 100755 index 801cedba6..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationTakeWhile.java +++ /dev/null @@ -1,144 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import java.util.concurrent.atomic.AtomicInteger; - -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.AtomicObservableSubscription; -import rx.util.AtomicObserver; -import rx.util.functions.Func1; -import rx.util.functions.Func2; - -/** - * Returns values from an observable sequence as long as a specified condition - * is true, and then skips the remaining values. - */ -public final class OperationTakeWhile { - - /** - * Returns a specified number of contiguous values from the start of an - * observable sequence. - * - * @param items - * @param predicate a function to test each source element for a condition - * - * @return - */ - public static Func1, Subscription> takeWhile(final Observable items, final Func1 predicate) { - return takeWhileWithIndex(items, OperationTakeWhile.skipIndex(predicate)); - } - - /** - * Returns values from an observable sequence as long as a specified - * condition is true, and then skips the remaining values. - * - * @param items - * @param predicate a function to test each element for a condition; the - * second parameter of the function represents the index of the source - * element; otherwise, false. - * - * @return - */ - public static Func1, Subscription> takeWhileWithIndex(final Observable items, final Func2 predicate) { - // wrap in a Func so that if a chain is built up, then asynchronously subscribed to twice we will have 2 instances of Take rather than 1 handing both, which is not thread-safe. - return new TakeWhile(items, predicate)::call; - } - - private static Func2 skipIndex(final Func1 underlying) { - return (T input, Integer index) -> underlying.call(input); - } - - /** - * This class is NOT thread-safe if invoked and referenced multiple times. - * In other words, don't subscribe to it multiple times from different - * threads. - *

- * It IS thread-safe from within it while receiving onNext events from - * multiple threads. - *

- * This should all be fine as long as it's kept as a private class and a new - * instance created from static factory method above. - *

- * Note how the takeWhileWithIndex() factory method above protects us from a - * single instance being exposed with the Observable wrapper handling the - * subscribe flow. - * - * @param - */ - private static class TakeWhile implements Func1, Subscription> { - - private final AtomicInteger counter = new AtomicInteger(); - private final Observable items; - private final Func2 predicate; - private final AtomicObservableSubscription subscription = new AtomicObservableSubscription(); - - private TakeWhile(Observable items, Func2 predicate) { - this.items = items; - this.predicate = predicate; - } - - @Override - public Subscription call(Observer observer) { - return subscription.wrap(items.subscribe(new ItemObserver(observer))); - } - - private class ItemObserver implements Observer { - - private final Observer observer; - - public ItemObserver(Observer observer) { - // Using AtomicObserver because the unsubscribe, onCompleted, onError and error handling behavior - // needs "isFinished" logic to not send duplicated events - // The 'testTakeWhile1' and 'testTakeWhile2' tests fail without this. - this.observer = new AtomicObserver<>(subscription, observer); - } - - @Override - public void onCompleted() { - observer.onCompleted(); - } - - @Override - public void onError(Exception e) { - observer.onError(e); - } - - @Override - public void onNext(T args) { - Boolean isSelected; - try { - isSelected = predicate.call(args, counter.getAndIncrement()); - } catch (Exception e) { - observer.onError(e); - return; - } - if (isSelected) - observer.onNext(args); - else { - observer.onCompleted(); - // this will work if the sequence is asynchronous, it will have no effect on a synchronous observable - subscription.unsubscribe(); - } - } - - } - - } - -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationToObservableFuture.java b/HMCLAPI/src/main/java/rx/operators/OperationToObservableFuture.java deleted file mode 100755 index bb2a4402c..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationToObservableFuture.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; - -import rx.Observer; -import rx.Subscription; -import rx.subscriptions.Subscriptions; -import rx.util.functions.Func1; - -public class OperationToObservableFuture { - - private static class ToObservableFuture implements Func1, Subscription> { - - private final Future that; - private final Long time; - private final TimeUnit unit; - - public ToObservableFuture(Future that) { - this.that = that; - this.time = null; - this.unit = null; - } - - public ToObservableFuture(Future that, long time, TimeUnit unit) { - this.that = that; - this.time = time; - this.unit = unit; - } - - @Override - public Subscription call(Observer observer) { - try { - T value = (time == null) ? that.get() : that.get(time, unit); - - if (!that.isCancelled()) - observer.onNext(value); - observer.onCompleted(); - } catch (Exception e) { - observer.onError(e); - } - - // the get() has already completed so there is no point in - // giving the user a way to cancel. - return Subscriptions.empty(); - } - } - - public static Func1, Subscription> toObservableFuture(final Future that) { - return new ToObservableFuture<>(that); - } - - public static Func1, Subscription> toObservableFuture(final Future that, long time, TimeUnit unit) { - return new ToObservableFuture<>(that, time, unit); - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationToObservableIterable.java b/HMCLAPI/src/main/java/rx/operators/OperationToObservableIterable.java deleted file mode 100755 index aa5df40b9..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationToObservableIterable.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import rx.Observer; -import rx.Subscription; -import rx.subscriptions.Subscriptions; -import rx.util.functions.Func1; - -/** - * Accepts an Iterable object and exposes it as an Observable. - * - * @param The type of the Iterable sequence. - */ -public final class OperationToObservableIterable { - - public static Func1, Subscription> toObservableIterable(Iterable iterable) { - return (Observer observer) -> { - for (T item : iterable) - observer.onNext(item); - observer.onCompleted(); - - return Subscriptions.empty(); - }; - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationToObservableList.java b/HMCLAPI/src/main/java/rx/operators/OperationToObservableList.java deleted file mode 100755 index bdc3ca1c6..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationToObservableList.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ConcurrentLinkedQueue; - -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.functions.Func1; - -public final class OperationToObservableList { - - public static Func1>, Subscription> toObservableList(Observable that) { - return new ToObservableList<>(that); - } - - private static class ToObservableList implements Func1>, Subscription> { - - private final Observable that; - - public ToObservableList(Observable that) { - this.that = that; - } - - @Override - public Subscription call(final Observer> observer) { - - return that.subscribe(new Observer() { - final ConcurrentLinkedQueue list = new ConcurrentLinkedQueue<>(); - - @Override - public void onNext(T value) { - // onNext can be concurrently executed so list must be thread-safe - list.add(value); - } - - @Override - public void onError(Exception ex) { - observer.onError(ex); - } - - @Override - public void onCompleted() { - try { - // copy from LinkedQueue to List since ConcurrentLinkedQueue does not implement the List interface - ArrayList l = new ArrayList<>(list.size()); - for (T t : list) - l.add(t); - - // benjchristensen => I want to make this list immutable but some clients are sorting this - // instead of using toSortedList() and this change breaks them until we migrate their code. - // observer.onNext(Collections.unmodifiableList(l)); - observer.onNext(l); - observer.onCompleted(); - } catch (Exception e) { - onError(e); - } - - } - }); - } - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationToObservableSortedList.java b/HMCLAPI/src/main/java/rx/operators/OperationToObservableSortedList.java deleted file mode 100755 index 14748e231..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationToObservableSortedList.java +++ /dev/null @@ -1,131 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.ConcurrentLinkedQueue; - -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.functions.Func1; -import rx.util.functions.Func2; - -/** - * Similar to toList in that it converts a sequence into a List except - * that it accepts a Function that will provide an implementation of Comparator. - * - * @param - */ -public final class OperationToObservableSortedList { - - /** - * Sort T objects by their natural order (object must implement Comparable). - * - * @param sequence - * - * @throws ClassCastException if T objects do not implement Comparable - * @return - */ - public static Func1>, Subscription> toSortedList(Observable sequence) { - return new ToObservableSortedList<>(sequence); - } - - /** - * Sort T objects using the defined sort function. - * - * @param sequence - * @param sortFunction - * - * @return - */ - public static Func1>, Subscription> toSortedList(Observable sequence, Func2 sortFunction) { - return new ToObservableSortedList<>(sequence, sortFunction); - } - - private static class ToObservableSortedList implements Func1>, Subscription> { - - private final Observable that; - private final ConcurrentLinkedQueue list = new ConcurrentLinkedQueue<>(); - private final Func2 sortFunction; - - // unchecked as we're support Object for the default - @SuppressWarnings("unchecked") - private ToObservableSortedList(Observable that) { - this(that, defaultSortFunction); - } - - private ToObservableSortedList(Observable that, Func2 sortFunction) { - this.that = that; - this.sortFunction = sortFunction; - } - - @Override - public Subscription call(final Observer> observer) { - return that.subscribe(new Observer() { - @Override - public void onNext(T value) { - // onNext can be concurrently executed so list must be thread-safe - list.add(value); - } - - @Override - public void onError(Exception ex) { - observer.onError(ex); - } - - @Override - public void onCompleted() { - try { - // copy from LinkedQueue to List since ConcurrentLinkedQueue does not implement the List interface - ArrayList l = new ArrayList<>(list.size()); - for (T t : list) - l.add(t); - - // sort the list before delivery - Collections.sort(l, (T o1, T o2) -> sortFunction.call(o1, o2)); - - observer.onNext(Collections.unmodifiableList(l)); - observer.onCompleted(); - } catch (Exception e) { - onError(e); - } - - } - }); - } - - // raw because we want to support Object for this default - @SuppressWarnings("rawtypes") - private static Func2 defaultSortFunction = new DefaultComparableFunction(); - - private static class DefaultComparableFunction implements Func2 { - - // unchecked because we want to support Object for this default - @SuppressWarnings("unchecked") - @Override - public Integer call(Object t1, Object t2) { - Comparable c1 = (Comparable) t1; - Comparable c2 = (Comparable) t2; - return c1.compareTo(c2); - } - - } - - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationWhere.java b/HMCLAPI/src/main/java/rx/operators/OperationWhere.java deleted file mode 100755 index 4e08aa70c..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationWhere.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.functions.Func1; - -public final class OperationWhere { - - public static Func1, Subscription> where(Observable that, Func1 predicate) { - return OperationFilter.filter(that, predicate); - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperationZip.java b/HMCLAPI/src/main/java/rx/operators/OperationZip.java deleted file mode 100755 index 861217305..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperationZip.java +++ /dev/null @@ -1,284 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.atomic.AtomicBoolean; - -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.AtomicObservableSubscription; -import rx.util.SynchronizedObserver; -import rx.util.functions.Func1; -import rx.util.functions.Func2; -import rx.util.functions.Func3; -import rx.util.functions.Func4; -import rx.util.functions.FuncN; -import rx.util.functions.Functions; - -public final class OperationZip { - - public static Func1, Subscription> zip(Observable w0, Observable w1, Func2 zipFunction) { - Aggregator a = new Aggregator<>(Functions.fromFunc(zipFunction)); - a.addObserver(new ZipObserver<>(a, w0)); - a.addObserver(new ZipObserver<>(a, w1)); - return a; - } - - public static Func1, Subscription> zip(Observable w0, Observable w1, Observable w2, Func3 zipFunction) { - Aggregator a = new Aggregator<>(Functions.fromFunc(zipFunction)); - a.addObserver(new ZipObserver<>(a, w0)); - a.addObserver(new ZipObserver<>(a, w1)); - a.addObserver(new ZipObserver<>(a, w2)); - return a; - } - - public static Func1, Subscription> zip(Observable w0, Observable w1, Observable w2, Observable w3, Func4 zipFunction) { - Aggregator a = new Aggregator<>(Functions.fromFunc(zipFunction)); - a.addObserver(new ZipObserver<>(a, w0)); - a.addObserver(new ZipObserver<>(a, w1)); - a.addObserver(new ZipObserver<>(a, w2)); - a.addObserver(new ZipObserver<>(a, w3)); - return a; - } - - /* - * ThreadSafe - */ - private static class ZipObserver implements Observer { - - final Observable w; - final Aggregator a; - private final AtomicObservableSubscription subscription = new AtomicObservableSubscription(); - private final AtomicBoolean subscribed = new AtomicBoolean(false); - - public ZipObserver(Aggregator a, Observable w) { - this.a = a; - this.w = w; - } - - public void startWatching() { - if (subscribed.compareAndSet(false, true)) - // only subscribe once even if called more than once - subscription.wrap(w.subscribe(this)); - } - - @Override - public void onCompleted() { - a.complete(this); - } - - @Override - public void onError(Exception e) { - a.error(this, e); - } - - @Override - public void onNext(T args) { - try { - a.next(this, args); - } catch (Exception e) { - onError(e); - } - } - } - - /** - * Receive notifications from each of the Observables we are reducing and - * execute the zipFunction whenever we have received events from all - * Observables. - * - * This class is thread-safe. - * - * @param - */ - private static class Aggregator implements Func1, Subscription> { - - private volatile SynchronizedObserver observer; - private final FuncN zipFunction; - private final AtomicBoolean started = new AtomicBoolean(false); - private final AtomicBoolean running = new AtomicBoolean(true); - private final ConcurrentHashMap, Boolean> completed = new ConcurrentHashMap<>(); - - /* - * we use ConcurrentHashMap despite synchronization of methods because - * stop() does NOT use synchronization and this map is used by it and - * can be called by other threads - */ - private final ConcurrentHashMap, ConcurrentLinkedQueue> receivedValuesPerObserver = new ConcurrentHashMap<>(); - /* - * we use a ConcurrentLinkedQueue to retain ordering (I'd like to just - * use a ConcurrentLinkedHashMap for 'receivedValuesPerObserver' but - * that doesn't exist in standard java - */ - private final ConcurrentLinkedQueue> observers = new ConcurrentLinkedQueue<>(); - - public Aggregator(FuncN zipFunction) { - this.zipFunction = zipFunction; - } - - /** - * Receive notification of a Observer starting (meaning we should - * require it for aggregation) - * - * Thread Safety => Invoke ONLY from the static factory methods at top - * of this class which are always an atomic execution by a single - * thread. - * - * @param w - */ - private void addObserver(ZipObserver w) { - // initialize this ZipObserver - observers.add(w); - receivedValuesPerObserver.put(w, new ConcurrentLinkedQueue<>()); - } - - /** - * Receive notification of a Observer completing its iterations. - * - * @param w - */ - void complete(ZipObserver w) { - // store that this ZipObserver is completed - completed.put(w, Boolean.TRUE); - // if all ZipObservers are completed, we mark the whole thing as completed - if (completed.size() == observers.size()) - if (running.compareAndSet(true, false)) - // this thread succeeded in setting running=false so let's propagate the completion - // mark ourselves as done - observer.onCompleted(); - } - - /** - * Receive error for a Observer. Throw the error up the chain and stop - * processing. - * - * @param w - */ - void error(ZipObserver w, Exception e) { - if (running.compareAndSet(true, false)) { - // this thread succeeded in setting running=false so let's propagate the error - observer.onError(e); - /* - * since we receive an error we want to tell everyone to stop - */ - stop(); - } - } - - /** - * Receive the next value from a Observer. - *

- * If we have received values from all Observers, trigger the zip - * function, otherwise store the value and keep waiting. - * - * @param w - * @param arg - */ - void next(ZipObserver w, Object arg) { - if (observer == null) - throw new RuntimeException("This shouldn't be running if a Observer isn't registered"); - - /* - * if we've been 'unsubscribed' don't process anything further even - * if the things we're watching keep sending (likely because they - * are not responding to the unsubscribe call) - */ - if (!running.get()) - return; - - // store the value we received and below we'll decide if we are to send it to the Observer - receivedValuesPerObserver.get(w).add(arg); - - // define here so the variable is out of the synchronized scope - Object[] argsToZip = new Object[observers.size()]; - - /* - * we have to synchronize here despite using concurrent data - * structures because the compound logic here must all be done - * atomically - */ - synchronized (this) { - // if all ZipObservers in 'receivedValues' map have a value, invoke the zipFunction - for (ZipObserver rw : receivedValuesPerObserver.keySet()) - if (receivedValuesPerObserver.get(rw).peek() == null) - // we have a null meaning the queues aren't all populated so won't do anything - return; - // if we get to here this means all the queues have data - int i = 0; - for (ZipObserver rw : observers) - argsToZip[i++] = receivedValuesPerObserver.get(rw).remove(); - } - // if we did not return above from the synchronized block we can now invoke the zipFunction with all of the args - // we do this outside the synchronized block as it is now safe to call this concurrently and don't need to block other threads from calling - // this 'next' method while another thread finishes calling this zipFunction - observer.onNext(zipFunction.call(argsToZip)); - } - - @Override - public Subscription call(Observer observer) { - if (started.compareAndSet(false, true)) { - AtomicObservableSubscription subscription = new AtomicObservableSubscription(); - this.observer = new SynchronizedObserver<>(observer, subscription); - /* - * start the Observers - */ - for (ZipObserver rw : observers) - rw.startWatching(); - - return subscription.wrap(this::stop); - } else - /* - * a Observer already has subscribed so blow up - */ - throw new IllegalStateException("Only one Observer can subscribe to this Observable."); - } - - /* - * Do NOT synchronize this because it gets called via unsubscribe which - * can occur on other threads - * and result in deadlocks. (http://jira/browse/API-4060) - * - * AtomicObservableSubscription uses compareAndSet instead of locking to - * avoid deadlocks but ensure single-execution. - * - * We do the same in the implementation of this method. - * - * ThreadSafety of this method is provided by: - * - AtomicBoolean[running].compareAndSet - * - ConcurrentLinkedQueue[Observers] - * - ZipObserver.subscription being an AtomicObservableSubscription - */ - private void stop() { - /* - * tell ourselves to stop processing onNext events by setting - * running=false - */ - if (running.compareAndSet(true, false)) - /* - * propogate to all Observers to unsubscribe if this thread - * succeeded in setting running=false - */ - for (ZipObserver o : observers) - if (o.subscription != null) - o.subscription.unsubscribe(); - } - - } - -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperatorGroupBy.java b/HMCLAPI/src/main/java/rx/operators/OperatorGroupBy.java deleted file mode 100755 index 09b3b464b..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperatorGroupBy.java +++ /dev/null @@ -1,117 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import java.util.concurrent.ConcurrentHashMap; - -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.observables.GroupedObservable; -import rx.util.functions.Func1; -import rx.util.functions.Functions; - -public final class OperatorGroupBy { - - public static Func1>, Subscription> groupBy(Observable source, final Func1 keySelector, final Func1 elementSelector) { - - final Observable> keyval = source.map(new Func1>() { - @Override - public KeyValue call(T t) { - K key = keySelector.call(t); - R value = elementSelector.call(t); - - return new KeyValue(key, value); - } - }); - - return new GroupBy(keyval); - } - - public static Func1>, Subscription> groupBy(Observable source, final Func1 keySelector) { - return groupBy(source, keySelector, Functions.identity()); - } - - private static class GroupBy implements Func1>, Subscription> { - - private final Observable> source; - private final ConcurrentHashMap keys = new ConcurrentHashMap(); - - private GroupBy(Observable> source) { - this.source = source; - } - - @Override - public Subscription call(final Observer> observer) { - - return source.subscribe(new Observer>() { - - @Override - public void onCompleted() { - observer.onCompleted(); - } - - @Override - public void onError(Exception e) { - observer.onError(e); - } - - @Override - public void onNext(final KeyValue args) { - K key = args.key; - boolean newGroup = keys.putIfAbsent(key, true) == null; - if (newGroup) - observer.onNext(buildObservableFor(source, key)); - } - - }); - } - } - - private static GroupedObservable buildObservableFor(Observable> source, final K key) { - final Observable observable = source.filter(new Func1, Boolean>() { - @Override - public Boolean call(KeyValue pair) { - return key.equals(pair.key); - } - }).map(new Func1, R>() { - @Override - public R call(KeyValue pair) { - return pair.value; - } - }); - return new GroupedObservable(key, new Func1, Subscription>() { - - @Override - public Subscription call(Observer observer) { - return observable.subscribe(observer); - } - - }); - } - - private static class KeyValue { - - private final K key; - private final V value; - - private KeyValue(K key, V value) { - this.key = key; - this.value = value; - } - } - -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperatorTakeUntil.java b/HMCLAPI/src/main/java/rx/operators/OperatorTakeUntil.java deleted file mode 100755 index 128419dff..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperatorTakeUntil.java +++ /dev/null @@ -1,141 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.functions.Func1; - -public class OperatorTakeUntil { - - /** - * Returns the values from the source observable sequence until the other - * observable sequence produces a value. - * - * @param source the source sequence to propagate elements for. - * @param other the observable sequence that terminates propagation of - * elements of the source sequence. - * @param the type of source. - * @param the other type. - * - * @return An observable sequence containing the elements of the source - * sequence up to the point the other sequence interrupted further - * propagation. - */ - public static Observable takeUntil(final Observable source, final Observable other) { - Observable> s = Observable.create(new SourceObservable(source)); - Observable> o = Observable.create(new OtherObservable(other)); - - @SuppressWarnings("unchecked") - /** - * In JDK 7 we could use 'varargs' instead of 'unchecked'. See - * http://stackoverflow.com/questions/1445233/is-it-possible-to-solve-the-a-generic-array-of-t-is-created-for-a-varargs-param - * and http://hg.openjdk.java.net/jdk7/tl/langtools/rev/46cf751559ae - */ - Observable> result = Observable.merge(s, o); - - return result.takeWhile(new Func1, Boolean>() { - @Override - public Boolean call(Notification notification) { - return !notification.halt; - } - }).map(new Func1, T>() { - @Override - public T call(Notification notification) { - return notification.value; - } - }); - } - - private static class Notification { - - private final boolean halt; - private final T value; - - public static Notification value(T value) { - return new Notification(false, value); - } - - public static Notification halt() { - return new Notification(true, null); - } - - private Notification(boolean halt, T value) { - this.halt = halt; - this.value = value; - } - - } - - private static class SourceObservable implements Func1>, Subscription> { - - private final Observable sequence; - - private SourceObservable(Observable sequence) { - this.sequence = sequence; - } - - @Override - public Subscription call(final Observer> notificationObserver) { - return sequence.subscribe(new Observer() { - @Override - public void onCompleted() { - notificationObserver.onNext(Notification.halt()); - } - - @Override - public void onError(Exception e) { - notificationObserver.onError(e); - } - - @Override - public void onNext(T args) { - notificationObserver.onNext(Notification.value(args)); - } - }); - } - } - - private static class OtherObservable implements Func1>, Subscription> { - - private final Observable sequence; - - private OtherObservable(Observable sequence) { - this.sequence = sequence; - } - - @Override - public Subscription call(final Observer> notificationObserver) { - return sequence.subscribe(new Observer() { - @Override - public void onCompleted() { - // Ignore - } - - @Override - public void onError(Exception e) { - notificationObserver.onError(e); - } - - @Override - public void onNext(E args) { - notificationObserver.onNext(Notification.halt()); - } - }); - } - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/OperatorToIterator.java b/HMCLAPI/src/main/java/rx/operators/OperatorToIterator.java deleted file mode 100755 index 61d63f0b7..000000000 --- a/HMCLAPI/src/main/java/rx/operators/OperatorToIterator.java +++ /dev/null @@ -1,82 +0,0 @@ -package rx.operators; - -import java.util.Iterator; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; - -import rx.Notification; -import rx.Observable; -import rx.Observer; -import rx.util.Exceptions; - -/** - * @see https://github.com/Netflix/RxJava/issues/50 - */ -public class OperatorToIterator { - - /** - * Returns an iterator that iterates all values of the observable. - * - * @param that an observable sequence to get an iterator for. - * @param the type of source. - * - * @return the iterator that could be used to iterate over the elements of - * the observable. - */ - public static Iterator toIterator(Observable that) { - final BlockingQueue> notifications = new LinkedBlockingQueue>(); - - Observable.materialize(that).subscribe(new Observer>() { - @Override - public void onCompleted() { - // ignore - } - - @Override - public void onError(Exception e) { - // ignore - } - - @Override - public void onNext(Notification args) { - notifications.offer(args); - } - }); - - return new Iterator() { - private Notification buf; - - @Override - public boolean hasNext() { - if (buf == null) - buf = take(); - return !buf.isOnCompleted(); - } - - @Override - public T next() { - if (buf == null) - buf = take(); - if (buf.isOnError()) - throw Exceptions.propagate(buf.getException()); - - T result = buf.getValue(); - buf = null; - return result; - } - - private Notification take() { - try { - return notifications.take(); - } catch (InterruptedException e) { - throw Exceptions.propagate(e); - } - } - - @Override - public void remove() { - throw new UnsupportedOperationException("Read-only iterator"); - } - }; - } -} diff --git a/HMCLAPI/src/main/java/rx/operators/ScheduledObserver.java b/HMCLAPI/src/main/java/rx/operators/ScheduledObserver.java deleted file mode 100755 index da43d0adc..000000000 --- a/HMCLAPI/src/main/java/rx/operators/ScheduledObserver.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.operators; - -import rx.Observer; -import rx.Scheduler; -import rx.util.functions.Action0; - -/* - * package - */ -class ScheduledObserver implements Observer { - - private final Observer underlying; - private final Scheduler scheduler; - - public ScheduledObserver(Observer underlying, Scheduler scheduler) { - this.underlying = underlying; - this.scheduler = scheduler; - } - - @Override - public void onCompleted() { - scheduler.schedule(() -> { - underlying.onCompleted(); - }); - } - - @Override - public void onError(final Exception e) { - scheduler.schedule(() -> underlying.onError(e)); - } - - @Override - public void onNext(final T args) { - scheduler.schedule(() -> { - underlying.onNext(args); - }); - } -} diff --git a/HMCLAPI/src/main/java/rx/plugins/RxJavaErrorHandler.java b/HMCLAPI/src/main/java/rx/plugins/RxJavaErrorHandler.java deleted file mode 100755 index acbbcc605..000000000 --- a/HMCLAPI/src/main/java/rx/plugins/RxJavaErrorHandler.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.plugins; - -import rx.Observable; -import rx.Observer; - -/** - * Abstract class for defining error handling logic in addition to the normal - * {@link Observer#onError(Exception)} behavior. - *

- * For example, all Exceptions can be logged using this handler even if - * {@link Observer#onError(Exception)} is ignored or not provided when an - * {@link Observable} is subscribed to. - *

- * See {@link RxJavaPlugins} or the RxJava GitHub Wiki for information on - * configuring plugins: https://github.com/Netflix/RxJava/wiki/Plugins. - */ -public abstract class RxJavaErrorHandler { - - /** - * Receives all Exceptions from an {@link Observable} passed to - * {@link Observer#onError(Exception)}. - * - * @param e Exception - */ - public void handleError(Exception e) { - // do nothing by default - } - -} diff --git a/HMCLAPI/src/main/java/rx/plugins/RxJavaErrorHandlerDefault.java b/HMCLAPI/src/main/java/rx/plugins/RxJavaErrorHandlerDefault.java deleted file mode 100755 index ab9604123..000000000 --- a/HMCLAPI/src/main/java/rx/plugins/RxJavaErrorHandlerDefault.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.plugins; - -/** - * Default implementation of {@link RxJavaErrorHandler} that does nothing. - * - * @ExcludeFromJavadoc - */ -public class RxJavaErrorHandlerDefault extends RxJavaErrorHandler { - - private static RxJavaErrorHandlerDefault INSTANCE = new RxJavaErrorHandlerDefault(); - - public static RxJavaErrorHandler getInstance() { - return INSTANCE; - } - -} diff --git a/HMCLAPI/src/main/java/rx/plugins/RxJavaObservableExecutionHook.java b/HMCLAPI/src/main/java/rx/plugins/RxJavaObservableExecutionHook.java deleted file mode 100755 index 55f111437..000000000 --- a/HMCLAPI/src/main/java/rx/plugins/RxJavaObservableExecutionHook.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.plugins; - -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.functions.Func1; - -/** - * Abstract ExecutionHook with invocations at different lifecycle points of - * {@link Observable} execution with a default no-op implementation. - *

- * See {@link RxJavaPlugins} or the RxJava GitHub Wiki for information on - * configuring plugins: https://github.com/Netflix/RxJava/wiki/Plugins. - *

- * Note on thread-safety and performance - *

- * A single implementation of this class will be used globally so methods on - * this class will be invoked concurrently from multiple threads so all - * functionality must be thread-safe. - *

- * Methods are also invoked synchronously and will add to execution time of the - * observable so all behavior should be fast. If anything time-consuming is to - * be done it should be spawned asynchronously onto separate worker threads. - * - * - */ -public abstract class RxJavaObservableExecutionHook { - - /** - * Invoked before {@link Observable#subscribe(rx.Observer)} is about to be - * executed. - *

- * This can be used to decorate or replace the onSubscribe - * function or just perform extra logging, metrics and other such things and - * pass-thru the function. - * - * @param observableInstance The executing {@link Observable} instance. - * @param onSubscribe original {@link Func1}<{@link - * Observer}{@code}, - * {@link Subscription}> to be executed - * - * @return {@link Func1}<{@link Observer}{@code}, {@link Subscription}> - * function that can be modified, decorated, replaced or just returned as a - * pass-thru. - */ - public Func1, Subscription> onSubscribeStart(Observable observableInstance, Func1, Subscription> onSubscribe) { - // pass-thru by default - return onSubscribe; - } - - /** - * Invoked after successful execution of - * {@link Observable#subscribe(rx.Observer)} with returned - * {@link Subscription}. - *

- * This can be used to decorate or replace the {@link Subscription} instance - * or just perform extra logging, metrics and other such things and - * pass-thru the subscription. - * - * @param observableInstance The executing {@link Observable} instance. - * @param subscription original {@link Subscription} - * - * @return {@link Subscription} subscription that can be modified, - * decorated, replaced or just returned as a pass-thru. - */ - public Subscription onSubscribeReturn(Observable observableInstance, Subscription subscription) { - // pass-thru by default - return subscription; - } - - /** - * Invoked after failed execution of {@link Observable#subscribe(Observer)} - * with thrown Exception. - *

- * This is NOT errors emitted via {@link Observer#onError(Exception)} but - * exceptions thrown when attempting to subscribe to a {@link Func1}<{@link - * Observer}{@code}, {@link Subscription}>. - * - * @param observableInstance The executing {@link Observable} instance. - * @param e Exception thrown by - * {@link Observable#subscribe(Observer)} - * - * @return Exception that can be decorated, replaced or just returned as a - * pass-thru. - */ - public Exception onSubscribeError(Observable observableInstance, Exception e) { - // pass-thru by default - return e; - } - -} diff --git a/HMCLAPI/src/main/java/rx/plugins/RxJavaObservableExecutionHookDefault.java b/HMCLAPI/src/main/java/rx/plugins/RxJavaObservableExecutionHookDefault.java deleted file mode 100755 index eeff228b4..000000000 --- a/HMCLAPI/src/main/java/rx/plugins/RxJavaObservableExecutionHookDefault.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.plugins; - -/** - * Default no-op implementation of {@link RxJavaObservableExecutionHook} - */ -/* - * package - */ -class RxJavaObservableExecutionHookDefault extends RxJavaObservableExecutionHook { - - private static RxJavaObservableExecutionHookDefault INSTANCE = new RxJavaObservableExecutionHookDefault(); - - public static RxJavaObservableExecutionHook getInstance() { - return INSTANCE; - } - -} diff --git a/HMCLAPI/src/main/java/rx/plugins/RxJavaPlugins.java b/HMCLAPI/src/main/java/rx/plugins/RxJavaPlugins.java deleted file mode 100755 index a7d241f77..000000000 --- a/HMCLAPI/src/main/java/rx/plugins/RxJavaPlugins.java +++ /dev/null @@ -1,156 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.plugins; - -import java.util.concurrent.atomic.AtomicReference; - -/** - * Registry for plugin implementations that allows global override and handles - * the retrieval of correct implementation based on order of precedence: - *

    - *
  1. plugin registered globally via register methods in this - * class
  2. - *
  3. plugin registered and retrieved using - * {@link java.lang.System#getProperty(String)} (see get methods for property - * names)
  4. - *
  5. default implementation
  6. - *
- * See the RxJava GitHub Wiki for more information: - * https://github.com/Netflix/RxJava/wiki/Plugins. - */ -public class RxJavaPlugins { - - private final static RxJavaPlugins INSTANCE = new RxJavaPlugins(); - - private final AtomicReference errorHandler = new AtomicReference(); - private final AtomicReference observableExecutionHook = new AtomicReference(); - - private RxJavaPlugins() { - - } - - public static RxJavaPlugins getInstance() { - return INSTANCE; - } - - /** - * Retrieve instance of {@link RxJavaErrorHandler} to use based on order of - * precedence as defined in {@link RxJavaPlugins} class header. - *

- * Override default by using - * {@link #registerErrorHandler(RxJavaErrorHandler)} or setting property: - * rxjava.plugin.RxJavaErrorHandler.implementation with the - * full classname to load. - * - * @return {@link RxJavaErrorHandler} implementation to use - */ - public RxJavaErrorHandler getErrorHandler() { - if (errorHandler.get() == null) { - // check for an implementation from System.getProperty first - Object impl = getPluginImplementationViaProperty(RxJavaErrorHandler.class); - if (impl == null) - // nothing set via properties so initialize with default - errorHandler.compareAndSet(null, RxJavaErrorHandlerDefault.getInstance()); // we don't return from here but call get() again in case of thread-race so the winner will always get returned - else - // we received an implementation from the system property so use it - errorHandler.compareAndSet(null, (RxJavaErrorHandler) impl); - } - return errorHandler.get(); - } - - /** - * Register a {@link RxJavaErrorHandler} implementation as a global override - * of any injected or default implementations. - * - * @param impl {@link RxJavaErrorHandler} implementation - * - * @throws IllegalStateException if called more than once or after the - * default was initialized (if usage occurs before trying to register) - */ - public void registerErrorHandler(RxJavaErrorHandler impl) { - if (!errorHandler.compareAndSet(null, impl)) - throw new IllegalStateException("Another strategy was already registered."); - } - - /** - * Retrieve instance of {@link RxJavaObservableExecutionHook} to use based - * on order of precedence as defined in {@link RxJavaPlugins} class header. - *

- * Override default by using - * {@link #registerObservableExecutionHook(RxJavaObservableExecutionHook)} - * or setting property: - * rxjava.plugin.RxJavaObservableExecutionHook.implementation - * with the full classname to load. - * - * @return {@link RxJavaObservableExecutionHook} implementation to use - */ - public RxJavaObservableExecutionHook getObservableExecutionHook() { - if (observableExecutionHook.get() == null) { - // check for an implementation from System.getProperty first - Object impl = getPluginImplementationViaProperty(RxJavaObservableExecutionHook.class); - if (impl == null) - // nothing set via properties so initialize with default - observableExecutionHook.compareAndSet(null, RxJavaObservableExecutionHookDefault.getInstance()); // we don't return from here but call get() again in case of thread-race so the winner will always get returned - else - // we received an implementation from the system property so use it - observableExecutionHook.compareAndSet(null, (RxJavaObservableExecutionHook) impl); - } - return observableExecutionHook.get(); - } - - /** - * Register a {@link RxJavaObservableExecutionHook} implementation as a - * global override of any injected or default implementations. - * - * @param impl {@link RxJavaObservableExecutionHook} implementation - * - * @throws IllegalStateException if called more than once or after the - * default was initialized (if usage occurs before trying to register) - */ - public void registerObservableExecutionHook(RxJavaObservableExecutionHook impl) { - if (!observableExecutionHook.compareAndSet(null, impl)) - throw new IllegalStateException("Another strategy was already registered."); - } - - private static Object getPluginImplementationViaProperty(Class pluginClass) { - String classSimpleName = pluginClass.getSimpleName(); - /* - * Check system properties for plugin class. - *

- * This will only happen during system startup thus it's okay to use the - * synchronized System.getProperties - * as it will never get called in normal operations. - */ - String implementingClass = System.getProperty("rxjava.plugin." + classSimpleName + ".implementation"); - if (implementingClass != null) - try { - Class cls = Class.forName(implementingClass); - // narrow the scope (cast) to the type we're expecting - cls = cls.asSubclass(pluginClass); - return cls.newInstance(); - } catch (ClassCastException e) { - throw new RuntimeException(classSimpleName + " implementation is not an instance of " + classSimpleName + ": " + implementingClass); - } catch (ClassNotFoundException e) { - throw new RuntimeException(classSimpleName + " implementation class not found: " + implementingClass, e); - } catch (InstantiationException e) { - throw new RuntimeException(classSimpleName + " implementation not able to be instantiated: " + implementingClass, e); - } catch (IllegalAccessException e) { - throw new RuntimeException(classSimpleName + " implementation not able to be accessed: " + implementingClass, e); - } - else - return null; - } -} diff --git a/HMCLAPI/src/main/java/rx/subjects/Subject.java b/HMCLAPI/src/main/java/rx/subjects/Subject.java deleted file mode 100755 index dfcadddac..000000000 --- a/HMCLAPI/src/main/java/rx/subjects/Subject.java +++ /dev/null @@ -1,57 +0,0 @@ -package rx.subjects; - -import java.util.concurrent.ConcurrentHashMap; -import rx.Observable; -import rx.Observer; -import rx.Subscription; -import rx.util.AtomicObservableSubscription; -import rx.util.SynchronizedObserver; -import rx.util.functions.Func1; - -public class Subject extends Observable implements Observer { - - public static Subject create() { - final ConcurrentHashMap> observers = new ConcurrentHashMap<>(); - - Func1, Subscription> onSubscribe = observer -> { - final AtomicObservableSubscription subscription = new AtomicObservableSubscription(); - - subscription.wrap(() -> { - // on unsubscribe remove it from the map of outbound observers to notify - observers.remove(subscription); - }); - - // on subscribe add it to the map of outbound observers to notify - observers.put(subscription, new SynchronizedObserver<>(observer, subscription)); - return subscription; - }; - - return new Subject<>(onSubscribe, observers); - } - - private final ConcurrentHashMap> observers; - - protected Subject(Func1, Subscription> onSubscribe, ConcurrentHashMap> observers) { - super(onSubscribe); - this.observers = observers; - } - - @Override - public void onCompleted() { - for (Observer observer : observers.values()) - observer.onCompleted(); - } - - @Override - public void onError(Exception e) { - for (Observer observer : observers.values()) - observer.onError(e); - } - - @Override - public void onNext(T args) { - for (Observer observer : observers.values()) - observer.onNext(args); - } - -} diff --git a/HMCLAPI/src/main/java/rx/subscriptions/BooleanSubscription.java b/HMCLAPI/src/main/java/rx/subscriptions/BooleanSubscription.java deleted file mode 100755 index 3ae294967..000000000 --- a/HMCLAPI/src/main/java/rx/subscriptions/BooleanSubscription.java +++ /dev/null @@ -1,28 +0,0 @@ -package rx.subscriptions; - -import java.util.concurrent.atomic.AtomicBoolean; - -import rx.Observable; -import rx.Subscription; - -/** - * Subscription that can be checked for status such as in a loop inside an - * {@link Observable} to exit the loop if unsubscribed. - * - * @see Rx.Net equivalent BooleanDisposable at - * http://msdn.microsoft.com/en-us/library/system.reactive.disposables.booleandisposable(v=vs.103).aspx - */ -public class BooleanSubscription implements Subscription { - - private final AtomicBoolean unsubscribed = new AtomicBoolean(false); - - public boolean isUnsubscribed() { - return unsubscribed.get(); - } - - @Override - public void unsubscribe() { - unsubscribed.set(true); - } - -} diff --git a/HMCLAPI/src/main/java/rx/subscriptions/Subscriptions.java b/HMCLAPI/src/main/java/rx/subscriptions/Subscriptions.java deleted file mode 100755 index 5e2b4bcd8..000000000 --- a/HMCLAPI/src/main/java/rx/subscriptions/Subscriptions.java +++ /dev/null @@ -1,45 +0,0 @@ -package rx.subscriptions; - -import rx.Subscription; -import rx.util.functions.Action0; -import rx.util.functions.FuncN; -import rx.util.functions.Functions; - -public class Subscriptions { - - /** - * A {@link Subscription} that does nothing. - * - * @return {@link Subscription} - */ - public static Subscription empty() { - return EMPTY; - } - - /** - * A {@link Subscription} implemented via a Func - * - * @return {@link Subscription} - */ - public static Subscription create(final Action0 unsubscribe) { - return unsubscribe::call; - } - - /** - * A {@link Subscription} implemented via an anonymous function (such as - * closures from other languages). - * - * @return {@link Subscription} - */ - public static Subscription create(final Object unsubscribe) { - final FuncN f = Functions.from(unsubscribe); - return f::call; - } - - /** - * A {@link Subscription} that does nothing when its unsubscribe method is - * called. - */ - private static final Subscription EMPTY = () -> { - }; -} diff --git a/HMCLAPI/src/main/java/rx/util/AtomicObservableSubscription.java b/HMCLAPI/src/main/java/rx/util/AtomicObservableSubscription.java deleted file mode 100755 index cbadb8b7a..000000000 --- a/HMCLAPI/src/main/java/rx/util/AtomicObservableSubscription.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.util; - -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicReference; - -import rx.Subscription; - -/** - * Thread-safe wrapper around Observable Subscription that ensures unsubscribe - * can be called only once. - *

- * Also used to: - *

- *

    - *
  • allow the AtomicObserver to have access to the subscription in - * asynchronous execution for checking if unsubscribed occurred without - * onComplete/onError.
  • - *
  • handle both synchronous and asynchronous subscribe() execution flows
  • - *
- */ -public final class AtomicObservableSubscription implements Subscription { - - private final AtomicReference actualSubscription = new AtomicReference<>(); - private final AtomicBoolean unsubscribed = new AtomicBoolean(false); - - public AtomicObservableSubscription() { - - } - - public AtomicObservableSubscription(Subscription actualSubscription) { - this.actualSubscription.set(actualSubscription); - } - - /** - * Wraps the actual subscription once it exists (if it wasn't available when - * constructed) - * - * @param actualSubscription - * - * @throws IllegalStateException if trying to set more than once (or use - * this method after setting via constructor) - */ - public AtomicObservableSubscription wrap(Subscription actualSubscription) { - if (!this.actualSubscription.compareAndSet(null, actualSubscription)) - throw new IllegalStateException("Can not set subscription more than once."); - return this; - } - - @Override - public void unsubscribe() { - // get the real thing and set to null in an atomic operation so we will only ever call unsubscribe once - Subscription actual = actualSubscription.getAndSet(null); - // if it's not null we will unsubscribe - if (actual != null) { - actual.unsubscribe(); - unsubscribed.set(true); - } - } - - public boolean isUnsubscribed() { - return unsubscribed.get(); - } -} diff --git a/HMCLAPI/src/main/java/rx/util/AtomicObserver.java b/HMCLAPI/src/main/java/rx/util/AtomicObserver.java deleted file mode 100755 index 9599230cd..000000000 --- a/HMCLAPI/src/main/java/rx/util/AtomicObserver.java +++ /dev/null @@ -1,101 +0,0 @@ -package rx.util; - -import java.util.Arrays; -import java.util.concurrent.atomic.AtomicBoolean; - -import rx.Observer; -import rx.plugins.RxJavaPlugins; - -/** - * Wrapper around Observer to ensure compliance with Rx contract. - *

- * The following is taken from the Rx Design Guidelines document: - * http://go.microsoft.com/fwlink/?LinkID=205219 - *

- * Messages sent to instances of the IObserver interface follow the following grammar:
- *
- * OnNext* (OnCompleted | OnError)?
- *
- * This grammar allows observable sequences to send any amount (0 or more) of OnNext messages to the subscribed
- * observer instance, optionally followed by a single success (OnCompleted) or failure (OnError) message.
- *
- * The single message indicating that an observable sequence has finished ensures that consumers of the observable
- * sequence can deterministically establish that it is safe to perform cleanup operations.
- *
- * A single failure further ensures that abort semantics can be maintained for operators that work on
- * multiple observable sequences (see paragraph 6.6).
- * 
- * - *

- * This wrapper will do the following: - *

    - *
  • Allow only single execution of either onError or onCompleted.
  • - *
  • Once an onComplete or onError are performed, no further calls can be - * executed
  • - *
  • If unsubscribe is called, this means we call completed() and don't allow - * any further onNext calls.
  • - *
  • When onError or onComplete occur it will unsubscribe from the Observable - * (if executing asynchronously).
  • - *
- *

- * It will not synchronize onNext execution. Use the - * {@link SynchronizedObserver} to do that. - * - * @param - */ -public class AtomicObserver implements Observer { - - private final Observer actual; - private final AtomicBoolean isFinished = new AtomicBoolean(false); - private final AtomicObservableSubscription subscription; - - public AtomicObserver(AtomicObservableSubscription subscription, Observer actual) { - this.subscription = subscription; - this.actual = actual; - } - - @Override - public void onCompleted() { - if (isFinished.compareAndSet(false, true)) { - try { - actual.onCompleted(); - } catch (Exception e) { - // handle errors if the onCompleted implementation fails, not just if the Observable fails - onError(e); - } - // auto-unsubscribe - subscription.unsubscribe(); - } - } - - @Override - public void onError(Exception e) { - if (isFinished.compareAndSet(false, true)) { - try { - actual.onError(e); - } catch (Exception e2) { - // if the onError itself fails then pass to the plugin - // see https://github.com/Netflix/RxJava/issues/216 for further discussion - RxJavaPlugins.getInstance().getErrorHandler().handleError(e); - RxJavaPlugins.getInstance().getErrorHandler().handleError(e2); - // and throw exception despite that not being proper for Rx - // https://github.com/Netflix/RxJava/issues/198 - throw new RuntimeException("Error occurred when trying to propagate error to Observer.onError", new CompositeException(Arrays.asList(e, e2))); - } - // auto-unsubscribe - subscription.unsubscribe(); - } - } - - @Override - public void onNext(T args) { - try { - if (!isFinished.get()) - actual.onNext(args); - } catch (Exception e) { - // handle errors if the onNext implementation fails, not just if the Observable fails - onError(e); - } - } - -} diff --git a/HMCLAPI/src/main/java/rx/util/CompositeException.java b/HMCLAPI/src/main/java/rx/util/CompositeException.java deleted file mode 100755 index 772cc2cc0..000000000 --- a/HMCLAPI/src/main/java/rx/util/CompositeException.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.util; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -/** - * Exception that is a composite of 1 or more other exceptions. - *

- * The getMessage() will return a concatenation of the composite - * exceptions. - */ -public class CompositeException extends RuntimeException { - - private static final long serialVersionUID = 3026362227162912146L; - - private final List exceptions; - private final String message; - - public CompositeException(String messagePrefix, Collection errors) { - StringBuilder _message = new StringBuilder(); - if (messagePrefix != null) - _message.append(messagePrefix).append(" => "); - - List _exceptions = new ArrayList<>(); - for (Exception e : errors) { - _exceptions.add(e); - if (_message.length() > 0) - _message.append(", "); - _message.append(e.getClass().getSimpleName()).append(":").append(e.getMessage()); - } - this.exceptions = Collections.unmodifiableList(_exceptions); - this.message = _message.toString(); - } - - public CompositeException(Collection errors) { - this(null, errors); - } - - public List getExceptions() { - return exceptions; - } - - @Override - public String getMessage() { - return message; - } -} diff --git a/HMCLAPI/src/main/java/rx/util/Exceptions.java b/HMCLAPI/src/main/java/rx/util/Exceptions.java deleted file mode 100755 index 3dd8e85c6..000000000 --- a/HMCLAPI/src/main/java/rx/util/Exceptions.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.util; - -public class Exceptions { - - private Exceptions() { - - } - - public static RuntimeException propagate(Throwable t) { - if (t instanceof RuntimeException) - throw (RuntimeException) t; - else - throw new RuntimeException(t); - } - -} diff --git a/HMCLAPI/src/main/java/rx/util/Range.java b/HMCLAPI/src/main/java/rx/util/Range.java deleted file mode 100755 index d53e54736..000000000 --- a/HMCLAPI/src/main/java/rx/util/Range.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.util; - -import java.util.Iterator; -import java.util.NoSuchElementException; - -public final class Range implements Iterable { - - private final int start; - private final int end; - private final int step; - - public static Range createWithCount(int start, int count) { - return create(start, start + count); - } - - public static Range create(int start, int end) { - return new Range(start, end, 1); - } - - public static Range createWithStep(int start, int end, int step) { - return new Range(start, end, step); - } - - private Range(int start, int end, int step) { - this.start = start; - this.end = end; - this.step = step; - } - - @Override - public Iterator iterator() { - return new Iterator() { - private int current = start; - - @Override - public boolean hasNext() { - return current < end; - } - - @Override - public Integer next() { - if (!hasNext()) - throw new NoSuchElementException("No more elements"); - int result = current; - current += step; - return result; - } - - @Override - public void remove() { - throw new UnsupportedOperationException("Read only iterator"); - } - }; - } - - @Override - public String toString() { - return "Range (" + start + ", " + end + "), step " + step; - } -} diff --git a/HMCLAPI/src/main/java/rx/util/SynchronizedObserver.java b/HMCLAPI/src/main/java/rx/util/SynchronizedObserver.java deleted file mode 100755 index 9e203a5df..000000000 --- a/HMCLAPI/src/main/java/rx/util/SynchronizedObserver.java +++ /dev/null @@ -1,109 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.util; - -import rx.Observer; - -/** - * A thread-safe Observer for transitioning states in operators. - *

- * Execution rules are: - *

    - *
  • Allow only single-threaded, synchronous, ordered execution of onNext, - * onCompleted, onError
  • - *
  • Once an onComplete or onError are performed, no further calls can be - * executed
  • - *
  • If unsubscribe is called, this means we call completed() and don't allow - * any further onNext calls.
  • - *
- * - * @param - */ -public final class SynchronizedObserver implements Observer { - - /** - * Intrinsic synchronized locking with double-check short-circuiting was - * chosen after testing several other implementations. - * - * The code and results can be found here: - - * https://github.com/benjchristensen/JavaLockPerformanceTests/tree/master/results/Observer - * - - * https://github.com/benjchristensen/JavaLockPerformanceTests/tree/master/src/com/benjchristensen/performance/locks/Observer - * - * The major characteristic that made me choose synchronized instead of - * Reentrant or a customer AbstractQueueSynchronizer implementation is that - * intrinsic locking performed better when nested, and AtomicObserver will - * end up nested most of the time since Rx is compositional by its very - * nature. - * - * // TODO composing of this class should rarely happen now with updated - * design so this decision should be revisited - */ - private final Observer observer; - private final AtomicObservableSubscription subscription; - private volatile boolean finishRequested = false; - private volatile boolean finished = false; - - public SynchronizedObserver(Observer Observer, AtomicObservableSubscription subscription) { - this.observer = Observer; - this.subscription = subscription; - } - - @Override - public void onNext(T arg) { - if (finished || finishRequested || subscription.isUnsubscribed()) - // if we're already stopped, or a finish request has been received, we won't allow further onNext requests - return; - synchronized (this) { - // check again since this could have changed while waiting - if (finished || finishRequested || subscription.isUnsubscribed()) - // if we're already stopped, or a finish request has been received, we won't allow further onNext requests - return; - observer.onNext(arg); - } - } - - @Override - public void onError(Exception e) { - if (finished || subscription.isUnsubscribed()) - // another thread has already finished us, so we won't proceed - return; - finishRequested = true; - synchronized (this) { - // check again since this could have changed while waiting - if (finished || subscription.isUnsubscribed()) - return; - observer.onError(e); - finished = true; - } - } - - @Override - public void onCompleted() { - if (finished || subscription.isUnsubscribed()) - // another thread has already finished us, so we won't proceed - return; - finishRequested = true; - synchronized (this) { - // check again since this could have changed while waiting - if (finished || subscription.isUnsubscribed()) - return; - observer.onCompleted(); - finished = true; - } - } - -} diff --git a/HMCLAPI/src/main/java/rx/util/functions/Action0.java b/HMCLAPI/src/main/java/rx/util/functions/Action0.java deleted file mode 100755 index a20f1533f..000000000 --- a/HMCLAPI/src/main/java/rx/util/functions/Action0.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.util.functions; - -public interface Action0 extends Function { - - public void call(); -} diff --git a/HMCLAPI/src/main/java/rx/util/functions/Action1.java b/HMCLAPI/src/main/java/rx/util/functions/Action1.java deleted file mode 100755 index 8991be796..000000000 --- a/HMCLAPI/src/main/java/rx/util/functions/Action1.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.util.functions; - -public interface Action1 extends Function { - - public void call(T1 t1); -} diff --git a/HMCLAPI/src/main/java/rx/util/functions/Action2.java b/HMCLAPI/src/main/java/rx/util/functions/Action2.java deleted file mode 100755 index c12af11e7..000000000 --- a/HMCLAPI/src/main/java/rx/util/functions/Action2.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.util.functions; - -public interface Action2 extends Function { - - public void call(T1 t1, T2 t2); -} diff --git a/HMCLAPI/src/main/java/rx/util/functions/Action3.java b/HMCLAPI/src/main/java/rx/util/functions/Action3.java deleted file mode 100755 index 6ccf1b44a..000000000 --- a/HMCLAPI/src/main/java/rx/util/functions/Action3.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.util.functions; - -public interface Action3 extends Function { - - public void call(T1 t1, T2 t2, T3 t3); -} diff --git a/HMCLAPI/src/main/java/rx/util/functions/Func0.java b/HMCLAPI/src/main/java/rx/util/functions/Func0.java deleted file mode 100755 index 1c1fd3349..000000000 --- a/HMCLAPI/src/main/java/rx/util/functions/Func0.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.util.functions; - -public interface Func0 extends Function { - - public R call(); -} diff --git a/HMCLAPI/src/main/java/rx/util/functions/Func1.java b/HMCLAPI/src/main/java/rx/util/functions/Func1.java deleted file mode 100755 index 51bc08e68..000000000 --- a/HMCLAPI/src/main/java/rx/util/functions/Func1.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.util.functions; - -public interface Func1 extends Function { - - public R call(T1 t1); -} diff --git a/HMCLAPI/src/main/java/rx/util/functions/Func2.java b/HMCLAPI/src/main/java/rx/util/functions/Func2.java deleted file mode 100755 index 7e60998d3..000000000 --- a/HMCLAPI/src/main/java/rx/util/functions/Func2.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.util.functions; - -public interface Func2 extends Function { - - public R call(T1 t1, T2 t2); -} diff --git a/HMCLAPI/src/main/java/rx/util/functions/Func3.java b/HMCLAPI/src/main/java/rx/util/functions/Func3.java deleted file mode 100755 index b7ba5a1af..000000000 --- a/HMCLAPI/src/main/java/rx/util/functions/Func3.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.util.functions; - -public interface Func3 extends Function { - - public R call(T1 t1, T2 t2, T3 t3); -} diff --git a/HMCLAPI/src/main/java/rx/util/functions/Func4.java b/HMCLAPI/src/main/java/rx/util/functions/Func4.java deleted file mode 100755 index 1010ad6a7..000000000 --- a/HMCLAPI/src/main/java/rx/util/functions/Func4.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.util.functions; - -public interface Func4 extends Function { - - public R call(T1 t1, T2 t2, T3 t3, T4 t4); -} diff --git a/HMCLAPI/src/main/java/rx/util/functions/Func5.java b/HMCLAPI/src/main/java/rx/util/functions/Func5.java deleted file mode 100755 index f040934cb..000000000 --- a/HMCLAPI/src/main/java/rx/util/functions/Func5.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.util.functions; - -public interface Func5 extends Function { - - public R call(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5); -} diff --git a/HMCLAPI/src/main/java/rx/util/functions/Func6.java b/HMCLAPI/src/main/java/rx/util/functions/Func6.java deleted file mode 100755 index 1a2ab8acf..000000000 --- a/HMCLAPI/src/main/java/rx/util/functions/Func6.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.util.functions; - -public interface Func6 extends Function { - - public R call(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6); -} diff --git a/HMCLAPI/src/main/java/rx/util/functions/Func7.java b/HMCLAPI/src/main/java/rx/util/functions/Func7.java deleted file mode 100755 index 815ab596a..000000000 --- a/HMCLAPI/src/main/java/rx/util/functions/Func7.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.util.functions; - -public interface Func7 extends Function { - - public R call(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7); -} diff --git a/HMCLAPI/src/main/java/rx/util/functions/Func8.java b/HMCLAPI/src/main/java/rx/util/functions/Func8.java deleted file mode 100755 index 61be78829..000000000 --- a/HMCLAPI/src/main/java/rx/util/functions/Func8.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.util.functions; - -public interface Func8 extends Function { - - public R call(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8); -} diff --git a/HMCLAPI/src/main/java/rx/util/functions/Func9.java b/HMCLAPI/src/main/java/rx/util/functions/Func9.java deleted file mode 100755 index ccad90114..000000000 --- a/HMCLAPI/src/main/java/rx/util/functions/Func9.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.util.functions; - -public interface Func9 extends Function { - - public R call(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9); -} diff --git a/HMCLAPI/src/main/java/rx/util/functions/FuncN.java b/HMCLAPI/src/main/java/rx/util/functions/FuncN.java deleted file mode 100755 index 20c66a6b7..000000000 --- a/HMCLAPI/src/main/java/rx/util/functions/FuncN.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.util.functions; - -public interface FuncN extends Function { - - public R call(Object... args); -} diff --git a/HMCLAPI/src/main/java/rx/util/functions/Function.java b/HMCLAPI/src/main/java/rx/util/functions/Function.java deleted file mode 100755 index cfe85a221..000000000 --- a/HMCLAPI/src/main/java/rx/util/functions/Function.java +++ /dev/null @@ -1,10 +0,0 @@ -package rx.util.functions; - -/** - * All Func and Action interfaces extend from this. - *

- * Marker interface to allow isntanceof checks. - */ -public interface Function { - -} diff --git a/HMCLAPI/src/main/java/rx/util/functions/FunctionLanguageAdaptor.java b/HMCLAPI/src/main/java/rx/util/functions/FunctionLanguageAdaptor.java deleted file mode 100755 index 4b12f30c1..000000000 --- a/HMCLAPI/src/main/java/rx/util/functions/FunctionLanguageAdaptor.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package rx.util.functions; - -public interface FunctionLanguageAdaptor { - - /** - * Invoke the function and return the results. - * - * @param function - * @param args - * - * @return Object results from function execution - */ - Object call(Object function, Object[] args); - - /** - * The Class of the Function that this adaptor serves. - *

- * Example: groovy.lang.Closure - *

- * This should not return classes of java.* packages. - * - * @return Class[] of classes that this adaptor should be invoked for. - */ - public Class[] getFunctionClass(); -} diff --git a/HMCLAPI/src/main/java/rx/util/functions/Functions.java b/HMCLAPI/src/main/java/rx/util/functions/Functions.java deleted file mode 100755 index b955a9b15..000000000 --- a/HMCLAPI/src/main/java/rx/util/functions/Functions.java +++ /dev/null @@ -1,503 +0,0 @@ -/** - * Copyright 2013 Netflix, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package rx.util.functions; - -import java.util.Collection; -import java.util.concurrent.ConcurrentHashMap; -import org.jackhuang.hellominecraft.utils.logging.logger.Logger; - -/** - * Allows execution of functions from multiple different languages. - *

- * Language support is provided via implementations of - * {@link FunctionLanguageAdaptor}. - *

- * This class will dynamically look for known language adaptors on the classpath - * at startup or new ones can be registered using - * {@link #registerLanguageAdaptor(Class[], FunctionLanguageAdaptor)}. - */ -public class Functions { - - private static final Logger logger = new Logger("Functions"); - - private final static ConcurrentHashMap, FunctionLanguageAdaptor> languageAdaptors = new ConcurrentHashMap<>(); - - private static boolean loadLanguageAdaptor(String name) { - String className = "rx.lang." + name.toLowerCase() + "." + name + "Adaptor"; - try { - Class c = Class.forName(className); - FunctionLanguageAdaptor a = (FunctionLanguageAdaptor) c.newInstance(); - registerLanguageAdaptor(a.getFunctionClass(), a); - logger.info("Successfully loaded function language adaptor: " + name + " with path: " + className); - } catch (ClassNotFoundException e) { - logger.info("Could not find function language adaptor: " + name + " with path: " + className); - return false; - } catch (Exception e) { - logger.error("Failed trying to initialize function language adaptor: " + className, e); - return false; - } - return true; - } - - public static void registerLanguageAdaptor(Class[] functionClasses, FunctionLanguageAdaptor adaptor) { - for (Class functionClass : functionClasses) { - if (functionClass.getPackage().getName().startsWith("java.")) - throw new IllegalArgumentException("FunctionLanguageAdaptor implementations can not specify java.lang.* classes."); - languageAdaptors.put(functionClass, adaptor); - } - } - - public static void removeLanguageAdaptor(Class functionClass) { - languageAdaptors.remove(functionClass); - } - - public static Collection getRegisteredLanguageAdaptors() { - return languageAdaptors.values(); - } - - /** - * Utility method for determining the type of closure/function and executing - * it. - * - * @param function - */ - @SuppressWarnings({ "rawtypes" }) - public static FuncN from(final Object function) { - if (function == null) - throw new RuntimeException("function is null. Can't send arguments to null function."); - - /* - * check for typed Rx Function implementation first - */ - if (function instanceof Function) - return fromFunction((Function) function); - else - /* - * not an Rx Function so try language adaptors - */ - - // check for language adaptor - for (final Class c : languageAdaptors.keySet()) - if (c.isInstance(function)) { - final FunctionLanguageAdaptor la = languageAdaptors.get(c); - // found the language adaptor so wrap in FuncN and return - return new FuncN() { - - @Override - public Object call(Object... args) { - return la.call(function, args); - } - - }; - } // no language adaptor found - - // no support found - throw new RuntimeException("Unsupported closure type: " + function.getClass().getSimpleName()); - } - - // - // @SuppressWarnings("unchecked") - // private static R executionRxFunction(Function function, Object... args) { - // // check Func* classes - // if (function instanceof Func0) { - // Func0 f = (Func0) function; - // if (args.length != 0) { - // throw new RuntimeException("The closure was Func0 and expected no arguments, but we received: " + args.length); - // } - // return (R) f.call(); - // } else if (function instanceof Func1) { - // Func1 f = (Func1) function; - // if (args.length != 1) { - // throw new RuntimeException("The closure was Func1 and expected 1 argument, but we received: " + args.length); - // } - // return f.call(args[0]); - // } else if (function instanceof Func2) { - // Func2 f = (Func2) function; - // if (args.length != 2) { - // throw new RuntimeException("The closure was Func2 and expected 2 arguments, but we received: " + args.length); - // } - // return f.call(args[0], args[1]); - // } else if (function instanceof Func3) { - // Func3 f = (Func3) function; - // if (args.length != 3) { - // throw new RuntimeException("The closure was Func3 and expected 3 arguments, but we received: " + args.length); - // } - // return (R) f.call(args[0], args[1], args[2]); - // } else if (function instanceof Func4) { - // Func4 f = (Func4) function; - // if (args.length != 1) { - // throw new RuntimeException("The closure was Func4 and expected 4 arguments, but we received: " + args.length); - // } - // return f.call(args[0], args[1], args[2], args[3]); - // } else if (function instanceof Func5) { - // Func5 f = (Func5) function; - // if (args.length != 1) { - // throw new RuntimeException("The closure was Func5 and expected 5 arguments, but we received: " + args.length); - // } - // return f.call(args[0], args[1], args[2], args[3], args[4]); - // } else if (function instanceof Func6) { - // Func6 f = (Func6) function; - // if (args.length != 1) { - // throw new RuntimeException("The closure was Func6 and expected 6 arguments, but we received: " + args.length); - // } - // return f.call(args[0], args[1], args[2], args[3], args[4], args[5]); - // } else if (function instanceof Func7) { - // Func7 f = (Func7) function; - // if (args.length != 1) { - // throw new RuntimeException("The closure was Func7 and expected 7 arguments, but we received: " + args.length); - // } - // return f.call(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); - // } else if (function instanceof Func8) { - // Func8 f = (Func8) function; - // if (args.length != 1) { - // throw new RuntimeException("The closure was Func8 and expected 8 arguments, but we received: " + args.length); - // } - // return f.call(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]); - // } else if (function instanceof Func9) { - // Func9 f = (Func9) function; - // if (args.length != 1) { - // throw new RuntimeException("The closure was Func9 and expected 9 arguments, but we received: " + args.length); - // } - // return f.call(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]); - // } else if (function instanceof FuncN) { - // FuncN f = (FuncN) function; - // return f.call(args); - // } else if (function instanceof Action0) { - // Action0 f = (Action0) function; - // if (args.length != 1) { - // throw new RuntimeException("The closure was Action0 and expected 0 arguments, but we received: " + args.length); - // } - // f.call(); - // return null; - // } else if (function instanceof Action1) { - // Action1 f = (Action1) function; - // if (args.length != 1) { - // throw new RuntimeException("The closure was Action1 and expected 1 argument, but we received: " + args.length); - // } - // f.call(args[0]); - // return null; - // } else if (function instanceof Action2) { - // Action2 f = (Action2) function; - // if (args.length != 1) { - // throw new RuntimeException("The closure was Action2 and expected 2 argument, but we received: " + args.length); - // } - // f.call(args[0], args[1]); - // return null; - // } else if (function instanceof Action3) { - // Action3 f = (Action3) function; - // if (args.length != 1) { - // throw new RuntimeException("The closure was Action1 and expected 1 argument, but we received: " + args.length); - // } - // f.call(args[0], args[1], args[2]); - // return null; - // } - // - // throw new RuntimeException("Unknown implementation of Function: " + function.getClass().getSimpleName()); - // } - @SuppressWarnings({ "unchecked", "rawtypes" }) - private static FuncN fromFunction(Function function) { - // check Func* classes - if (function instanceof Func0) - return fromFunc((Func0) function); - else if (function instanceof Func1) - return fromFunc((Func1) function); - else if (function instanceof Func2) - return fromFunc((Func2) function); - else if (function instanceof Func3) - return fromFunc((Func3) function); - else if (function instanceof Func4) - return fromFunc((Func4) function); - else if (function instanceof Func5) - return fromFunc((Func5) function); - else if (function instanceof Func6) - return fromFunc((Func6) function); - else if (function instanceof Func7) - return fromFunc((Func7) function); - else if (function instanceof Func8) - return fromFunc((Func8) function); - else if (function instanceof Func9) - return fromFunc((Func9) function); - else if (function instanceof FuncN) - return (FuncN) function; - else if (function instanceof Action0) - return fromAction((Action0) function); - else if (function instanceof Action1) - return fromAction((Action1) function); - else if (function instanceof Action2) - return fromAction((Action2) function); - else if (function instanceof Action3) - return fromAction((Action3) function); - - throw new RuntimeException("Unknown implementation of Function: " + function.getClass().getSimpleName()); - } - - /** - * Convert a function to FuncN to allow heterogeneous handling of functions - * with different arities. - * - * @param f - * - * @return {@link FuncN} - */ - public static FuncN fromFunc(final Func0 f) { - return (Object... args) -> { - if (args.length != 0) - throw new RuntimeException("Func0 expecting 0 arguments."); - return f.call(); - }; - } - - /** - * Convert a function to FuncN to allow heterogeneous handling of functions - * with different arities. - * - * @param f - * - * @return {@link FuncN} - */ - public static FuncN fromFunc(final Func1 f) { - return (Object... args) -> { - if (args.length != 1) - throw new RuntimeException("Func1 expecting 1 argument."); - return f.call((T0) args[0]); - }; - } - - /** - * Convert a function to FuncN to allow heterogeneous handling of functions - * with different arities. - * - * @param f - * - * @return {@link FuncN} - */ - public static FuncN fromFunc(final Func2 f) { - return (Object... args) -> { - if (args.length != 2) - throw new RuntimeException("Func2 expecting 2 arguments."); - return f.call((T0) args[0], (T1) args[1]); - }; - } - - /** - * Convert a function to FuncN to allow heterogeneous handling of functions - * with different arities. - * - * @param f - * - * @return {@link FuncN} - */ - public static FuncN fromFunc(final Func3 f) { - return (Object... args) -> { - if (args.length != 3) - throw new RuntimeException("Func3 expecting 3 arguments."); - return f.call((T0) args[0], (T1) args[1], (T2) args[2]); - }; - } - - /** - * Convert a function to FuncN to allow heterogeneous handling of functions - * with different arities. - * - * @param f - * - * @return {@link FuncN} - */ - public static FuncN fromFunc(final Func4 f) { - return (Object... args) -> { - if (args.length != 4) - throw new RuntimeException("Func4 expecting 4 arguments."); - return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3]); - }; - } - - /** - * Convert a function to FuncN to allow heterogeneous handling of functions - * with different arities. - * - * @param f - * - * @return {@link FuncN} - */ - public static FuncN fromFunc(final Func5 f) { - return (Object... args) -> { - if (args.length != 5) - throw new RuntimeException("Func5 expecting 5 arguments."); - return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4]); - }; - } - - /** - * Convert a function to FuncN to allow heterogeneous handling of functions - * with different arities. - * - * @param f - * - * @return {@link FuncN} - */ - public static FuncN fromFunc(final Func6 f) { - return (Object... args) -> { - if (args.length != 6) - throw new RuntimeException("Func6 expecting 6 arguments."); - return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4], (T5) args[5]); - }; - } - - /** - * Convert a function to FuncN to allow heterogeneous handling of functions - * with different arities. - * - * @param f - * - * @return {@link FuncN} - */ - public static FuncN fromFunc(final Func7 f) { - return (Object... args) -> { - if (args.length != 7) - throw new RuntimeException("Func7 expecting 7 arguments."); - return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4], (T5) args[5], (T6) args[6]); - }; - } - - /** - * Convert a function to FuncN to allow heterogeneous handling of functions - * with different arities. - * - * @param f - * - * @return {@link FuncN} - */ - public static FuncN fromFunc(final Func8 f) { - return (Object... args) -> { - if (args.length != 8) - throw new RuntimeException("Func8 expecting 8 arguments."); - return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4], (T5) args[5], (T6) args[6], (T7) args[7]); - }; - } - - /** - * Convert a function to FuncN to allow heterogeneous handling of functions - * with different arities. - * - * @param f - * - * @return {@link FuncN} - */ - public static FuncN fromFunc(final Func9 f) { - return (Object... args) -> { - if (args.length != 9) - throw new RuntimeException("Func9 expecting 9 arguments."); - return f.call((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3], (T4) args[4], (T5) args[5], (T6) args[6], (T7) args[7], (T8) args[8]); - }; - } - - /** - * Convert a function to FuncN to allow heterogeneous handling of functions - * with different arities. - * - * @param f - * - * @return {@link FuncN} - */ - public static FuncN fromAction(final Action0 f) { - return (Object... args) -> { - if (args.length != 0) - throw new RuntimeException("Action0 expecting 0 arguments."); - f.call(); - return null; - }; - } - - /** - * Convert a function to FuncN to allow heterogeneous handling of functions - * with different arities. - * - * @param f - * - * @return {@link FuncN} - */ - public static FuncN fromAction(final Action1 f) { - return (Object... args) -> { - if (args.length != 1) - throw new RuntimeException("Action1 expecting 1 argument."); - f.call((T0) args[0]); - return null; - }; - } - - /** - * Convert a function to FuncN to allow heterogeneous handling of functions - * with different arities. - * - * @param f - * - * @return {@link FuncN} - */ - public static FuncN fromAction(final Action2 f) { - return (Object... args) -> { - if (args.length != 2) - throw new RuntimeException("Action3 expecting 2 arguments."); - f.call((T0) args[0], (T1) args[1]); - return null; - }; - } - - /** - * Convert a function to FuncN to allow heterogeneous handling of functions - * with different arities. - * - * @param f - * - * @return {@link FuncN} - */ - public static FuncN fromAction(final Action3 f) { - return (Object... args) -> { - if (args.length != 3) - throw new RuntimeException("Action3 expecting 3 arguments."); - f.call((T0) args[0], (T1) args[1], (T2) args[2]); - return null; - }; - } - - @SuppressWarnings("unchecked") - public static Func1 alwaysTrue() { - return (Func1) AlwaysTrue.INSTANCE; - } - - @SuppressWarnings("unchecked") - public static Func1 identity() { - return (Func1) Identity.INSTANCE; - } - - private enum AlwaysTrue implements Func1 { - INSTANCE; - - @Override - public Boolean call(Object o) { - return true; - } - } - - private enum Identity implements Func1 { - INSTANCE; - - @Override - public Object call(Object o) { - return o; - } - } - -} diff --git a/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N.properties b/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N.properties index 774472a9e..f9a5ba8f9 100755 --- a/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N.properties +++ b/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N.properties @@ -260,7 +260,7 @@ mainwindow.enter_script_name=\u8f93\u5165\u8981\u751f\u6210\u811a\u672c\u7684\u6 mainwindow.make_launch_succeed=\u542f\u52a8\u811a\u672c\u5df2\u751f\u6210\u5b8c\u6bd5: mainwindow.no_version=\u672a\u627e\u5230\u4efb\u4f55\u7248\u672c\uff0c\u662f\u5426\u8fdb\u5165\u6e38\u620f\u4e0b\u8f7d\uff1f -launcher.about=\u9ed8\u8ba4\u80cc\u666f\u56fe\u6765\u81eaLiberty Dome\u670d\u52a1\u5668\u3002
\u5173\u4e8e\u4f5c\u8005\uff1a
\n\u767e\u5ea6ID\uff1ahuanghongxun20
\nmcbbs\uff1ahuanghongxun
\n\u90ae\u7bb1\uff1ahuanghongxun2008@126.com
\nMinecraft Forum ID: klkl6523
\n\u6b22\u8fce\u63d0\u4ea4Bug\u54e6
\nCopyright (c) 2013-2015 huangyuhui.
\u514d\u8d23\u58f0\u660e\uff1aMinecraft\u8f6f\u4ef6\u7248\u6743\u5f52Mojang AB\u6240\u6709\uff0c\u6e38\u620f\u7531\u4e8e\u8bef\u64cd\u4f5c\u672c\u542f\u52a8\u5668\u800c\u4e22\u5931\u6570\u636e\u7684\u6982\u4e0d\u8d1f\u8d23\u3002
\u672c\u542f\u52a8\u5668\u5728GPLv3\u534f\u8bae\u4e0b\u5f00\u6e90:https://github.com/huanghongxun/HMCL/
\u672c\u8f6f\u4ef6\u4f7f\u7528\u4e86\u57fa\u4e8eApache License 2.0\u7684RxJava\u548cGson\u9879\u76ee\uff0c\u611f\u8c22\u8d21\u732e\u8005\u3002 +launcher.about=\u9ed8\u8ba4\u80cc\u666f\u56fe\u6765\u81eaLiberty Dome\u670d\u52a1\u5668\u3002
\u5173\u4e8e\u4f5c\u8005\uff1a
\n\u767e\u5ea6ID\uff1ahuanghongxun20
\nmcbbs\uff1ahuanghongxun
\n\u90ae\u7bb1\uff1ahuanghongxun2008@126.com
\nMinecraft Forum ID: klkl6523
\n\u6b22\u8fce\u63d0\u4ea4Bug\u54e6
\nCopyright (c) 2013-2015 huangyuhui.
\u514d\u8d23\u58f0\u660e\uff1aMinecraft\u8f6f\u4ef6\u7248\u6743\u5f52Mojang AB\u6240\u6709\uff0c\u6e38\u620f\u7531\u4e8e\u8bef\u64cd\u4f5c\u672c\u542f\u52a8\u5668\u800c\u4e22\u5931\u6570\u636e\u7684\u6982\u4e0d\u8d1f\u8d23\u3002
\u672c\u542f\u52a8\u5668\u5728GPLv3\u534f\u8bae\u4e0b\u5f00\u6e90:https://github.com/huanghongxun/HMCL/
\u672c\u8f6f\u4ef6\u4f7f\u7528\u4e86\u57fa\u4e8eApache License 2.0\u7684Gson\u9879\u76ee\uff0c\u611f\u8c22\u8d21\u732e\u8005\u3002 launcher.download_source=\u4e0b\u8f7d\u6e90 launcher.background_location=\u80cc\u666f\u5730\u5740 launcher.exit_failed=\u5f3a\u5236\u9000\u51fa\u5931\u8d25\uff0c\u53ef\u80fd\u662fForge 1.7.10\u53ca\u66f4\u9ad8\u7248\u672c\u5bfc\u81f4\u7684\uff0c\u65e0\u6cd5\u89e3\u51b3\u3002 diff --git a/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N_en.properties b/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N_en.properties index 9500fadf6..7c8747db3 100755 --- a/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N_en.properties +++ b/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N_en.properties @@ -260,7 +260,7 @@ mainwindow.enter_script_name=Enter the script name. mainwindow.make_launch_succeed=Finished script creation. mainwindow.no_version=No version found. Switch to Game Downloads Tab? -launcher.about=About Author
\nEmail\uff1ahuanghongxun2008@126.com
\nMinecraft Forum ID: klkl6523
\nCopyright (c) 2013 huangyuhui
Opened source under GPL v3 license:http://github.com/huanghongxun/HMCL/
This software used project RxJava and Gson which is under Apache License 2.0, thanks contributors. +launcher.about=About Author
\nEmail\uff1ahuanghongxun2008@126.com
\nMinecraft Forum ID: klkl6523
\nCopyright (c) 2013 huangyuhui
Opened source under GPL v3 license:http://github.com/huanghongxun/HMCL/
This software used project Gson which is under Apache License 2.0, thanks contributors. launcher.download_source=Download Source launcher.background_location=Background Location launcher.exit_failed=Failed to shutdown. diff --git a/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N_zh.properties b/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N_zh.properties index 32a3cbf9a..4ac1cdcb3 100755 --- a/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N_zh.properties +++ b/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N_zh.properties @@ -110,7 +110,7 @@ crash.advice.ConcurrentModificationException=\u9019\u53ef\u80fd\u662f\u56e0\u70b crash.advice.ClassNotFoundException=Minecraft\u4e0d\u5b8c\u6574\u6216Mod\u885d\u7a81\uff0c\u5982\u679c\u6709\u672a\u80fd\u4e0b\u8f7d\u7684\u8cc7\u6599\u8bf7\u4e0b\u8f7d\u6210\u529f\u540e\u91cd\u8bd5\u6216\u662f\u5ba2\u6237\u7aef\u635f\u574f\u8bf7\u91cd\u8bd5\u8bf7\u91cd\u65b0\u5236\u4f5c\u5ba2\u6237\u7aef\u6216\u4e0b\u8f09\u6574\u5408\u5305\u89e3\u6c7a\u554f\u984c\u3002 crash.advice.NoSuchFieldError=Minecraft\u4e0d\u5b8c\u6574\u6216Mod\u885d\u7a81\uff0c\u5982\u679c\u6709\u672a\u80fd\u4e0b\u8f7d\u7684\u8cc7\u6599\u8bf7\u4e0b\u8f7d\u6210\u529f\u540e\u91cd\u8bd5\u6216\u662f\u5ba2\u6237\u7aef\u635f\u574f\u8bf7\u91cd\u8bd5\u8bf7\u91cd\u65b0\u5236\u4f5c\u5ba2\u6237\u7aef\u6216\u4e0b\u8f09\u6574\u5408\u5305\u89e3\u6c7a\u554f\u984c\u3002 crash.advice.LWJGLException=\u60a8\u7684\u7535\u8111\u4e0d\u6b63\u5e38\uff0c\u53ef\u80fd\u9700\u8981\u4f7f\u7528\u9a71\u52a8\u7cbe\u7075\u6216\u5176\u4ed6\u5b89\u88c5\u5668\u66f4\u65b0\u663e\u5361\u9a71\u52a8\u3002 -crash.advice.SecurityException=\u53ef\u80fd\u662f\u60a8\u4fee\u6539\u4e86minecraft.jar\u4f46\u672a\u522a\u9664META-INF\u8cc7\u6599\u593e\u7684\u539f\u56e0\u3002\u8acb\u901a\u904e\u58d3\u7e2e\u8edf\u4ef6\u522a\u9664jar\u4e2d\u7684META-INF\u8cc7\u6599\u593e\u3002 +crash.advice.SecurityException=\u53ef\u80fd\u662f\u60a8\u4fee\u6539\u4e86minecraft.jar\u4f46\u672a\u522a\u9664META-INF\u8cc7\u6599\u593e\u7684\u539f\u56e0\u3002\u8acb\u901a\u904e\u58d3\u7e2e\u8edf\u9ad4\u522a\u9664jar\u4e2d\u7684META-INF\u8cc7\u6599\u593e\u3002 crash.advice.OutOfMemoryError=\u5185\u5b58\u6ea2\u51fa\uff0c\u60a8\u8bbe\u7f6e\u7684Minecraft\u6700\u5927\u5185\u5b58\u8fc7\u5c0f\uff0c\u8bf7\u8c03\u5927\uff01 crash.advice.otherwise=\u53ef\u80fd\u662fMod\u6216\u5176\u4ed6\u554f\u984c\u3002 @@ -119,7 +119,7 @@ crash.advice.no_lwjgl=\u53ef\u80fd\u662f\u904a\u6232\u4f9d\u8cf4\u5eab\u4e0d\u5b crash.advice.no=\u7121\u5efa\u8b70\u3002 -crash.user_fault=\u60a8\u7684\u7cfb\u7d71\u6216Java\u74b0\u5883\u53ef\u80fd\u5b89\u88dd\u4e0d\u7576\u5c0e\u81f4\u672c\u8edf\u4ef6\u5d29\u6f70\uff0c\u8acb\u6aa2\u67e5\u60a8\u7684Java\u74b0\u5883\u6216\u60a8\u7684\u96fb\u8166\uff01\u53ef\u4ee5\u5617\u8a66\u91cd\u65b0\u5b89\u88ddJava\u3002 +crash.user_fault=\u60a8\u7684\u7cfb\u7d71\u6216Java\u74b0\u5883\u53ef\u80fd\u5b89\u88dd\u4e0d\u7576\u5c0e\u81f4\u672c\u8edf\u9ad4\u5d29\u6f70\uff0c\u8acb\u6aa2\u67e5\u60a8\u7684Java\u74b0\u5883\u6216\u60a8\u7684\u96fb\u8166\uff01\u53ef\u4ee5\u5617\u8a66\u91cd\u65b0\u5b89\u88ddJava\u3002 crash.headless=\u5982\u679c\u60a8\u7684\u64cd\u4f5c\u7cfb\u7d71\u662fLinux\uff0c\u8acb\u6ce8\u610f\u4e0d\u8981\u4f7f\u7528OpenJDK\uff0c\u52d9\u5fc5\u4f7f\u7528Oracle JDK\uff0c\u6216\u5617\u8a66\u6dfb\u52a0-Djava.awt.headless=false\u53c3\u6578\uff0c\u6216\u6aa2\u67e5\u60a8\u7684Xserver\u662f\u5426\u6b63\u5e38 crash.NoClassDefFound=\u8acb\u78ba\u8a8dHMCL\u672c\u9ad4\u662f\u5426\u5b8c\u6574 @@ -260,7 +260,7 @@ mainwindow.enter_script_name=\u8f38\u5165\u8981\u751f\u6210\u8173\u672c\u7684\u8 mainwindow.make_launch_succeed=\u555f\u52d5\u8173\u672c\u5df2\u751f\u6210\u5b8c\u7562: mainwindow.no_version=\u672a\u627e\u5230\u4efb\u4f55\u7248\u672c\uff0c\u662f\u5426\u9032\u5165\u904a\u6232\u4e0b\u8f09\uff1f -launcher.about=\u9ed8\u8a8d\u80cc\u666f\u5716\u4f86\u81eaLiberty Dome\u670d\u52d9\u5668\u3002
\u95dc\u65bc\u4f5c\u8005\uff1a
\n\u767e\u5ea6ID\uff1ahuanghongxun20
\nmcbbs\uff1ahuanghongxun
\n\u90f5\u7bb1\uff1ahuanghongxun2008@126.com
\nMinecraft Forum ID: klkl6523
\n\u6b61\u8fce\u63d0\u4ea4Bug\u54e6
\nCopyright (c) 2013-2015 huangyuhui.
\u514d\u8cac\u8072\u660e\uff1aMinecraft\u8edf\u4ef6\u7248\u6b0a\u6b78Mojang AB\u6240\u6709\uff0c\u904a\u6232\u7531\u65bc\u8aa4\u64cd\u4f5c\u672c\u555f\u52d5\u5668\u800c\u4e1f\u5931\u6578\u64da\u7684\u6982\u4e0d\u8ca0\u8cac\u3002
\u672c\u555f\u52d5\u5668\u5728GPLv3\u5354\u8b70\u4e0b\u958b\u6e90:http://github.com/huanghongxun/HMCL/
\u672c\u8edf\u4ef6\u4f7f\u7528\u4e86\u57fa\u65bcApache License 2.0\u7684RxJava\u548cGson\u9805\u76ee\uff0c\u611f\u8b1d\u8ca2\u737b\u8005\u3002 +launcher.about=\u9ed8\u8a8d\u80cc\u666f\u5716\u4f86\u81eaLiberty Dome\u670d\u52d9\u5668\u3002
\u95dc\u65bc\u4f5c\u8005\uff1a
\n\u767e\u5ea6ID\uff1ahuanghongxun20
\nmcbbs\uff1ahuanghongxun
\n\u90f5\u7bb1\uff1ahuanghongxun2008@126.com
\nMinecraft Forum ID: klkl6523
\n\u6b61\u8fce\u63d0\u4ea4Bug\u54e6
\nCopyright (c) 2013-2015 huangyuhui.
\u514d\u8cac\u8072\u660e\uff1aMinecraft\u8edf\u9ad4\u7248\u6b0a\u6b78Mojang AB\u6240\u6709\uff0c\u904a\u6232\u7531\u65bc\u8aa4\u64cd\u4f5c\u672c\u555f\u52d5\u5668\u800c\u4e1f\u5931\u6578\u64da\u7684\u6982\u4e0d\u8ca0\u8cac\u3002
\u672c\u555f\u52d5\u5668\u5728GPLv3\u5354\u8b70\u4e0b\u958b\u6e90:http://github.com/huanghongxun/HMCL/
\u672c\u8edf\u9ad4\u4f7f\u7528\u4e86\u57fa\u65bcApache License 2.0\u7684Gson\u9805\u76ee\uff0c\u611f\u8b1d\u8ca2\u737b\u8005\u3002 launcher.download_source=\u4e0b\u8f09\u6e90 launcher.background_location=\u80cc\u666f\u5730\u5740 launcher.exit_failed=\u5f37\u5236\u9000\u51fa\u5931\u6557\uff0c\u53ef\u80fd\u662fForge 1.7.10\u53ca\u66f4\u9ad8\u7248\u672c\u5c0e\u81f4\u7684\uff0c\u7121\u6cd5\u89e3\u6c7a\u3002 diff --git a/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N_zh_CN.properties b/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N_zh_CN.properties index 60b8772ee..73a5df1b3 100755 --- a/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N_zh_CN.properties +++ b/HMCLAPI/src/main/resources/org/jackhuang/hellominecraft/launcher/I18N_zh_CN.properties @@ -260,7 +260,7 @@ mainwindow.enter_script_name=\u8f93\u5165\u8981\u751f\u6210\u811a\u672c\u7684\u6 mainwindow.make_launch_succeed=\u542f\u52a8\u811a\u672c\u5df2\u751f\u6210\u5b8c\u6bd5: mainwindow.no_version=\u672a\u627e\u5230\u4efb\u4f55\u7248\u672c\uff0c\u662f\u5426\u8fdb\u5165\u6e38\u620f\u4e0b\u8f7d\uff1f -launcher.about=\u9ed8\u8ba4\u80cc\u666f\u56fe\u6765\u81eaLiberty Dome\u670d\u52a1\u5668\u3002
\u5173\u4e8e\u4f5c\u8005\uff1a
\n\u767e\u5ea6ID\uff1ahuanghongxun20
\nmcbbs\uff1ahuanghongxun
\n\u90ae\u7bb1\uff1ahuanghongxun2008@126.com
\nMinecraft Forum ID: klkl6523
\n\u6b22\u8fce\u63d0\u4ea4Bug\u54e6
\nCopyright (c) 2013-2015 huangyuhui.
\u514d\u8d23\u58f0\u660e\uff1aMinecraft\u8f6f\u4ef6\u7248\u6743\u5f52Mojang AB\u6240\u6709\uff0c\u6e38\u620f\u7531\u4e8e\u8bef\u64cd\u4f5c\u672c\u542f\u52a8\u5668\u800c\u4e22\u5931\u6570\u636e\u7684\u6982\u4e0d\u8d1f\u8d23\u3002
\u672c\u542f\u52a8\u5668\u5728GPLv3\u534f\u8bae\u4e0b\u5f00\u6e90:https://github.com/huanghongxun/HMCL/
\u672c\u8f6f\u4ef6\u4f7f\u7528\u4e86\u57fa\u4e8eApache License 2.0\u7684RxJava\u548cGson\u9879\u76ee\uff0c\u611f\u8c22\u8d21\u732e\u8005\u3002 +launcher.about=\u9ed8\u8ba4\u80cc\u666f\u56fe\u6765\u81eaLiberty Dome\u670d\u52a1\u5668\u3002
\u5173\u4e8e\u4f5c\u8005\uff1a
\n\u767e\u5ea6ID\uff1ahuanghongxun20
\nmcbbs\uff1ahuanghongxun
\n\u90ae\u7bb1\uff1ahuanghongxun2008@126.com
\nMinecraft Forum ID: klkl6523
\n\u6b22\u8fce\u63d0\u4ea4Bug\u54e6
\nCopyright (c) 2013-2015 huangyuhui.
\u514d\u8d23\u58f0\u660e\uff1aMinecraft\u8f6f\u4ef6\u7248\u6743\u5f52Mojang AB\u6240\u6709\uff0c\u6e38\u620f\u7531\u4e8e\u8bef\u64cd\u4f5c\u672c\u542f\u52a8\u5668\u800c\u4e22\u5931\u6570\u636e\u7684\u6982\u4e0d\u8d1f\u8d23\u3002
\u672c\u542f\u52a8\u5668\u5728GPLv3\u534f\u8bae\u4e0b\u5f00\u6e90:https://github.com/huanghongxun/HMCL/
\u672c\u8f6f\u4ef6\u4f7f\u7528\u4e86\u57fa\u4e8eApache License 2.0\u7684Gson\u9879\u76ee\uff0c\u611f\u8c22\u8d21\u732e\u8005\u3002 launcher.download_source=\u4e0b\u8f7d\u6e90 launcher.background_location=\u80cc\u666f\u5730\u5740 launcher.exit_failed=\u5f3a\u5236\u9000\u51fa\u5931\u8d25\uff0c\u53ef\u80fd\u662fForge 1.7.10\u53ca\u66f4\u9ad8\u7248\u672c\u5bfc\u81f4\u7684\uff0c\u65e0\u6cd5\u89e3\u51b3\u3002 diff --git a/HMCLServer/src/main/java/org.jackhuang.hellominecraft.launcher/servers/ServerPlugin.java b/HMCLServer/src/main/java/org.jackhuang.hellominecraft.launcher/servers/ServerPlugin.java index b1a464371..d2cacac63 100755 --- a/HMCLServer/src/main/java/org.jackhuang.hellominecraft.launcher/servers/ServerPlugin.java +++ b/HMCLServer/src/main/java/org.jackhuang.hellominecraft.launcher/servers/ServerPlugin.java @@ -18,7 +18,6 @@ package org.jackhuang.hellominecraft.launcher.servers; import org.jackhuang.hellominecraft.launcher.api.IPlugin; -import org.jackhuang.hellominecraft.launcher.core.Profile; import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService; import org.jackhuang.hellominecraft.launcher.servers.mfcraft.MFCraftAuthenticator; import org.jackhuang.hellominecraft.launcher.servers.mfcraft.MFCraftMinecraftService; @@ -29,10 +28,11 @@ import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator; import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider; import org.jackhuang.hellominecraft.launcher.core.auth.YggdrasilAuthenticator; import org.jackhuang.hellominecraft.launcher.core.version.ServerInfo; +import org.jackhuang.hellominecraft.launcher.settings.Profile; import org.jackhuang.hellominecraft.launcher.views.MainFrame; import org.jackhuang.hellominecraft.launcher.views.ServerListView; import org.jackhuang.hellominecraft.utils.functions.Consumer; -import org.jackhuang.hellominecraft.views.Selector; +import org.jackhuang.hellominecraft.utils.views.Selector; /** * diff --git a/HMCLServer/src/main/java/org.jackhuang.hellominecraft.launcher/servers/mfcraft/CheckModsMinecraftProvider.java b/HMCLServer/src/main/java/org.jackhuang.hellominecraft.launcher/servers/mfcraft/CheckModsMinecraftProvider.java index d1a2d376a..296f54760 100755 --- a/HMCLServer/src/main/java/org.jackhuang.hellominecraft.launcher/servers/mfcraft/CheckModsMinecraftProvider.java +++ b/HMCLServer/src/main/java/org.jackhuang.hellominecraft.launcher/servers/mfcraft/CheckModsMinecraftProvider.java @@ -18,11 +18,12 @@ package org.jackhuang.hellominecraft.launcher.servers.mfcraft; import java.io.IOException; -import org.jackhuang.hellominecraft.HMCLog; +import org.jackhuang.hellominecraft.utils.logging.HMCLog; import org.jackhuang.hellominecraft.launcher.core.service.IMinecraftService; import org.jackhuang.hellominecraft.launcher.servers.ServerPlugin; -import org.jackhuang.hellominecraft.launcher.core.version.MinecraftModService; +import org.jackhuang.hellominecraft.launcher.core.mod.MinecraftModService; import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersionManager; +import org.jackhuang.hellominecraft.launcher.utils.DefaultMinecraftService; import org.jackhuang.hellominecraft.utils.ArrayUtils; /** @@ -39,7 +40,7 @@ public class CheckModsMinecraftProvider extends MinecraftVersionManager { public boolean onLaunch() { try { super.onLaunch(); - String[] md5s = ((MinecraftModService) service.mod()).checkMd5s(); + String[] md5s = ((MinecraftModService) service.mod()).checkMd5s(((DefaultMinecraftService) service).getProfile().getSelectedVersion()); String[] md5 = ServerPlugin.lastServerInfo.md5; return ArrayUtils.equals(md5s, md5); } catch (IOException ex) { diff --git a/HMCLServer/src/main/java/org.jackhuang.hellominecraft.launcher/servers/mfcraft/MFCraftAuthenticator.java b/HMCLServer/src/main/java/org.jackhuang.hellominecraft.launcher/servers/mfcraft/MFCraftAuthenticator.java index 246e242c6..9a42224e8 100755 --- a/HMCLServer/src/main/java/org.jackhuang.hellominecraft.launcher/servers/mfcraft/MFCraftAuthenticator.java +++ b/HMCLServer/src/main/java/org.jackhuang.hellominecraft.launcher/servers/mfcraft/MFCraftAuthenticator.java @@ -19,12 +19,12 @@ package org.jackhuang.hellominecraft.launcher.servers.mfcraft; import com.google.gson.JsonSyntaxException; import java.io.IOException; -import org.jackhuang.hellominecraft.C; import org.jackhuang.hellominecraft.launcher.core.auth.AuthenticationException; import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator; import org.jackhuang.hellominecraft.launcher.core.auth.LoginInfo; import static org.jackhuang.hellominecraft.launcher.core.auth.OfflineAuthenticator.getUUIDFromUserName; import org.jackhuang.hellominecraft.launcher.core.auth.UserProfileProvider; +import org.jackhuang.hellominecraft.utils.C; import org.jackhuang.hellominecraft.utils.NetUtils; /** diff --git a/HMCLServer/src/main/java/org.jackhuang.hellominecraft.launcher/servers/mfcraft/Servers.java b/HMCLServer/src/main/java/org.jackhuang.hellominecraft.launcher/servers/mfcraft/Servers.java index 09baa1881..60d4fda5c 100755 --- a/HMCLServer/src/main/java/org.jackhuang.hellominecraft.launcher/servers/mfcraft/Servers.java +++ b/HMCLServer/src/main/java/org.jackhuang.hellominecraft.launcher/servers/mfcraft/Servers.java @@ -19,11 +19,9 @@ package org.jackhuang.hellominecraft.launcher.servers.mfcraft; import java.io.IOException; import java.util.ArrayList; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.jackhuang.hellominecraft.C; -import org.jackhuang.hellominecraft.HMCLog; +import org.jackhuang.hellominecraft.utils.C; import org.jackhuang.hellominecraft.utils.NetUtils; +import org.jackhuang.hellominecraft.utils.logging.HMCLog; /** * diff --git a/HMCSM/src/main/java/org/jackhuang/hellominecraft/svrmgr/Main.java b/HMCSM/src/main/java/org/jackhuang/hellominecraft/svrmgr/Main.java index e3775279b..6e6ba63df 100755 --- a/HMCSM/src/main/java/org/jackhuang/hellominecraft/svrmgr/Main.java +++ b/HMCSM/src/main/java/org/jackhuang/hellominecraft/svrmgr/Main.java @@ -31,7 +31,6 @@ import org.jackhuang.hellominecraft.svrmgr.views.MainWindow; import org.jackhuang.hellominecraft.utils.VersionNumber; import org.jackhuang.hellominecraft.lookandfeel.HelloMinecraftLookAndFeel; import org.jackhuang.hellominecraft.utils.MessageBox; -import rx.concurrency.Schedulers; /** * @@ -57,7 +56,7 @@ public class Main { } catch (ParseException | UnsupportedLookAndFeelException ex) { HMCLog.warn("Failed to set look and feel", ex); } - UPDATE_CHECKER.process(false).subscribeOn(Schedulers.newThread()).subscribe(t -> MessageBox.Show("发现更新!" + t.version)); + UPDATE_CHECKER.process(false).reg(t -> MessageBox.Show("发现更新!" + t.version)).execute(); new MainWindow().setVisible(true); } catch (Throwable t) { HMCLog.err("There's something wrong when running server holder.", t);