1 21 package org.jacorb.collection; 22 23 24 25 import org.omg.CosCollection.*; 26 27 import org.jacorb.collection.util.*; 28 29 import java.util.*; 30 import org.omg.PortableServer.POA ; 31 32 import org.omg.PortableServer.Servant ; 33 34 import org.omg.CORBA.Any ; 35 36 import org.omg.CORBA.AnyHolder ; 37 38 import org.omg.CORBA.BooleanHolder ; 39 40 41 42 class OrderedIteratorImpl extends PositionalIteratorImpl 43 44 implements OrderedIteratorOperations { 45 46 47 48 protected boolean reverse; 50 51 52 OrderedIteratorImpl( OrderedCollectionImpl collection ){ 53 54 super( collection ); 55 56 reverse = false; 57 58 }; 59 60 61 62 OrderedIteratorImpl( OrderedCollectionImpl collection, boolean read_only ){ 63 64 super( collection, read_only ); 65 66 reverse = false; 67 68 }; 69 70 71 72 OrderedIteratorImpl( OrderedCollectionImpl collection, boolean read_only, boolean reverse ){ 73 74 super( collection, read_only ); 75 76 if( reverse ){ 77 78 throw new org.omg.CORBA.NO_IMPLEMENT (); 79 80 } 81 82 this.reverse = reverse; 83 84 }; 85 86 87 88 public boolean set_to_last_element(){ 89 90 synchronized( collection ){ 91 92 set_pos( collection.data.size()-1 ); 93 94 set_in_between( false ); 95 96 return is_valid(); 97 98 } 99 100 }; 101 102 103 104 public boolean set_to_previous_element() throws IteratorInvalid{ 105 106 return set_to_nth_previous_element( 1 ); 107 108 }; 109 110 111 112 public boolean set_to_nth_previous_element(int n) throws IteratorInvalid{ 113 114 synchronized( collection ) { 115 116 check_invalid(); 117 118 int new_pos = get_pos()-n; 119 120 if( collection.number_of_elements() > new_pos && new_pos >= 0 ){ 121 122 set_pos( new_pos ); 123 124 } else { 125 126 invalidate(); 127 128 throw new IteratorInvalid( IteratorInvalidReason.is_invalid ); 129 130 } 131 132 set_in_between( false ); 133 134 return is_valid(); 135 136 } 137 138 }; 139 140 141 142 public void set_to_position(int position) throws PositionInvalid{ 143 144 synchronized( collection ){ 145 146 if( position <0 || position >= collection.data.size() ){ 147 148 throw new PositionInvalid(); 149 150 } 151 152 set_pos( position ); 153 154 set_in_between( false ); 155 156 }; 157 158 }; 159 160 161 162 public int position() throws IteratorInvalid{ 163 164 synchronized( collection ){ 165 166 check_invalid(); 167 168 return get_pos(); 169 170 } 171 172 } 173 174 175 176 public boolean retrieve_element_set_to_previous( AnyHolder element, BooleanHolder more) throws IteratorInvalid,IteratorInBetween{ 177 178 synchronized( collection ){ 179 180 check_iterator(); 181 182 try { 183 184 element.value = collection.element_retrieve( pos ); 185 186 } catch ( PositionInvalid e ){ 187 188 invalidate(); 189 190 throw new IteratorInvalid( IteratorInvalidReason.is_invalid ); 191 192 }; 193 194 more.value = (get_pos() > 0); 195 196 return set_to_previous_element(); 197 198 } 199 200 }; 201 202 203 204 public boolean retrieve_previous_n_elements(int n, AnySequenceHolder result, BooleanHolder more) throws IteratorInvalid,IteratorInBetween{ 205 206 synchronized( collection ) { 207 208 check_iterator(); 209 210 Vector v = new Vector(n); 211 212 AnyHolder a = new AnyHolder (); 213 214 for( int i=0; ( i<n || n==0 ) && is_valid(); i++ ){ 215 216 try { 217 218 a.value = collection.element_retrieve( get_pos() ); 219 220 set_pos( get_pos()-1 ); 221 222 } catch ( PositionInvalid e ){ 223 224 invalidate(); 225 226 throw new IteratorInvalid( IteratorInvalidReason.is_invalid ); 227 228 }; 229 230 v.addElement( a.value ); 231 232 a.value = null; 233 234 } 235 236 more.value = (get_pos() > 0); 237 238 if( v.size() > 0 ){ 239 240 result.value = new Any [ v.size() ]; 241 242 v.copyInto( (java.lang.Object []) result.value ); 243 244 return true; 245 246 } else { 247 248 return false; 249 250 } 251 252 } 253 254 }; 255 256 257 258 public boolean not_equal_retrieve_element_set_to_previous(org.omg.CosCollection.Iterator test, 259 260 AnyHolder element) 261 262 throws IteratorInvalid,IteratorInBetween 263 264 { 265 266 synchronized( collection ) { 267 268 check_iterator(); 269 270 PositionalIteratorImpl iter = collection.check_iterator( test ); 271 272 iter.check_iterator(); 273 274 if( is_equal( test ) ){ 275 276 retrieve_element( element ); 277 278 return false; 279 280 } else { 281 282 retrieve_element_set_to_previous( element, new org.omg.CORBA.BooleanHolder () ); 283 284 return true; 285 286 } 287 288 } 289 290 }; 291 292 293 294 public boolean remove_element_set_to_previous() throws IteratorInvalid,IteratorInBetween{ 295 296 synchronized( collection ) { 297 298 remove_element(); 299 300 return set_to_previous_element(); 301 302 } 303 304 }; 305 306 307 308 public boolean remove_previous_n_elements(int n, org.omg.CORBA.IntHolder actual_number) throws IteratorInvalid,IteratorInBetween{ 309 310 synchronized( collection ) { 311 312 actual_number.value = 0; 313 314 for( int i = 0; ( i<n || n == 0 ) && is_valid(); i++, actual_number.value++ ){ 315 316 remove_element_set_to_previous(); 317 318 } 319 320 return is_valid(); 321 322 } 323 324 }; 325 326 327 328 public boolean not_equal_remove_element_set_to_previous(org.omg.CosCollection.Iterator test) 329 330 throws IteratorInvalid,IteratorInBetween 331 332 { 333 334 synchronized( collection ) { 335 336 check_iterator(); 337 338 PositionalIteratorImpl iter = collection.check_iterator( test ); 339 340 iter.check_iterator(); 341 342 if( is_equal( test ) ){ 343 344 remove_element(); 345 346 return false; 347 348 } else { 349 350 remove_element_set_to_previous(); 351 352 return true; 353 354 } 355 356 } 357 358 }; 359 360 361 362 public boolean replace_element_set_to_previous(org.omg.CORBA.Any element) throws IteratorInvalid,IteratorInBetween,ElementInvalid{ 363 364 synchronized( collection ) { 365 366 replace_element( element ); 367 368 return set_to_previous_element(); 369 370 } 371 372 }; 373 374 375 376 public boolean replace_previous_n_elements(org.omg.CORBA.Any [] elements, org.omg.CORBA.IntHolder actual_number) throws IteratorInvalid,IteratorInBetween,ElementInvalid{ 377 378 synchronized( collection ) { 379 380 actual_number.value = 0; 381 382 for( int i=0; i<elements.length && is_valid(); i++,actual_number.value++ ){ 383 384 replace_element_set_to_previous( elements[i] ); 385 386 } 387 388 return is_valid(); 389 390 } 391 392 }; 393 394 395 396 public boolean not_equal_replace_element_set_to_previous(org.omg.CosCollection.Iterator test, Any element) throws IteratorInvalid,IteratorInBetween,ElementInvalid{ 397 398 synchronized( collection ) { 399 400 check_iterator(); 401 402 PositionalIteratorImpl iter = collection.check_iterator( test ); 403 404 iter.check_iterator(); 405 406 if( is_equal( test ) ){ 407 408 replace_element( element ); 409 410 return false; 411 412 } else { 413 414 replace_element_set_to_previous( element ); 415 416 return true; 417 418 } 419 420 } 421 422 }; 423 424 425 426 public boolean is_first(){ 427 428 return get_pos() == 0; 429 430 }; 431 432 433 434 public boolean is_last(){ 435 436 synchronized( collection ){ 437 438 return collection.data.size()-1 == get_pos(); 439 440 } 441 442 }; 443 444 445 446 public boolean is_for_same(org.omg.CosCollection.Iterator test){ 447 448 synchronized( collection ){ 449 450 try { 451 452 collection.check_iterator( test ); 453 454 return true; 455 456 } catch ( IteratorInvalid e ){ 457 458 return false; 459 460 } 461 462 } 463 464 }; 465 466 467 468 public synchronized boolean is_reverse(){ 469 470 return reverse; 471 472 }; 473 474 475 476 }; 477 478 479 480 481 482 483 484 485 486 487 488 489 490 | Popular Tags |