KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > collection > KeyComparator


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2004 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

21 package org.jacorb.collection;
22
23
24
25 import org.omg.CosCollection.*;
26
27 import org.jacorb.collection.util.*;
28
29
30
31 class KeyComparator implements ObjectComparator {
32
33     private KeyNode current = null;
34
35     private OperationsOperations ops;
36
37     KeyComparator( OperationsOperations ops ){
38
39         this.ops = ops;
40
41     };
42
43     public int compare( Object JavaDoc obj1, Object JavaDoc obj2 ) throws ObjectInvalid{
44
45         if( obj1 == null || obj2 == null ){
46
47             throw new ObjectInvalid();
48
49         }
50
51         check_object( obj1 );
52
53         check_object( obj2 );
54
55         return ops.key_compare( ((KeyNode)obj1).key, ((KeyNode)obj2).key );
56
57     };
58
59     public void element( Object JavaDoc obj ) throws ObjectInvalid{
60
61         check_object( obj );
62
63         current = (KeyNode)obj;
64
65     };
66
67     public Object JavaDoc element(){
68
69         return current;
70
71     };
72
73     public int compare_with( Object JavaDoc obj ) throws ObjectInvalid{
74
75         if( current == null || obj == null ){
76
77             throw new ObjectInvalid();
78
79         }
80
81         check_object( obj );
82
83         return ops.key_compare( current.key, ((KeyNode)obj).key );
84
85     };
86
87     public boolean equal( Object JavaDoc obj1, Object JavaDoc obj2 ) throws ObjectInvalid{
88
89         if( obj1 == null || obj2 == null ){
90
91             throw new ObjectInvalid();
92
93         }
94
95         check_object( obj1 );
96
97         check_object( obj2 );
98
99         return ops.key_equal( ((KeyNode)obj1).key, ((KeyNode)obj2).key );
100
101     };
102
103     public boolean equal( Object JavaDoc obj ) throws ObjectInvalid{
104
105         if( current == null || obj == null ){
106
107             throw new ObjectInvalid();
108
109         }
110
111         check_object( obj );
112
113         return ops.key_equal( current.key, ((KeyNode)obj).key );
114
115     };
116
117     private void check_object( Object JavaDoc obj ) throws ObjectInvalid {
118
119         if( !( obj instanceof KeyNode ) ){
120
121             throw new ObjectInvalid();
122
123         }
124
125     };
126
127 };
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
Popular Tags