2 * Rhynodge - 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.rhynodge.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 return value.equals(parameter.value);
94 * Defines a part of a chain.
96 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
98 public static class Part {
100 /** The class name of the part. */
101 @JsonProperty(value = "class")
104 /** The parameters of the part. */
106 private List<Parameter> parameters = new ArrayList<Parameter>();
109 * Returns the name of the part’s class.
111 * @return The name of the part’s class
113 public String name() {
118 * Returns the parameters of the part.
120 * @return The parameters of the part
122 public List<Parameter> parameters() {
130 public int hashCode() {
132 hashCode ^= name.hashCode();
133 for (Parameter parameter : parameters) {
134 hashCode ^= parameter.hashCode();
143 public boolean equals(Object object) {
144 if (!(object instanceof Part)) {
147 Part part = (Part) object;
148 if (!name.equals(part.name)) {
151 if (parameters.size() != part.parameters.size()) {
154 for (int parameterIndex = 0; parameterIndex < parameters.size(); ++parameterIndex) {
155 if (!parameters.get(parameterIndex).equals(part.parameters.get(parameterIndex))) {
164 /** Whether this chain is enabled. */
166 private boolean enabled;
168 /** The name of the chain. */
172 /** The query of the chain. */
176 /** The filters of the chain. */
178 private List<Part> filters = new ArrayList<Part>();
180 /** The trigger of the chain. */
182 private Part trigger;
184 /** A combination of query, filters, and a trigger. */
186 private Part watcher;
188 /** The action of the chain. */
192 /** Interval between updates (in seconds). */
194 private int updateInterval;
197 * Returns whether this chain is enabled.
199 * @return {@code true} if this chain is enabled, {@code false} otherwise
201 public boolean enabled() {
206 * Returns the name of the chain.
208 * @return The name of the chain
210 public String name() {
215 * Returns the query of this chain.
217 * @return The query of this chain
219 public Part query() {
224 * Returns the filters of this chain.
226 * @return The filters of this chain
228 public List<Part> filters() {
233 * Returns the trigger of this chain.
235 * @return The trigger of this chain
237 public Part trigger() {
242 * Returns an optional watcher.
244 * @return The watcher of this chain
246 public Part watcher() {
251 * Returns the action of this chain.
253 * @return The action of this chain
255 public Part action() {
260 * Returns the update interval of the chain.
262 * @return The update interval (in seconds)
264 public int updateInterval() {
265 return updateInterval;
276 public int hashCode() {
278 hashCode ^= name.hashCode();
279 if (watcher != null) {
280 hashCode ^= watcher.hashCode();
282 hashCode ^= query.hashCode();
283 for (Part filter : filters) {
284 hashCode ^= filter.hashCode();
286 hashCode ^= trigger.hashCode();
288 hashCode ^= action.hashCode();
289 hashCode ^= updateInterval;
297 public boolean equals(Object object) {
298 if (!(object instanceof Chain)) {
301 Chain chain = (Chain) object;
302 if (!name.equals(chain.name)) {
305 if (watcher != null) {
306 if (!watcher.equals(chain.watcher)) {
310 if (!query.equals(chain.query)) {
313 if (filters.size() != chain.filters.size()) {
316 for (int filterIndex = 0; filterIndex < filters.size(); ++filterIndex) {
317 if (!filters.get(filterIndex).equals(chain.filters.get(filterIndex))) {
321 if (!trigger.equals(chain.trigger)) {
325 if (!action.equals(chain.action)) {
328 return updateInterval == chain.updateInterval;