View Javadoc

1   /*
2    * (C)opyright 2010, Nikolaos Georgosopoulos
3    *
4    * This file is part of URLChecker.
5   
6       URLChecker is free software: you can redistribute it and/or modify
7       it under the terms of the Lesser General Public License as published by
8       the Free Software Foundation, either version 3 of the License, or
9       (at your option) any later version.
10  
11      URLChecker is distributed in the hope that it will be useful,
12      but WITHOUT ANY WARRANTY; without even the implied warranty of
13      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14      GNU General Public License for more details.
15  
16      You should have received a copy of the Lesser General Public License
17      along with URLChecker.  If not, see <http://www.gnu.org/licenses/>.
18  
19   */
20  package net.sf.urlchecker.events;
21  
22  import net.sf.urlchecker.commands.Command;
23  import net.sf.urlchecker.commands.Context;
24  
25  import org.apache.commons.lang.builder.EqualsBuilder;
26  import org.apache.commons.lang.builder.HashCodeBuilder;
27  
28  /**
29   * The Class BasicChainEvent. Immutable.
30   * 
31   * <p>
32   * <b> $Id: BasicChainEvent.java 180 2010-12-12 18:47:56Z georgosn $</b>
33   * </p>
34   * 
35   * @author $LastChangedBy: georgosn $
36   * @version $LastChangedRevision: 180 $
37   */
38  public class BasicChainEvent implements ChainEvent {
39  
40      /** The command. */
41      private final Command    command;
42  
43      /** The context. */
44      private final Context    context;
45  
46      /** The event type. */
47      private final EventTypes eventType;
48  
49      /**
50       * Instantiates a new basic chain event.
51       * 
52       * @param command
53       *            the command
54       * @param context
55       *            the context
56       * @param eventType
57       *            the event type
58       */
59      public BasicChainEvent(final Command command, final Context context,
60              final EventTypes eventType) {
61          this.command = command;
62          this.context = context;
63          this.eventType = eventType;
64      }
65  
66      /*
67       * (non-Javadoc)
68       * 
69       * @see java.lang.Object#equals(java.lang.Object)
70       */
71      /** {@inheritDoc} */
72      @Override
73      public boolean equals(final Object obj) {
74          if (this == obj) {
75              return true;
76          }
77          if (obj == null) {
78              return false;
79          }
80          if (getClass() != obj.getClass()) {
81              return false;
82          }
83          final BasicChainEvent other = (BasicChainEvent) obj;
84          return new EqualsBuilder().append(context, other.getContext())
85                  .append(eventType, other.getEventType()).isEquals();
86      }
87  
88      /**
89       * Gets the command.
90       * 
91       * @return the command
92       */
93      public Command getCommand() {
94          return command;
95      }
96  
97      /**
98       * Gets the context.
99       * 
100      * @return the context
101      */
102     public Context getContext() {
103         return context;
104     }
105 
106     /**
107      * Gets the event type.
108      * 
109      * @return the eventType
110      */
111     public EventTypes getEventType() {
112         return eventType;
113     }
114 
115     /*
116      * (non-Javadoc)
117      * 
118      * @see java.lang.Object#hashCode()
119      */
120     /** {@inheritDoc} */
121     @Override
122     public int hashCode() {
123         return new HashCodeBuilder().append(context).append(eventType)
124                 .hashCode();
125     }
126 
127     /*
128      * (non-Javadoc)
129      * 
130      * @see java.lang.Object#toString()
131      */
132     /** {@inheritDoc} */
133     @Override
134     public String toString() {
135         return "BasicChainEvent [command=" + command + ", context=" + context
136                 + ", eventType=" + eventType + "]";
137     }
138 
139 }