X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Freactor%2FReaction.java;h=65a637bf468faef2471224e3e9e64efb44d7e6e1;hb=13a4fe6bece23b3dd561de657cf9bb7ea307e2b6;hp=f7a8c2c49437c676df8d14ce3ff76b61283ee6a8;hpb=4aa0a149254611a863c784069e4ca0b7ca9b9e8f;p=rhynodge.git diff --git a/src/main/java/net/pterodactylus/reactor/Reaction.java b/src/main/java/net/pterodactylus/reactor/Reaction.java index f7a8c2c..65a637b 100644 --- a/src/main/java/net/pterodactylus/reactor/Reaction.java +++ b/src/main/java/net/pterodactylus/reactor/Reaction.java @@ -17,30 +17,33 @@ 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 - * The type of the state * @author David ‘Bombe’ Roden */ -public class Reaction { +public class Reaction { + + /** The name of this reaction. */ + private final String name; /** The query to run. */ - private final Query query; + private final Query query; + + /** The filters to run. */ + private final List filters = Lists.newArrayList(); /** The trigger to detect changes. */ - private final Trigger trigger; + private final Trigger trigger; /** The action to perform. */ - private final Action action; - - /** The current state of the query. */ - private S currentState; - - /** The previous state of the query. */ - private S previousState; + private final Action action; /** The interval in which to run queries (in milliseconds). */ private long updateInterval; @@ -48,15 +51,37 @@ public class Reaction { /** * 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. 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 query, Trigger trigger, Action action) { + public Reaction(String name, Query query, List filters, Trigger trigger, Action action) { + this.name = name; this.query = query; + this.filters.addAll(filters); this.trigger = trigger; this.action = action; } @@ -66,48 +91,49 @@ public class Reaction { // /** - * Returns the query to run. + * Returns the name of this reaction. This name is solely used for display + * purposes and does not need to be unique. * - * @return The query to run + * @return The name of this reaction */ - public Query query() { - return query; + public String name() { + return name; } /** - * Returns the trigger to detect changes. + * Returns the query to run. * - * @return The trigger to detect changes + * @return The query to run */ - public Trigger trigger() { - return trigger; + public Query query() { + return query; } /** - * Returns the action to perform. + * Returns the filters to run. * - * @return The action to perform + * @return The filters to run */ - public Action action() { - return action; + public Iterable filters() { + return filters; } /** - * Returns the current state of the query. + * Returns the trigger to detect changes. * - * @return The current state of the query + * @return The trigger to detect changes */ - public S currentState() { - return currentState; + public Trigger trigger() { + return trigger; } /** - * Returns the previous state of the query. + * Returns the action to perform. * - * @return The previous state of the query + * @return The action to perform */ - public S previousState() { - return previousState; + public Action action() { + return action; } /** @@ -126,7 +152,7 @@ public class Reaction { * The update interval of this reaction (in milliseconds) * @return This reaction */ - public Reaction setUpdateInterval(long updateInterval) { + public Reaction setUpdateInterval(long updateInterval) { this.updateInterval = updateInterval; return this; }