2 * Reactor - 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.reactor;
21 * A {@code Reaction} binds together {@link Query}s, {@link Trigger}s, and
22 * {@link Action}s, and it stores the intermediary {@link State}s.
25 * The type of the state
26 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
28 public class Reaction<S extends State> {
30 /** The query to run. */
31 private final Query<S> query;
33 /** The trigger to detect changes. */
34 private final Trigger<S> trigger;
36 /** The action to perform. */
37 private final Action<S> action;
39 /** The current state of the query. */
40 private S currentState;
42 /** The previous state of the query. */
43 private S previousState;
46 * Creates a new reaction.
51 * The trigger to detect changes
53 * The action to perform
55 public Reaction(Query<S> query, Trigger<S> trigger, Action<S> action) {
57 this.trigger = trigger;
66 * Returns the query to run.
68 * @return The query to run
70 public Query<S> query() {
75 * Returns the trigger to detect changes.
77 * @return The trigger to detect changes
79 public Trigger<S> trigger() {
84 * Returns the action to perform.
86 * @return The action to perform
88 public Action<S> action() {
93 * Returns the current state of the query.
95 * @return The current state of the query
97 public S currentState() {
102 * Returns the previous state of the query.
104 * @return The previous state of the query
106 public S previousState() {
107 return previousState;