KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.omg.CosCollection.OperationsOperations;
24 import org.omg.CORBA.Any JavaDoc;
25 import org.jacorb.collection.util.*;
26
27 class SequenceComparator implements ObjectComparator {
28     private OperationsOperations ops;
29     private Any JavaDoc current = null;
30 /* ------------------------------------------------------------------------- */
31     SequenceComparator( OperationsOperations ops ) {
32         this.ops = ops;
33     }
34 /* ------------------------------------------------------------------------- */
35     public synchronized int compare( Object JavaDoc obj1, Object JavaDoc obj2 ) throws ObjectInvalid {
36         if( obj1 == null || obj2 == null ){
37             throw new ObjectInvalid();
38         }
39         check_object( obj1 );
40         check_object( obj2 );
41         return ops.compare( (Any JavaDoc)obj1, (Any JavaDoc)obj2 );
42     }
43 /* ------------------------------------------------------------------------- */
44     public synchronized void element( Object JavaDoc obj ) throws ObjectInvalid {
45         check_object( obj );
46         current = (Any JavaDoc) obj;
47     }
48 /* ------------------------------------------------------------------------- */
49     public synchronized Object JavaDoc element() {
50         return current;
51     }
52 /* ------------------------------------------------------------------------- */
53     public synchronized int compare_with( Object JavaDoc obj ) throws ObjectInvalid {
54         if( obj == null || current == null ) {
55             throw new ObjectInvalid();
56         }
57         check_object( obj );
58         return ops.compare( current, (Any JavaDoc)obj );
59     }
60 /* ------------------------------------------------------------------------- */
61     public synchronized boolean equal( Object JavaDoc obj1, Object JavaDoc obj2 ) throws ObjectInvalid {
62         if( obj1 == null || obj2 == null ){
63             throw new ObjectInvalid();
64         }
65         check_object( obj1 );
66         check_object( obj2 );
67         return ops.equal( (Any JavaDoc)obj1, (Any JavaDoc)obj2 );
68     }
69 /* ------------------------------------------------------------------------- */
70     public synchronized boolean equal( Object JavaDoc obj1 ) throws ObjectInvalid {
71         if( obj1 == null || current == null ) {
72             throw new ObjectInvalid();
73         }
74         check_object( obj1 );
75         return ops.equal( current, (Any JavaDoc)obj1 );
76     }
77 /* ------------------------------------------------------------------------- */
78     private void check_object( Object JavaDoc obj ) throws ObjectInvalid {
79         if( !( obj instanceof Any JavaDoc )
80             || !((Any JavaDoc)obj).type().equal( ops.element_type() ) ){
81             throw new ObjectInvalid();
82         }
83     }
84
85 }
86
87
88
89
90
91
92
93
94
95
Popular Tags