View Javadoc

1   /*
2    * Created on 11 Nov 2007
3    *
4    */
5   package org.sourceforge.jemm.types;
6   
7   import java.io.Serializable;
8   
9   /**
10   * An ID used used to track an object.
11   *
12   * The ID is unique across all virtual machines
13   *
14   * @author Rory Graves
15   *
16   */
17  public class ID implements Serializable {
18  	private static final long serialVersionUID = 1L;
19  	
20  	protected final long idValue;
21  
22      /**
23       * Creates an ID using the passed in value.
24       * @param idValue The unique internal ID, uniqueness not checked in this class
25       */
26      public ID(long idValue) {
27          this.idValue = idValue;
28      }
29  
30      /**
31       * Retrieves the internal id representation for this ID
32       * @return The internal id representation
33       */
34      public long getIDValue() {
35          return idValue;
36      }
37  
38      @Override
39      public int hashCode() {
40          return (int) (idValue ^ (idValue >>> 32));
41      }
42  
43      @Override
44      public boolean equals(Object obj) {
45          if (this == obj)
46              return true;
47          if (obj == null)
48              return false;
49          if (!(obj instanceof ID))
50              return false;
51          ID other = (ID) obj;
52          return idValue == other.idValue;
53      }
54  
55      @Override
56      public String toString() {
57          return "ID(" + idValue + ")";
58      }
59  }