From e70b242c016709c41a09114996806fbdef30dd80 Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Sun, 7 Jan 2018 00:41:47 -0600 Subject: model: Remove confusing uses of completion chaining This looks like the builder pattern, but isn't. Signed-off-by: Samuel Holland --- .../java/com/wireguard/android/model/Tunnel.java | 9 +++---- .../com/wireguard/android/model/TunnelManager.java | 30 ++++++++++++++-------- 2 files changed, 23 insertions(+), 16 deletions(-) (limited to 'app') diff --git a/app/src/main/java/com/wireguard/android/model/Tunnel.java b/app/src/main/java/com/wireguard/android/model/Tunnel.java index 9bb7406c..e61ea095 100644 --- a/app/src/main/java/com/wireguard/android/model/Tunnel.java +++ b/app/src/main/java/com/wireguard/android/model/Tunnel.java @@ -95,24 +95,21 @@ public class Tunnel extends BaseObservable implements Keyed { return CompletableFuture.completedFuture(statistics); } - Config onConfigChanged(final Config config) { + void onConfigChanged(final Config config) { this.config = config; notifyPropertyChanged(BR.config); - return config; } - State onStateChanged(final State state) { + void onStateChanged(final State state) { if (state != State.UP) onStatisticsChanged(null); this.state = state; notifyPropertyChanged(BR.state); - return state; } - Statistics onStatisticsChanged(final Statistics statistics) { + void onStatisticsChanged(final Statistics statistics) { this.statistics = statistics; notifyPropertyChanged(BR.statistics); - return statistics; } public CompletionStage setConfig(@NonNull final Config config) { diff --git a/app/src/main/java/com/wireguard/android/model/TunnelManager.java b/app/src/main/java/com/wireguard/android/model/TunnelManager.java index e802c152..beed16fe 100644 --- a/app/src/main/java/com/wireguard/android/model/TunnelManager.java +++ b/app/src/main/java/com/wireguard/android/model/TunnelManager.java @@ -85,18 +85,24 @@ public final class TunnelManager { } CompletionStage getTunnelConfig(final Tunnel tunnel) { - return asyncWorker.supplyAsync(() -> configStore.load(tunnel.getName())) - .thenApply(tunnel::onConfigChanged); + final CompletionStage completion = + asyncWorker.supplyAsync(() -> configStore.load(tunnel.getName())); + completion.thenAccept(tunnel::onConfigChanged); + return completion; } CompletionStage getTunnelState(final Tunnel tunnel) { - return asyncWorker.supplyAsync(() -> backend.getState(tunnel)) - .thenApply(tunnel::onStateChanged); + final CompletionStage completion = + asyncWorker.supplyAsync(() -> backend.getState(tunnel)); + completion.thenAccept(tunnel::onStateChanged); + return completion; } CompletionStage getTunnelStatistics(final Tunnel tunnel) { - return asyncWorker.supplyAsync(() -> backend.getStatistics(tunnel)) - .thenApply(tunnel::onStatisticsChanged); + final CompletionStage completion = + asyncWorker.supplyAsync(() -> backend.getStatistics(tunnel)); + completion.thenAccept(tunnel::onStatisticsChanged); + return completion; } public ObservableKeyedList getTunnels() { @@ -136,14 +142,18 @@ public final class TunnelManager { } CompletionStage setTunnelConfig(final Tunnel tunnel, final Config config) { - return asyncWorker.supplyAsync(() -> { + final CompletionStage completion = asyncWorker.supplyAsync(() -> { final Config appliedConfig = backend.applyConfig(tunnel, config); return configStore.save(tunnel.getName(), appliedConfig); - }).thenApply(tunnel::onConfigChanged); + }); + completion.thenAccept(tunnel::onConfigChanged); + return completion; } CompletionStage setTunnelState(final Tunnel tunnel, final State state) { - return asyncWorker.supplyAsync(() -> backend.setState(tunnel, state)) - .thenApply(tunnel::onStateChanged); + final CompletionStage completion = + asyncWorker.supplyAsync(() -> backend.setState(tunnel, state)); + completion.thenAccept(tunnel::onStateChanged); + return completion; } } -- cgit v1.2.3