From: David ‘Bombe’ Roden Date: Mon, 7 Jan 2013 09:20:31 +0000 (+0100) Subject: Add display name to chains and reactions. X-Git-Tag: 0.1~51 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=b984a8b79ccaec6c2f97cc5c6cca60c6257dad05;p=rhynodge.git Add display name to chains and reactions. --- 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": {