2 * Rhynodge - Reaction.java - Copyright © 2013 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.rhynodge;
20 import java.util.Collections;
21 import java.util.List;
23 import com.google.common.collect.Lists;
26 * A {@code Reaction} binds together {@link Query}s, {@link Trigger}s, and
27 * {@link Action}s, and it stores the intermediary {@link State}s.
29 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
31 public class Reaction {
33 /** The name of this reaction. */
34 private final String name;
36 /** The query to run. */
37 private final Query query;
39 /** The filters to run. */
40 private final List<Filter> filters = Lists.newArrayList();
42 /** The trigger to detect changes. */
43 private final Trigger trigger;
45 /** The action to perform. */
46 private final Action action;
48 /** The interval in which to run queries (in milliseconds). */
49 private long updateInterval;
52 * Creates a new reaction.
55 * The name of the reaction
59 * The trigger to detect changes
61 * The action to perform
63 public Reaction(String name, Query query, Trigger trigger, Action action) {
64 this(name, query, Collections.<Filter> emptyList(), trigger, action);
68 * Creates a new reaction.
71 * The name of the reaction
77 * The trigger to detect changes
79 * The action to perform
81 public Reaction(String name, Query query, List<Filter> filters, Trigger trigger, Action action) {
84 this.filters.addAll(filters);
85 this.trigger = trigger;
94 * Returns the name of this reaction. This name is solely used for display
95 * purposes and does not need to be unique.
97 * @return The name of this reaction
99 public String name() {
104 * Returns the query to run.
106 * @return The query to run
108 public Query query() {
113 * Returns the filters to run.
115 * @return The filters to run
117 public Iterable<Filter> filters() {
122 * Returns the trigger to detect changes.
124 * @return The trigger to detect changes
126 public Trigger trigger() {
131 * Returns the action to perform.
133 * @return The action to perform
135 public Action action() {
140 * Returns the update interval of this reaction.
142 * @return The update interval of this reaction (in milliseconds)
144 public long updateInterval() {
145 return updateInterval;
149 * Sets the update interval of this reaction.
151 * @param updateInterval
152 * The update interval of this reaction (in milliseconds)
153 * @return This reaction
155 public Reaction setUpdateInterval(long updateInterval) {
156 this.updateInterval = updateInterval;