From: David ‘Bombe’ Roden Date: Sun, 28 Sep 2014 20:38:45 +0000 (+0200) Subject: Remove option watcher, it’s not used anymore. X-Git-Tag: 0.9-rc1^2~3^2~88 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=3f91e22e512f81a2e11fa584e30f83da74e62177 Remove option watcher, it’s not used anymore. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Options.java b/src/main/java/net/pterodactylus/sone/core/Options.java index d23926d..34fc9a3 100644 --- a/src/main/java/net/pterodactylus/sone/core/Options.java +++ b/src/main/java/net/pterodactylus/sone/core/Options.java @@ -79,32 +79,7 @@ public class Options { } /** - * Interface for objects that want to be notified when an option changes its - * value. - * - * @param - * The type of the option - * @author David ‘Bombe’ Roden - */ - public static interface OptionWatcher { - - /** - * Notifies an object that an option has been changed. - * - * @param option - * The option that has changed - * @param oldValue - * The old value of the option - * @param newValue - * The new value of the option - */ - public void optionChanged(Option option, T oldValue, T newValue); - - } - - /** - * Basic implementation of an {@link Option} that notifies an - * {@link OptionWatcher} if the value changes. + * Basic implementation of an {@link Option}. * * @param * The type of the option @@ -121,9 +96,6 @@ public class Options { /** The validator. */ private Predicate validator; - /** The option watcher. */ - private final OptionWatcher optionWatcher; - /** * Creates a new default option. * @@ -131,7 +103,7 @@ public class Options { * The default value of the option */ public DefaultOption(T defaultValue) { - this(defaultValue, (OptionWatcher) null); + this(defaultValue, null); } /** @@ -143,35 +115,8 @@ public class Options { * The validator for value validation (may be {@code null}) */ public DefaultOption(T defaultValue, Predicate validator) { - this(defaultValue, validator, null); - } - - /** - * Creates a new default option. - * - * @param defaultValue - * The default value of the option - * @param optionWatchers - * The option watchers (may be {@code null}) - */ - public DefaultOption(T defaultValue, OptionWatcher optionWatchers) { - this(defaultValue, null, optionWatchers); - } - - /** - * Creates a new default option. - * - * @param defaultValue - * The default value of the option - * @param validator - * The validator for value validation (may be {@code null}) - * @param optionWatcher - * The option watcher (may be {@code null}) - */ - public DefaultOption(T defaultValue, Predicate validator, OptionWatcher optionWatcher) { this.defaultValue = defaultValue; this.validator = validator; - this.optionWatcher = optionWatcher; } /** @@ -211,11 +156,6 @@ public class Options { } T oldValue = this.value; this.value = value; - if (!get().equals(oldValue)) { - if (optionWatcher != null) { - optionWatcher.optionChanged(this, oldValue, get()); - } - } } } diff --git a/src/test/java/net/pterodactylus/sone/core/DefaultOptionTest.java b/src/test/java/net/pterodactylus/sone/core/DefaultOptionTest.java index 8a1f8d5..6c4bf66 100644 --- a/src/test/java/net/pterodactylus/sone/core/DefaultOptionTest.java +++ b/src/test/java/net/pterodactylus/sone/core/DefaultOptionTest.java @@ -11,7 +11,6 @@ import javax.annotation.Nullable; import net.pterodactylus.sone.core.Options.DefaultOption; import net.pterodactylus.sone.core.Options.Option; -import net.pterodactylus.sone.core.Options.OptionWatcher; import com.google.common.base.Predicate; import org.junit.Test; @@ -66,37 +65,6 @@ public class DefaultOptionTest { } @Test - public void watcherIsNotifiedOnChange() { - final AtomicReference changedObject = new AtomicReference(); - Object newValue = new Object(); - DefaultOption defaultOption = new DefaultOption(defaultValue, new OptionWatcher() { - @Override - public void optionChanged(Option option, Object oldValue, Object newValue) { - assertThat(oldValue, nullValue()); - changedObject.set(newValue); - } - }); - defaultOption.set(newValue); - assertThat(defaultOption.get(), is(newValue)); - assertThat(changedObject.get(), is(newValue)); - } - - @Test - public void watcherIsNotNotifiedIfValueIsSetTwice() { - final AtomicInteger changeCounter = new AtomicInteger(); - Object newValue = new Object(); - DefaultOption defaultOption = new DefaultOption(defaultValue, new OptionWatcher() { - @Override - public void optionChanged(Option option, Object oldValue, Object newValue) { - changeCounter.incrementAndGet(); - } - }); - defaultOption.set(newValue); - defaultOption.set(newValue); - assertThat(changeCounter.get(), is(1)); - } - - @Test public void defaultOptionValidatesObjectsCorrectly() { DefaultOption defaultOption = new DefaultOption(defaultValue, matchesAcceptedValue); assertThat(defaultOption.validate(acceptedValue), is(true));