KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > ior > ObjectAdapterIdBase


1 /*
2  * @(#)ObjectAdapterIdBase.java 1.6 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 package com.sun.corba.se.impl.ior ;
9
10 import java.util.Iterator JavaDoc ;
11
12 import org.omg.CORBA_2_3.portable.OutputStream JavaDoc ;
13
14 import com.sun.corba.se.spi.ior.ObjectAdapterId ;
15
16 abstract class ObjectAdapterIdBase implements ObjectAdapterId {
17     public boolean equals( Object JavaDoc other )
18     {
19     if (!(other instanceof ObjectAdapterId))
20         return false ;
21
22     ObjectAdapterId theOther = (ObjectAdapterId)other ;
23
24     Iterator JavaDoc iter1 = iterator() ;
25     Iterator JavaDoc iter2 = theOther.iterator() ;
26
27     while (iter1.hasNext() && iter2.hasNext()) {
28         String JavaDoc str1 = (String JavaDoc)(iter1.next()) ;
29         String JavaDoc str2 = (String JavaDoc)(iter2.next()) ;
30
31         if (!str1.equals( str2 ))
32         return false ;
33     }
34
35     return iter1.hasNext() == iter2.hasNext() ;
36     }
37
38     public int hashCode()
39     {
40     int result = 17 ;
41     Iterator JavaDoc iter = iterator() ;
42     while (iter.hasNext()) {
43         String JavaDoc str = (String JavaDoc)(iter.next()) ;
44         result = 37*result + str.hashCode() ;
45     }
46     return result ;
47     }
48
49     public String JavaDoc toString()
50     {
51     StringBuffer JavaDoc buff = new StringBuffer JavaDoc() ;
52     buff.append( "ObjectAdapterID[" ) ;
53     Iterator JavaDoc iter = iterator() ;
54     boolean first = true ;
55     while (iter.hasNext()) {
56         String JavaDoc str = (String JavaDoc)(iter.next()) ;
57
58         if (first)
59         first = false ;
60         else
61         buff.append( "/" ) ;
62
63         buff.append( str ) ;
64     }
65
66     buff.append( "]" ) ;
67     
68     return buff.toString() ;
69     }
70
71     public void write( OutputStream JavaDoc os )
72     {
73     os.write_long( getNumLevels() ) ;
74     Iterator JavaDoc iter = iterator() ;
75     while (iter.hasNext()) {
76         String JavaDoc str = (String JavaDoc)(iter.next()) ;
77         os.write_string( str ) ;
78     }
79     }
80 }
81
Popular Tags