KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > util > AbstractIdentifier


1 /**
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.util;
5
6 import java.io.Serializable JavaDoc;
7
8 /**
9  * Generic Identifier class. Currently used as superclass for ObjectID, TransactionID and ChannelID
10  *
11  * @author steve
12  */

13 public abstract class AbstractIdentifier implements Serializable JavaDoc {
14   private static final long NULL_ID = -1;
15   private final long id;
16
17   public AbstractIdentifier(long id) {
18     this.id = id;
19   }
20
21   protected AbstractIdentifier() {
22     this.id = NULL_ID;
23   }
24
25   public boolean isNull() {
26     return (this.id == NULL_ID);
27   }
28
29   public final long toLong() {
30     return id;
31   }
32
33   public final String JavaDoc toString() {
34     return getIdentifierType() + "=" + "[" + id + "]";
35   }
36
37   abstract public String JavaDoc getIdentifierType();
38
39   public int hashCode() {
40     return (int) (this.id ^ (this.id >>> 32));
41   }
42
43   public boolean equals(Object JavaDoc obj) {
44     if (obj instanceof AbstractIdentifier) {
45       AbstractIdentifier other = (AbstractIdentifier) obj;
46       return ((this.id == other.id) && this.getClass().equals(other.getClass()));
47     }
48     return false;
49   }
50 }
Popular Tags