KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > naming > pcosnaming > InternalBindingKey


1 /*
2  * @(#)InternalBindingKey.java 1.9 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 /*
8  * @(#)InternalBindingKey.java 1.9 03/12/19
9  *
10  * Copyright 1993-1997 Sun Microsystems, Inc. 901 San Antonio Road,
11  * Palo Alto, California, 94303, U.S.A. All Rights Reserved.
12  *
13  * This software is the confidential and proprietary information of Sun
14  * Microsystems, Inc. ("Confidential Information"). You shall not
15  * disclose such Confidential Information and shall use it only in
16  * accordance with the terms of the license agreement you entered into
17  * with Sun.
18  *
19  * CopyrightVersion 1.2
20  *
21  */

22
23 package com.sun.corba.se.impl.naming.pcosnaming;
24
25 import java.io.Serializable JavaDoc;
26 import org.omg.CosNaming.NameComponent JavaDoc;
27
28
29 /**
30  * Class InternalBindingKey implements the necessary wrapper code
31  * around the org.omg.CosNaming::NameComponent class to implement the proper
32  * equals() method and the hashCode() method for use in a hash table.
33  * It computes the hashCode once and stores it, and also precomputes
34  * the lengths of the id and kind strings for faster comparison.
35  */

36 public class InternalBindingKey
37     implements Serializable JavaDoc
38 {
39
40     // computed by serialver tool
41
private static final long serialVersionUID = -5410796631793704055L;
42
43     public String JavaDoc id;
44     public String JavaDoc kind;
45
46     // Default Constructor
47
public InternalBindingKey() {}
48
49     // Normal constructor
50
public InternalBindingKey(NameComponent JavaDoc n)
51     {
52     setup(n);
53     }
54
55     // Setup the object
56
protected void setup(NameComponent JavaDoc n) {
57     this.id = n.id;
58     this.kind = n.kind;
59     }
60
61     // Compare the keys by comparing name's id and kind
62
public boolean equals(java.lang.Object JavaDoc o) {
63     if (o == null)
64         return false;
65     if (o instanceof InternalBindingKey) {
66         InternalBindingKey that = (InternalBindingKey)o;
67         if( this.id != null && that.id != null )
68         {
69             if (this.id.length() != that.id.length() )
70         {
71             return false;
72         }
73             // If id is set is must be equal
74
if (this.id.length() > 0 && this.id.equals(that.id) == false)
75         {
76             return false;
77             }
78         }
79         else
80         {
81         // If One is Null and the other is not then it's a mismatch
82
// So, return false
83
if( ( this.id == null && that.id != null )
84         || ( this.id !=null && that.id == null ) )
85         {
86             return false;
87         }
88         }
89         if( this.kind != null && that.kind != null )
90         {
91             if (this.kind.length() != that.kind.length() )
92         {
93             return false;
94         }
95             // If kind is set it must be equal
96
if (this.kind.length() > 0 && this.kind.equals(that.kind) == false)
97         {
98             return false;
99             }
100         }
101         else
102         {
103         // If One is Null and the other is not then it's a mismatch
104
// So, return false
105
if( ( this.kind == null && that.kind != null )
106         || ( this.kind !=null && that.kind == null ) )
107         {
108             return false;
109         }
110         }
111         // We have checked all the possibilities, so return true
112
return true;
113     } else {
114         return false;
115     }
116     }
117
118
119     // Return precomputed value
120
public int hashCode() {
121     int hashVal = 0;
122     if (this.id.length() > 0)
123     {
124         hashVal += this.id.hashCode();
125     }
126     if (this.kind.length() > 0)
127     {
128         hashVal += this.kind.hashCode();
129     }
130     return hashVal;
131     }
132 }
133
134
Popular Tags