From b984a8b79ccaec6c2f97cc5c6cca60c6257dad05 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 7 Jan 2013 10:20:31 +0100 Subject: [PATCH] Add display name to chains and reactions. --- .../java/net/pterodactylus/reactor/Reaction.java | 24 +++++++++++++++++++--- .../net/pterodactylus/reactor/loader/Chain.java | 17 +++++++++++++++ .../reactor/loader/ReactionLoader.java | 2 +- .../resources/chains/kickasstorrents-example.json | 1 + 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/pterodactylus/reactor/Reaction.java b/src/main/java/net/pterodactylus/reactor/Reaction.java index 59fad8f..65a637b 100644 --- a/src/main/java/net/pterodactylus/reactor/Reaction.java +++ b/src/main/java/net/pterodactylus/reactor/Reaction.java @@ -30,6 +30,9 @@ import com.google.common.collect.Lists; */ public class Reaction { + /** The name of this reaction. */ + private final String name; + /** The query to run. */ private final Query query; @@ -48,6 +51,8 @@ public class Reaction { /** * Creates a new reaction. * + * @param name + * The name of the reaction * @param query * The query to run * @param trigger @@ -55,13 +60,15 @@ public class Reaction { * @param action * The action to perform */ - public Reaction(Query query, Trigger trigger, Action action) { - this(query, Collections. emptyList(), trigger, action); + 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 @@ -71,7 +78,8 @@ public class Reaction { * @param action * The action to perform */ - public Reaction(Query query, List filters, 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; @@ -83,6 +91,16 @@ public class Reaction { // /** + * 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 diff --git a/src/main/java/net/pterodactylus/reactor/loader/Chain.java b/src/main/java/net/pterodactylus/reactor/loader/Chain.java index c367da0..8c98e50 100644 --- a/src/main/java/net/pterodactylus/reactor/loader/Chain.java +++ b/src/main/java/net/pterodactylus/reactor/loader/Chain.java @@ -168,6 +168,10 @@ public class Chain { @JsonProperty private boolean enabled; + /** The name of the chain. */ + @JsonProperty + private String name; + /** The query of the chain. */ @JsonProperty private Part query; @@ -198,6 +202,15 @@ public class Chain { } /** + * Returns the name of the chain. + * + * @return The name of the chain + */ + public String name() { + return name; + } + + /** * Returns the query of this chain. * * @return The query of this chain @@ -252,6 +265,7 @@ public class Chain { @Override public int hashCode() { int hashCode = 0; + hashCode ^= name.hashCode(); hashCode ^= query.hashCode(); for (Part filter : filters) { hashCode ^= filter.hashCode(); @@ -271,6 +285,9 @@ public class Chain { return false; } Chain chain = (Chain) object; + if (!name.equals(chain.name)) { + return false; + } if (!query.equals(chain.query)) { return false; } diff --git a/src/main/java/net/pterodactylus/reactor/loader/ReactionLoader.java b/src/main/java/net/pterodactylus/reactor/loader/ReactionLoader.java index 7016edb..a2c29aa 100644 --- a/src/main/java/net/pterodactylus/reactor/loader/ReactionLoader.java +++ b/src/main/java/net/pterodactylus/reactor/loader/ReactionLoader.java @@ -70,7 +70,7 @@ public class ReactionLoader { /* create action. */ Action action = createObject(chain.action().name(), "net.pterodactylus.reactor.actions", extractParameters(chain.action().parameters())); - return new Reaction(query, filters, trigger, action).setUpdateInterval(TimeUnit.SECONDS.toMillis(chain.updateInterval())); + return new Reaction(chain.name(), query, filters, trigger, action).setUpdateInterval(TimeUnit.SECONDS.toMillis(chain.updateInterval())); } // diff --git a/src/main/resources/chains/kickasstorrents-example.json b/src/main/resources/chains/kickasstorrents-example.json index 1473458..71125d7 100644 --- a/src/main/resources/chains/kickasstorrents-example.json +++ b/src/main/resources/chains/kickasstorrents-example.json @@ -1,5 +1,6 @@ { "enabled": false, + "name": "Example Reaction", "query": { -- 2.7.4