1 21 package org.jacorb.collection; 22 23 import org.omg.CosCollection.OperationsOperations; 24 import org.omg.CORBA.Any ; 25 import org.jacorb.collection.util.*; 26 27 class SequenceComparator implements ObjectComparator { 28 private OperationsOperations ops; 29 private Any current = null; 30 31 SequenceComparator( OperationsOperations ops ) { 32 this.ops = ops; 33 } 34 35 public synchronized int compare( Object obj1, Object 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 )obj1, (Any )obj2 ); 42 } 43 44 public synchronized void element( Object obj ) throws ObjectInvalid { 45 check_object( obj ); 46 current = (Any ) obj; 47 } 48 49 public synchronized Object element() { 50 return current; 51 } 52 53 public synchronized int compare_with( Object obj ) throws ObjectInvalid { 54 if( obj == null || current == null ) { 55 throw new ObjectInvalid(); 56 } 57 check_object( obj ); 58 return ops.compare( current, (Any )obj ); 59 } 60 61 public synchronized boolean equal( Object obj1, Object 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 )obj1, (Any )obj2 ); 68 } 69 70 public synchronized boolean equal( Object obj1 ) throws ObjectInvalid { 71 if( obj1 == null || current == null ) { 72 throw new ObjectInvalid(); 73 } 74 check_object( obj1 ); 75 return ops.equal( current, (Any )obj1 ); 76 } 77 78 private void check_object( Object obj ) throws ObjectInvalid { 79 if( !( obj instanceof Any ) 80 || !((Any )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 |