View Javadoc

1   /*
2    * Licensed under the Apache License, Version 2.0 (the "License");
3    * you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at
5    *
6    * http://www.apache.org/licenses/LICENSE-2.0
7    *
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS,
10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   * See the License for the specific language governing permissions and
12   * limitations under the License.
13   */
14  
15  package net.sourceforge.basher.impl;
16  
17  import net.sourceforge.basher.events.EventManager;
18  import net.sourceforge.basher.events.TickEvent;
19  
20  /**
21   * @author Johan Lindquist
22   * @version 1.0
23   */
24  public class TickTimerTask implements Runnable
25  {
26      private long _tick;
27      private EventManager _eventManager;
28  
29      public void setEventManager( final EventManager eventManager )
30      {
31          _eventManager = eventManager;
32      }
33  
34      public void run()
35      {
36          _eventManager.publish(new TickEvent(_tick++));
37      }
38  
39      public boolean equals(final Object o)
40      {
41          if (this == o)
42          {
43              return true;
44          }
45          if (o == null || getClass() != o.getClass())
46          {
47              return false;
48          }
49  
50          final TickTimerTask that = (TickTimerTask) o;
51  
52          if (_tick != that._tick)
53          {
54              return false;
55          }
56          if (_eventManager != null ? !_eventManager.equals(that._eventManager) : that._eventManager != null)
57          {
58              return false;
59          }
60  
61          return true;
62      }
63  
64      public int hashCode()
65      {
66          int result;
67          result = (int) (_tick ^ (_tick >>> 32));
68          result = 31 * result + (_eventManager != null ? _eventManager.hashCode() : 0);
69          return result;
70      }
71  }