Rename project to “Rhynodge.”
[rhynodge.git] / src / main / java / net / pterodactylus / rhynodge / Reaction.java
1 /*
2  * Rhynodge - Reaction.java - Copyright © 2013 David Roden
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.pterodactylus.rhynodge;
19
20 import java.util.Collections;
21 import java.util.List;
22
23 import com.google.common.collect.Lists;
24
25 /**
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.
28  *
29  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
30  */
31 public class Reaction {
32
33         /** The name of this reaction. */
34         private final String name;
35
36         /** The query to run. */
37         private final Query query;
38
39         /** The filters to run. */
40         private final List<Filter> filters = Lists.newArrayList();
41
42         /** The trigger to detect changes. */
43         private final Trigger trigger;
44
45         /** The action to perform. */
46         private final Action action;
47
48         /** The interval in which to run queries (in milliseconds). */
49         private long updateInterval;
50
51         /**
52          * Creates a new reaction.
53          *
54          * @param name
55          *            The name of the reaction
56          * @param query
57          *            The query to run
58          * @param trigger
59          *            The trigger to detect changes
60          * @param action
61          *            The action to perform
62          */
63         public Reaction(String name, Query query, Trigger trigger, Action action) {
64                 this(name, query, Collections.<Filter> emptyList(), trigger, action);
65         }
66
67         /**
68          * Creates a new reaction.
69          *
70          * @param name
71          *            The name of the reaction
72          * @param query
73          *            The query to run
74          * @param filters
75          *            The filters to run
76          * @param trigger
77          *            The trigger to detect changes
78          * @param action
79          *            The action to perform
80          */
81         public Reaction(String name, Query query, List<Filter> filters, Trigger trigger, Action action) {
82                 this.name = name;
83                 this.query = query;
84                 this.filters.addAll(filters);
85                 this.trigger = trigger;
86                 this.action = action;
87         }
88
89         //
90         // ACCESSORS
91         //
92
93         /**
94          * Returns the name of this reaction. This name is solely used for display
95          * purposes and does not need to be unique.
96          *
97          * @return The name of this reaction
98          */
99         public String name() {
100                 return name;
101         }
102
103         /**
104          * Returns the query to run.
105          *
106          * @return The query to run
107          */
108         public Query query() {
109                 return query;
110         }
111
112         /**
113          * Returns the filters to run.
114          *
115          * @return The filters to run
116          */
117         public Iterable<Filter> filters() {
118                 return filters;
119         }
120
121         /**
122          * Returns the trigger to detect changes.
123          *
124          * @return The trigger to detect changes
125          */
126         public Trigger trigger() {
127                 return trigger;
128         }
129
130         /**
131          * Returns the action to perform.
132          *
133          * @return The action to perform
134          */
135         public Action action() {
136                 return action;
137         }
138
139         /**
140          * Returns the update interval of this reaction.
141          *
142          * @return The update interval of this reaction (in milliseconds)
143          */
144         public long updateInterval() {
145                 return updateInterval;
146         }
147
148         /**
149          * Sets the update interval of this reaction.
150          *
151          * @param updateInterval
152          *            The update interval of this reaction (in milliseconds)
153          * @return This reaction
154          */
155         public Reaction setUpdateInterval(long updateInterval) {
156                 this.updateInterval = updateInterval;
157                 return this;
158         }
159
160 }