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 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 name of the chain. */
175 /** The query of the chain. */
179 /** The filters of the chain. */
181 private List<Part> filters = new ArrayList<Part>();
183 /** The trigger of the chain. */
185 private Part trigger;
187 /** A combination of query, filters, and a trigger. */
189 private Part watcher;
191 /** The action of the chain. */
195 /** Interval between updates (in seconds). */
197 private int updateInterval;
200 * Returns whether this chain is enabled.
202 * @return {@code true} if this chain is enabled, {@code false} otherwise
204 public boolean enabled() {
209 * Returns the name of the chain.
211 * @return The name of the chain
213 public String name() {
218 * Returns the query of this chain.
220 * @return The query of this chain
222 public Part query() {
227 * Returns the filters of this chain.
229 * @return The filters of this chain
231 public List<Part> filters() {
236 * Returns the trigger of this chain.
238 * @return The trigger of this chain
240 public Part trigger() {
245 * Returns an optional watcher.
247 * @return The watcher of this chain
249 public Part watcher() {
254 * Returns the action of this chain.
256 * @return The action of this chain
258 public Part action() {
263 * Returns the update interval of the chain.
265 * @return The update interval (in seconds)
267 public int updateInterval() {
268 return updateInterval;
279 public int hashCode() {
281 hashCode ^= name.hashCode();
282 if (watcher != null) {
283 hashCode ^= watcher.hashCode();
285 hashCode ^= query.hashCode();
286 for (Part filter : filters) {
287 hashCode ^= filter.hashCode();
289 hashCode ^= trigger.hashCode();
291 hashCode ^= action.hashCode();
292 hashCode ^= updateInterval;
300 public boolean equals(Object object) {
301 if (!(object instanceof Chain)) {
304 Chain chain = (Chain) object;
305 if (!name.equals(chain.name)) {
308 if (watcher != null) {
309 if (!watcher.equals(chain.watcher)) {
313 if (!query.equals(chain.query)) {
316 if (filters.size() != chain.filters.size()) {
319 for (int filterIndex = 0; filterIndex < filters.size(); ++filterIndex) {
320 if (!filters.get(filterIndex).equals(chain.filters.get(filterIndex))) {
324 if (!trigger.equals(chain.trigger)) {
328 if (!action.equals(chain.action)) {
331 if (updateInterval != chain.updateInterval) {