From bc11c5c7ea2d08b5cc3acd62a0af06459997454c Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 25 Oct 2010 08:21:06 +0200 Subject: [PATCH] Make the option watcher optional. --- src/main/java/net/pterodactylus/sone/core/Options.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Options.java b/src/main/java/net/pterodactylus/sone/core/Options.java index 04010da..752c36c 100644 --- a/src/main/java/net/pterodactylus/sone/core/Options.java +++ b/src/main/java/net/pterodactylus/sone/core/Options.java @@ -1,6 +1,9 @@ package net.pterodactylus.sone.core; +import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -93,19 +96,19 @@ public class Options { private T value; /** The option watcher. */ - private final OptionWatcher optionWatcher; + private final List> optionWatchers = new ArrayList>(); /** * Creates a new default option. * * @param defaultValue * The default value of the option - * @param optionWatcher - * The option watcher + * @param optionWatchers + * The option watchers */ - public DefaultOption(T defaultValue, OptionWatcher optionWatcher) { + public DefaultOption(T defaultValue, OptionWatcher... optionWatchers) { this.defaultValue = defaultValue; - this.optionWatcher = optionWatcher; + this.optionWatchers.addAll(Arrays.asList(optionWatchers)); } /** @@ -143,7 +146,9 @@ public class Options { T oldValue = this.value; this.value = value; if (!get().equals(oldValue)) { - optionWatcher.optionChanged(this, oldValue, get()); + for (OptionWatcher optionWatcher : optionWatchers) { + optionWatcher.optionChanged(this, oldValue, get()); + } } } -- 2.7.4