1 21 package org.jacorb.collection; 22 23 import org.omg.CosCollection.*; 24 import org.jacorb.collection.util.*; 25 import java.util.*; 26 import org.omg.PortableServer.POA ; 27 import org.omg.PortableServer.Servant ; 28 import org.omg.CORBA.Any ; 29 import org.omg.CORBA.AnyHolder ; 30 31 class EqualityKeySortedCollectionImpl 32 extends KeySortedCollectionImpl 33 implements EqualityKeySortedCollectionOperations 34 { 35 36 37 EqualityKeySortedCollectionImpl( OperationsOperations ops, 38 POA poa, 39 IteratorFactory iterator_factory ) 40 { 41 super( ops, poa, iterator_factory ); 42 } 43 44 45 public synchronized boolean contains_element(Any element) 46 throws ElementInvalid 47 { 48 check_element( element ); 49 try 50 { 51 return data.indexOf( element ) >= 0; 52 } 53 catch ( ObjectInvalid e ) 54 { 55 throw new ElementInvalid( ElementInvalidReason.element_type_invalid ); 56 } 57 } 58 59 60 61 public synchronized boolean contains_all_from(org.omg.CosCollection.Collection collector) 62 throws ElementInvalid 63 { 64 throw new org.omg.CORBA.NO_IMPLEMENT (); 65 } 66 67 68 public synchronized boolean locate_or_add_element(Any element) throws ElementInvalid{ 69 check_element( element ); 70 try { 71 if( data.indexOf( element ) < 0 ){ 72 element_add( element ); 73 return false; 74 } 75 return true; 76 } catch ( ObjectInvalid e ){ 77 throw new ElementInvalid( ElementInvalidReason.element_type_invalid ); 78 } 79 } 80 81 public synchronized boolean locate_or_add_element_set_iterator(Any element, org.omg.CosCollection.Iterator where) throws ElementInvalid,IteratorInvalid{ 82 check_element( element ); 83 PositionalIteratorImpl i = check_iterator( where ); 84 try { 85 int pos = data.indexOf( element ); 86 if( pos < 0 ){ 87 pos = element_add( element ); 88 i.set_pos( pos ); 89 i.set_in_between( false ); 90 return false; 91 } else { 92 i.set_pos( pos ); 93 i.set_in_between( false ); 94 return true; 95 } 96 } catch ( ObjectInvalid e ){ 97 throw new ElementInvalid( ElementInvalidReason.element_type_invalid ); 98 } 99 } 100 101 public synchronized boolean locate_element(Any element, org.omg.CosCollection.Iterator where) throws ElementInvalid,IteratorInvalid{ 102 check_element( element ); 103 PositionalIteratorImpl i = check_iterator( where ); 104 try { 105 int pos = data.indexOf( element ); 106 if( pos >= 0 ){ 107 i.set_pos( pos ); 108 i.set_in_between( false ); 109 return true; 110 } else { 111 i.invalidate(); 112 return false; 113 } 114 } catch ( ObjectInvalid e ){ 115 throw new ElementInvalid( ElementInvalidReason.element_type_invalid ); 116 } 117 } 118 119 public synchronized boolean locate_next_element(Any element, org.omg.CosCollection.Iterator where) throws ElementInvalid,IteratorInvalid{ 120 check_element( element ); 121 PositionalIteratorImpl i = check_iterator( where ); 122 i.check_invalid(); 123 try { 124 int pos = data.indexOf( element ); 125 if( pos >= 0 ){ 126 int new_pos = i.is_in_between()?pos:pos+1; 127 while( new_pos < data.size() && ops.compare( element, (Any )data.elementAt(new_pos) ) == 0 ){ 128 if( ops.equal( element, (Any )data.elementAt( new_pos ) ) ){ 129 i.set_pos( new_pos ); 130 i.set_in_between( false ); 131 return true; 132 } 133 new_pos++; 134 } 135 } 136 i.invalidate(); 137 return false; 138 } catch ( ObjectInvalid e ){ 139 throw new ElementInvalid( ElementInvalidReason.element_type_invalid ); 140 } 141 } 142 143 public synchronized boolean locate_next_different_element(org.omg.CosCollection.Iterator where) 144 throws IteratorInvalid,IteratorInBetween 145 { 146 PositionalIteratorImpl i = check_iterator( where ); 147 i.check_iterator(); 148 int pos = i.get_pos(); 149 Any element = (Any )data.elementAt( pos ); 150 if( pos >= 0 ){ 151 int new_pos = pos+1; 152 while( new_pos < data.size() ){ 153 if( ops.compare( element, (Any )data.elementAt( new_pos ) ) != 0 154 || !ops.equal( element, (Any )data.elementAt( new_pos ) ) ){ 155 i.set_pos( new_pos ); 156 i.set_in_between( false ); 157 return true; 158 } 159 new_pos++; 160 } 161 } 162 i.invalidate(); 163 return false; 164 } 165 166 public synchronized boolean remove_element(Any element) 167 throws ElementInvalid 168 { 169 check_element( element ); 170 try { 171 int pos = data.indexOf( element ); 172 if( pos >= 0 ){ 173 element_remove( 0 ); 174 return true; 175 } 176 return false; 177 } catch ( ObjectInvalid e ){ 178 throw new ElementInvalid( ElementInvalidReason.element_type_invalid ); 179 } catch ( Exception e ){ 180 e.printStackTrace( System.out ); 181 throw new org.omg.CORBA.INTERNAL (); 182 } 183 } 184 185 186 public synchronized int remove_all_occurrences(Any element) throws ElementInvalid{ 187 check_element( element ); 188 try { 189 int pos = data.indexOf( element ); 190 int count = 0; 191 while( pos < data.size() && ops.equal( element, (Any )data.elementAt( pos ) ) ){ 192 element_remove( pos ); 193 count++; 194 } 195 return count; 196 } catch ( ObjectInvalid e ){ 197 throw new ElementInvalid( ElementInvalidReason.element_type_invalid ); 198 } catch ( Exception e ){ 199 e.printStackTrace( System.out ); 200 throw new org.omg.CORBA.INTERNAL (); 201 } 202 } 203 204 205 public synchronized int number_of_different_elements(){ 206 throw new org.omg.CORBA.NO_IMPLEMENT (); 207 } 208 209 210 public synchronized int number_of_occurrences(Any element) throws ElementInvalid{ 211 throw new org.omg.CORBA.NO_IMPLEMENT (); 212 } 213 214 215 216 217 218 public synchronized org.omg.CosCollection.Iterator create_iterator(boolean read_only) 219 { 220 return create_ordered_iterator( read_only, false ); 221 } 222 223 224 } 225 226 | Popular Tags |