From 428acf8306397d8e170c950d1ec88870ae45acfb Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 2 Jan 2013 12:53:25 +0100 Subject: [PATCH] De-generify main interfaces. --- .../java/net/pterodactylus/reactor/Action.java | 6 +-- src/main/java/net/pterodactylus/reactor/Query.java | 6 +-- .../java/net/pterodactylus/reactor/Reaction.java | 44 +++++----------------- .../java/net/pterodactylus/reactor/Trigger.java | 6 +-- .../pterodactylus/reactor/queries/FileQuery.java | 5 ++- .../reactor/triggers/FileExistenceTrigger.java | 11 ++++-- 6 files changed, 26 insertions(+), 52 deletions(-) diff --git a/src/main/java/net/pterodactylus/reactor/Action.java b/src/main/java/net/pterodactylus/reactor/Action.java index 9d743b2..5c6a13f 100644 --- a/src/main/java/net/pterodactylus/reactor/Action.java +++ b/src/main/java/net/pterodactylus/reactor/Action.java @@ -21,11 +21,9 @@ package net.pterodactylus.reactor; * An action is performed when a {@link Trigger} determines that two given * {@link State}s of a {@link Query} signify a change. * - * @param - * The type of the state * @author David ‘Bombe’ Roden */ -public interface Action { +public interface Action { /** * Performs the action. @@ -35,6 +33,6 @@ public interface Action { * @param previousState * The previous state of the system */ - void execute(S currentState, S previousState); + void execute(State currentState, State previousState); } diff --git a/src/main/java/net/pterodactylus/reactor/Query.java b/src/main/java/net/pterodactylus/reactor/Query.java index cc868bb..0b46a39 100644 --- a/src/main/java/net/pterodactylus/reactor/Query.java +++ b/src/main/java/net/pterodactylus/reactor/Query.java @@ -20,11 +20,9 @@ package net.pterodactylus.reactor; /** * A query is used to retrieve the current {@link State} of a system. * - * @param - * The type of the state * @author David ‘Bombe’ Roden */ -public interface Query { +public interface Query { /** * Retrieves the current state of the system. The returned state is never @@ -32,6 +30,6 @@ public interface Query { * * @return The current state of the system. */ - public S state(); + public State state(); } diff --git a/src/main/java/net/pterodactylus/reactor/Reaction.java b/src/main/java/net/pterodactylus/reactor/Reaction.java index f7a8c2c..e3cfb86 100644 --- a/src/main/java/net/pterodactylus/reactor/Reaction.java +++ b/src/main/java/net/pterodactylus/reactor/Reaction.java @@ -21,26 +21,18 @@ package net.pterodactylus.reactor; * 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 query to run. */ - private final Query query; + private final Query query; /** 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; @@ -55,7 +47,7 @@ public class Reaction { * @param action * The action to perform */ - public Reaction(Query query, Trigger trigger, Action action) { + public Reaction(Query query, Trigger trigger, Action action) { this.query = query; this.trigger = trigger; this.action = action; @@ -70,7 +62,7 @@ public class Reaction { * * @return The query to run */ - public Query query() { + public Query query() { return query; } @@ -79,7 +71,7 @@ public class Reaction { * * @return The trigger to detect changes */ - public Trigger trigger() { + public Trigger trigger() { return trigger; } @@ -88,29 +80,11 @@ public class Reaction { * * @return The action to perform */ - public Action action() { + public Action action() { return action; } /** - * Returns the current state of the query. - * - * @return The current state of the query - */ - public S currentState() { - return currentState; - } - - /** - * Returns the previous state of the query. - * - * @return The previous state of the query - */ - public S previousState() { - return previousState; - } - - /** * Returns the update interval of this reaction. * * @return The update interval of this reaction (in milliseconds) @@ -126,7 +100,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; } diff --git a/src/main/java/net/pterodactylus/reactor/Trigger.java b/src/main/java/net/pterodactylus/reactor/Trigger.java index 449b4fe..c4e1aab 100644 --- a/src/main/java/net/pterodactylus/reactor/Trigger.java +++ b/src/main/java/net/pterodactylus/reactor/Trigger.java @@ -25,11 +25,9 @@ import net.pterodactylus.reactor.states.FileState; * sizes but a trigger might only care about whether the file appeared or * disappeared since the last check. * - * @param - * The type of the state * @author David ‘Bombe’ Roden */ -public interface Trigger { +public interface Trigger { /** * Checks whether the given states warrant a change trigger. @@ -41,6 +39,6 @@ public interface Trigger { * @return {@code true} if the given states warrant a change trigger, * {@code false} otherwise */ - boolean triggers(S currentState, S previousState); + boolean triggers(State currentState, State previousState); } diff --git a/src/main/java/net/pterodactylus/reactor/queries/FileQuery.java b/src/main/java/net/pterodactylus/reactor/queries/FileQuery.java index 64a72f4..ac0e895 100644 --- a/src/main/java/net/pterodactylus/reactor/queries/FileQuery.java +++ b/src/main/java/net/pterodactylus/reactor/queries/FileQuery.java @@ -22,6 +22,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.io.File; import net.pterodactylus.reactor.Query; +import net.pterodactylus.reactor.State; import net.pterodactylus.reactor.states.FileState; /** @@ -29,7 +30,7 @@ import net.pterodactylus.reactor.states.FileState; * * @author David ‘Bombe’ Roden */ -public class FileQuery implements Query { +public class FileQuery implements Query { /** The name of the file to query. */ private final String filename; @@ -52,7 +53,7 @@ public class FileQuery implements Query { * {@inheritDoc} */ @Override - public FileState state() { + public State state() { File file = new File(filename); if (!file.exists()) { return new FileState(false, false, -1, -1); diff --git a/src/main/java/net/pterodactylus/reactor/triggers/FileExistenceTrigger.java b/src/main/java/net/pterodactylus/reactor/triggers/FileExistenceTrigger.java index 2be86ea..33f1993 100644 --- a/src/main/java/net/pterodactylus/reactor/triggers/FileExistenceTrigger.java +++ b/src/main/java/net/pterodactylus/reactor/triggers/FileExistenceTrigger.java @@ -17,15 +17,18 @@ package net.pterodactylus.reactor.triggers; +import net.pterodactylus.reactor.State; import net.pterodactylus.reactor.Trigger; import net.pterodactylus.reactor.states.FileState; +import com.google.common.base.Preconditions; + /** * A trigger that detects changes in the existence of a file. * * @author David ‘Bombe’ Roden */ -public class FileExistenceTrigger implements Trigger { +public class FileExistenceTrigger implements Trigger { // // TRIGGER METHODS @@ -35,8 +38,10 @@ public class FileExistenceTrigger implements Trigger { * {@inheritDoc} */ @Override - public boolean triggers(FileState previousState, FileState currentState) { - return previousState.exists() != currentState.exists(); + public boolean triggers(State previousState, State currentState) { + Preconditions.checkState(previousState instanceof FileState, "previousState is not a FileState"); + Preconditions.checkState(currentState instanceof FileState, "currentState is not a FileState"); + return ((FileState) previousState).exists() != ((FileState) currentState).exists(); } } -- 2.7.4