KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > xml > UID


1 package jfun.yan.xml;
2
3 import jfun.util.Misc;
4
5 /**
6  * Unique id for a component. This id is guaranteed to be unique
7  * across multiple modules.
8  * <p>
9  * @author Ben Yu
10  * Dec 12, 2005 2:58:23 PM
11  */

12 public class UID implements java.io.Serializable JavaDoc{
13   private final Object JavaDoc module_id;
14   private final Object JavaDoc id;
15   private final int evaluation_seq;
16   private final int declaration_seq;
17   /**
18    * To create a UID object.
19    * @param module_id the module id.
20    * @param decl_seq the declaration sequence in the enclosing tag.
21    * @param eval_seq the evaluation sequence.
22    * @param id the id of the component within the module.
23    */

24   public UID(Object JavaDoc module_id, int decl_seq, int eval_seq, Object JavaDoc id) {
25     this.id = id;
26     this.evaluation_seq = eval_seq;
27     this.module_id = module_id;
28     this.declaration_seq = decl_seq;
29   }
30   /**
31    * Get the id of the component within the containing module.
32    */

33   public Object JavaDoc getComponentId() {
34     return id;
35   }
36   /**
37    * Get the id of the containing module.
38    */

39   public Object JavaDoc getModuleId() {
40     return module_id;
41   }
42   
43   /**
44    * Get the sequence number in the order of tag evaluation.
45    */

46   public int getEvaluationSequence(){
47     return evaluation_seq;
48   }
49   /**
50    * Get the sequence number in the order of tag declaration.
51    */

52   public int getDeclarationSequence(){
53     return declaration_seq;
54   }
55   public boolean equals(Object JavaDoc obj) {
56     if(obj instanceof UID){
57       final UID other = (UID)obj;
58       return declaration_seq==other.declaration_seq && evaluation_seq == other.evaluation_seq && Misc.equals(module_id, other.module_id);
59     }
60     else return false;
61   }
62   public int hashCode() {
63     return Misc.hashcode(module_id)*31+evaluation_seq;
64   }
65   public String JavaDoc toString() {
66     StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
67     buf.append(module_id).append('.');
68     if(id!=null){
69       buf.append(id);
70     }
71     else{
72       buf.append('#').append(declaration_seq);
73     }
74     return buf.toString();
75   }
76   
77 }
78
Popular Tags