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.List;
22 import org.simpleframework.xml.Element;
23 import org.simpleframework.xml.ElementList;
24 import org.simpleframework.xml.Root;
27 * Model for chain definitions.
29 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
37 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
39 public static class Parameter {
41 /** The name of the parameter. */
45 /** The value of the parameter. */
50 * Returns the name of the parameter.
52 * @return The name of the parameter
54 public String name() {
59 * Returns the value of the parameter.
61 * @return The value of the parameter
63 public String value() {
71 public int hashCode() {
73 hashCode ^= name.hashCode();
74 hashCode ^= value.hashCode();
82 public boolean equals(Object object) {
83 if (!(object instanceof Parameter)) {
86 Parameter parameter = (Parameter) object;
87 if (!name.equals(parameter.name)) {
90 if (!value.equals(parameter.value)) {
99 * Defines a part of a chain.
101 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
103 public static class Part {
105 /** The class name of the part. */
106 @Element(name = "class")
109 /** The parameters of the part. */
110 @ElementList(required = false, empty = false)
111 private List<Parameter> parameters;
114 * Returns the name of the part’s class.
116 * @return The name of the part’s class
118 public String name() {
123 * Returns the parameters of the part.
125 * @return The parameters of the part
127 public List<Parameter> parameters() {
135 public int hashCode() {
137 hashCode ^= name.hashCode();
138 for (Parameter parameter : parameters) {
139 hashCode ^= parameter.hashCode();
148 public boolean equals(Object object) {
149 if (!(object instanceof Part)) {
152 Part part = (Part) object;
153 if (!name.equals(part.name)) {
156 if (parameters.size() != part.parameters.size()) {
159 for (int parameterIndex = 0; parameterIndex < parameters.size(); ++parameterIndex) {
160 if (!parameters.get(parameterIndex).equals(part.parameters.get(parameterIndex))) {
169 /** Whether this chain is enabled. */
171 private boolean enabled;
173 /** The query of the chain. */
177 /** The filters of the chain. */
178 @ElementList(required = false, empty = false)
179 private List<Part> filters;
181 /** The trigger of the chain. */
183 private Part trigger;
185 /** The action of the chain. */
189 /** Interval between updates (in seconds). */
191 private int updateInterval;
194 * Returns whether this chain is enabled.
196 * @return {@code true} if this chain is enabled, {@code false} otherwise
198 public boolean enabled() {
203 * Returns the query of this chain.
205 * @return The query of this chain
207 public Part query() {
212 * Returns the filters of this chain.
214 * @return The filters of this chain
216 public List<Part> filters() {
221 * Returns the trigger of this chain.
223 * @return The trigger of this chain
225 public Part trigger() {
230 * Returns the action of this chain.
232 * @return The action of this chain
234 public Part action() {
239 * Returns the update interval of the chain.
241 * @return The update interval (in seconds)
243 public int updateInterval() {
244 return updateInterval;
255 public int hashCode() {
257 hashCode ^= query.hashCode();
258 for (Part filter : filters) {
259 hashCode ^= filter.hashCode();
261 hashCode ^= trigger.hashCode();
262 hashCode ^= action.hashCode();
263 hashCode ^= updateInterval;
271 public boolean equals(Object object) {
272 if (!(object instanceof Chain)) {
275 Chain chain = (Chain) object;
276 if (!query.equals(chain.query)) {
279 if (filters.size() != chain.filters.size()) {
282 for (int filterIndex = 0; filterIndex < filters.size(); ++filterIndex) {
283 if (!filters.get(filterIndex).equals(chain.filters.get(filterIndex))) {
287 if (!trigger.equals(chain.trigger)) {
290 if (!action.equals(chain.action)) {
293 if (updateInterval != chain.updateInterval) {