2 * Reactor - Chain.java - Copyright © 2013 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.reactor.loader;
20 import java.util.ArrayList;
21 import java.util.List;
23 import com.fasterxml.jackson.annotation.JsonProperty;
26 * Model for chain definitions.
28 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
35 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
37 public static class Parameter {
39 /** The name of the parameter. */
43 /** The value of the parameter. */
48 * Returns the name of the parameter.
50 * @return The name of the parameter
52 public String name() {
57 * Returns the value of the parameter.
59 * @return The value of the parameter
61 public String value() {
69 public int hashCode() {
71 hashCode ^= name.hashCode();
72 hashCode ^= value.hashCode();
80 public boolean equals(Object object) {
81 if (!(object instanceof Parameter)) {
84 Parameter parameter = (Parameter) object;
85 if (!name.equals(parameter.name)) {
88 if (!value.equals(parameter.value)) {
97 * Defines a part of a chain.
99 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
101 public static class Part {
103 /** The class name of the part. */
104 @JsonProperty(value = "class")
107 /** The parameters of the part. */
109 private List<Parameter> parameters = new ArrayList<Parameter>();
112 * Returns the name of the part’s class.
114 * @return The name of the part’s class
116 public String name() {
121 * Returns the parameters of the part.
123 * @return The parameters of the part
125 public List<Parameter> parameters() {
133 public int hashCode() {
135 hashCode ^= name.hashCode();
136 for (Parameter parameter : parameters) {
137 hashCode ^= parameter.hashCode();
146 public boolean equals(Object object) {
147 if (!(object instanceof Part)) {
150 Part part = (Part) object;
151 if (!name.equals(part.name)) {
154 if (parameters.size() != part.parameters.size()) {
157 for (int parameterIndex = 0; parameterIndex < parameters.size(); ++parameterIndex) {
158 if (!parameters.get(parameterIndex).equals(part.parameters.get(parameterIndex))) {
167 /** Whether this chain is enabled. */
169 private boolean enabled;
171 /** The query of the chain. */
175 /** The filters of the chain. */
177 private List<Part> filters = new ArrayList<Part>();
179 /** The trigger of the chain. */
181 private Part trigger;
183 /** The action of the chain. */
187 /** Interval between updates (in seconds). */
189 private int updateInterval;
192 * Returns whether this chain is enabled.
194 * @return {@code true} if this chain is enabled, {@code false} otherwise
196 public boolean enabled() {
201 * Returns the query of this chain.
203 * @return The query of this chain
205 public Part query() {
210 * Returns the filters of this chain.
212 * @return The filters of this chain
214 public List<Part> filters() {
219 * Returns the trigger of this chain.
221 * @return The trigger of this chain
223 public Part trigger() {
228 * Returns the action of this chain.
230 * @return The action of this chain
232 public Part action() {
237 * Returns the update interval of the chain.
239 * @return The update interval (in seconds)
241 public int updateInterval() {
242 return updateInterval;
253 public int hashCode() {
255 hashCode ^= query.hashCode();
256 for (Part filter : filters) {
257 hashCode ^= filter.hashCode();
259 hashCode ^= trigger.hashCode();
260 hashCode ^= action.hashCode();
261 hashCode ^= updateInterval;
269 public boolean equals(Object object) {
270 if (!(object instanceof Chain)) {
273 Chain chain = (Chain) object;
274 if (!query.equals(chain.query)) {
277 if (filters.size() != chain.filters.size()) {
280 for (int filterIndex = 0; filterIndex < filters.size(); ++filterIndex) {
281 if (!filters.get(filterIndex).equals(chain.filters.get(filterIndex))) {
285 if (!trigger.equals(chain.trigger)) {
288 if (!action.equals(chain.action)) {
291 if (updateInterval != chain.updateInterval) {