View Javadoc

1   /*
2      Copyright 2007 Ramon Servadei
3   
4      Licensed under the Apache License, Version 2.0 (the "License");
5      you may not use this file except in compliance with the License.
6      You may obtain a copy of the License at
7   
8          http://www.apache.org/licenses/LICENSE-2.0
9   
10     Unless required by applicable law or agreed to in writing, software
11     distributed under the License is distributed on an "AS IS" BASIS,
12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13     See the License for the specific language governing permissions and
14     limitations under the License.
15   */
16  package fulmine.event;
17  
18  import static fulmine.util.Utils.COLON;
19  import static fulmine.util.Utils.EMPTY_STRING;
20  import fulmine.util.reference.is;
21  
22  /**
23   * Implementation of the {@link IEventFrameExecution}. This uses the system nano
24   * time in conjunction with the system identity for the object to create a
25   * unique identity for this.
26   * 
27   * @author Ramon Servadei
28   * 
29   */
30  public final class EventFrameExecution implements IEventFrameExecution
31  {
32      /** A counter used to mark each frame with a unique number */
33      private static long counter;
34  
35      /** the frame identity */
36      private final String id;
37  
38      /**
39       * Standard constructor for an execution of an event frame
40       */
41      public EventFrameExecution()
42      {
43          this(EMPTY_STRING);
44      }
45  
46      public EventFrameExecution(String id)
47      {
48          synchronized (EventFrameExecution.class)
49          {
50              this.id = id + COLON + counter++;
51          }
52      }
53  
54      @Override
55      public String toString()
56      {
57          return EMPTY_STRING + this.id;
58      }
59  
60      @Override
61      public int hashCode()
62      {
63          final int prime = 31;
64          int result = 1;
65          result = prime * result + ((id == null) ? 0 : id.hashCode());
66          return result;
67      }
68  
69      @Override
70      public boolean equals(Object obj)
71      {
72          if (is.same(this, obj))
73          {
74              return true;
75          }
76          if (is.differentClass(this, obj))
77          {
78              return false;
79          }
80          final EventFrameExecution other = (EventFrameExecution) obj;
81          return is.eq(this.id, other.id);
82      }
83  }