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 javax.xml.bind.annotation.XmlElement;
24 import javax.xml.bind.annotation.XmlElementWrapper;
25 import javax.xml.bind.annotation.XmlRootElement;
28 * Model for chain definitions.
30 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
38 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
40 public static class Parameter {
42 /** The name of the parameter. */
43 @XmlElement(required = true)
46 /** The value of the parameter. */
47 @XmlElement(required = true)
51 * Returns the name of the parameter.
53 * @return The name of the parameter
55 public String name() {
60 * Returns the value of the parameter.
62 * @return The value of the parameter
64 public String value() {
72 public int hashCode() {
74 hashCode ^= name.hashCode();
75 hashCode ^= value.hashCode();
83 public boolean equals(Object object) {
84 if (!(object instanceof Parameter)) {
87 Parameter parameter = (Parameter) object;
88 if (!name.equals(parameter.name)) {
91 if (!value.equals(parameter.value)) {
100 * Defines a part of a chain.
102 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
104 public static class Part {
106 /** The class name of the part. */
107 @XmlElement(required = true, name = "class")
110 /** The parameters of the part. */
111 @XmlElement(name = "parameter")
112 @XmlElementWrapper(name = "parameters")
113 private List<Parameter> parameters = new ArrayList<Parameter>();
116 * Returns the name of the part’s class.
118 * @return The name of the part’s class
120 public String name() {
125 * Returns the parameters of the part.
127 * @return The parameters of the part
129 public List<Parameter> parameters() {
137 public int hashCode() {
139 hashCode ^= name.hashCode();
140 for (Parameter parameter : parameters) {
141 hashCode ^= parameter.hashCode();
150 public boolean equals(Object object) {
151 if (!(object instanceof Part)) {
154 Part part = (Part) object;
155 if (!name.equals(part.name)) {
158 if (parameters.size() != part.parameters.size()) {
161 for (int parameterIndex = 0; parameterIndex < parameters.size(); ++parameterIndex) {
162 if (!parameters.get(parameterIndex).equals(part.parameters.get(parameterIndex))) {
171 /** Whether this chain is enabled. */
172 @XmlElement(required = true)
173 private boolean enabled;
175 /** The query of the chain. */
176 @XmlElement(required = true)
179 /** The filters of the chain. */
180 @XmlElement(name = "filter")
181 @XmlElementWrapper(name = "filters")
182 private List<Part> filters = new ArrayList<Part>();
184 /** The trigger of the chain. */
185 @XmlElement(required = true)
186 private Part trigger;
188 /** The action of the chain. */
189 @XmlElement(required = true)
192 /** Interval between updates (in seconds). */
193 @XmlElement(required = true)
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 query of this chain.
208 * @return The query of this chain
210 public Part query() {
215 * Returns the filters of this chain.
217 * @return The filters of this chain
219 public List<Part> filters() {
224 * Returns the trigger of this chain.
226 * @return The trigger of this chain
228 public Part trigger() {
233 * Returns the action of this chain.
235 * @return The action of this chain
237 public Part action() {
242 * Returns the update interval of the chain.
244 * @return The update interval (in seconds)
246 public int updateInterval() {
247 return updateInterval;
258 public int hashCode() {
260 hashCode ^= query.hashCode();
261 for (Part filter : filters) {
262 hashCode ^= filter.hashCode();
264 hashCode ^= trigger.hashCode();
265 hashCode ^= action.hashCode();
266 hashCode ^= updateInterval;
274 public boolean equals(Object object) {
275 if (!(object instanceof Chain)) {
278 Chain chain = (Chain) object;
279 if (!query.equals(chain.query)) {
282 if (filters.size() != chain.filters.size()) {
285 for (int filterIndex = 0; filterIndex < filters.size(); ++filterIndex) {
286 if (!filters.get(filterIndex).equals(chain.filters.get(filterIndex))) {
290 if (!trigger.equals(chain.trigger)) {
293 if (!action.equals(chain.action)) {
296 if (updateInterval != chain.updateInterval) {