Ignore chains and states default directories.
[rhynodge.git] / src / main / java / net / pterodactylus / reactor / Reaction.java
index 0e0b359..65a637b 100644 (file)
 
 package net.pterodactylus.reactor;
 
+import java.util.Collections;
+import java.util.List;
+
+import com.google.common.collect.Lists;
+
 /**
  * A {@code Reaction} binds together {@link Query}s, {@link Trigger}s, and
  * {@link Action}s, and it stores the intermediary {@link State}s.
  *
- * @param <S>
- *            The type of the state
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
-public class Reaction<S extends State> {
+public class Reaction {
+
+       /** The name of this reaction. */
+       private final String name;
 
        /** The query to run. */
-       private final Query<S> query;
+       private final Query query;
+
+       /** The filters to run. */
+       private final List<Filter> filters = Lists.newArrayList();
 
        /** The trigger to detect changes. */
-       private final Trigger<S> trigger;
+       private final Trigger trigger;
 
        /** The action to perform. */
-       private final Action<S> action;
+       private final Action action;
 
-       /** The current state of the query. */
-       private S currentState;
+       /** The interval in which to run queries (in milliseconds). */
+       private long updateInterval;
 
-       /** The previous state of the query. */
-       private S previousState;
+       /**
+        * Creates a new reaction.
+        *
+        * @param name
+        *            The name of the reaction
+        * @param query
+        *            The query to run
+        * @param trigger
+        *            The trigger to detect changes
+        * @param action
+        *            The action to perform
+        */
+       public Reaction(String name, Query query, Trigger trigger, Action action) {
+               this(name, query, Collections.<Filter> emptyList(), trigger, action);
+       }
 
        /**
         * Creates a new reaction.
         *
+        * @param name
+        *            The name of the reaction
         * @param query
         *            The query to run
+        * @param filters
+        *            The filters to run
         * @param trigger
         *            The trigger to detect changes
         * @param action
         *            The action to perform
         */
-       public Reaction(Query<S> query, Trigger<S> trigger, Action<S> action) {
+       public Reaction(String name, Query query, List<Filter> filters, Trigger trigger, Action action) {
+               this.name = name;
                this.query = query;
+               this.filters.addAll(filters);
                this.trigger = trigger;
                this.action = action;
        }
@@ -63,20 +91,39 @@ public class Reaction<S extends State> {
        //
 
        /**
+        * Returns the name of this reaction. This name is solely used for display
+        * purposes and does not need to be unique.
+        *
+        * @return The name of this reaction
+        */
+       public String name() {
+               return name;
+       }
+
+       /**
         * Returns the query to run.
         *
         * @return The query to run
         */
-       public Query<S> query() {
+       public Query query() {
                return query;
        }
 
        /**
+        * Returns the filters to run.
+        *
+        * @return The filters to run
+        */
+       public Iterable<Filter> filters() {
+               return filters;
+       }
+
+       /**
         * Returns the trigger to detect changes.
         *
         * @return The trigger to detect changes
         */
-       public Trigger<S> trigger() {
+       public Trigger trigger() {
                return trigger;
        }
 
@@ -85,26 +132,29 @@ public class Reaction<S extends State> {
         *
         * @return The action to perform
         */
-       public Action<S> action() {
+       public Action action() {
                return action;
        }
 
        /**
-        * Returns the current state of the query.
+        * Returns the update interval of this reaction.
         *
-        * @return The current state of the query
+        * @return The update interval of this reaction (in milliseconds)
         */
-       public S currentState() {
-               return currentState;
+       public long updateInterval() {
+               return updateInterval;
        }
 
        /**
-        * Returns the previous state of the query.
+        * Sets the update interval of this reaction.
         *
-        * @return The previous state of the query
+        * @param updateInterval
+        *            The update interval of this reaction (in milliseconds)
+        * @return This reaction
         */
-       public S previousState() {
-               return previousState;
+       public Reaction setUpdateInterval(long updateInterval) {
+               this.updateInterval = updateInterval;
+               return this;
        }
 
 }