From: David ‘Bombe’ Roden Date: Mon, 25 Oct 2010 06:21:06 +0000 (+0200) Subject: Make the option watcher optional. X-Git-Tag: 0.1-RC1~35 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=bc11c5c7ea2d08b5cc3acd62a0af06459997454c;p=Sone.git Make the option watcher optional. --- 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()); + } } }