1 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 obj1, Object 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 obj ) throws ObjectInvalid{ 60 61 check_object( obj ); 62 63 current = (KeyNode)obj; 64 65 }; 66 67 public Object element(){ 68 69 return current; 70 71 }; 72 73 public int compare_with( Object 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 obj1, Object 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 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 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 |