1 21 package org.jacorb.collection; 22 23 import org.omg.CosCollection.*; 24 import org.jacorb.collection.util.*; 25 import org.omg.PortableServer.POA ; 26 import org.omg.PortableServer.Servant ; 27 import org.omg.CORBA.Any ; 28 import org.omg.CORBA.AnyHolder ; 29 30 class EqualityKeySortedIteratorImpl extends KeySortedIteratorImpl 31 implements EqualityKeySortedIteratorOperations { 32 33 EqualityKeySortedIteratorImpl( KeySortedCollectionImpl collection ){ 34 super( collection ); 35 }; 36 37 EqualityKeySortedIteratorImpl( KeySortedCollectionImpl collection, boolean read_only ){ 38 super( collection, read_only ); 39 }; 40 41 EqualityKeySortedIteratorImpl( KeySortedCollectionImpl collection, boolean read_only, boolean reverse ){ 42 super( collection, read_only, reverse ); 43 }; 44 45 public boolean set_to_element_with_value( Any element ) throws ElementInvalid { 46 synchronized( collection ){ 47 collection.check_element( element ); 48 try { 49 int pos = collection.data.indexOf( element ); 50 if( pos >= 0 ){ 51 set_pos( pos ); 52 set_in_between( false ); 53 return true; 54 } 55 invalidate(); 56 return false; 57 } catch ( ObjectInvalid e ) { 58 e.printStackTrace( System.out ); 59 throw new org.omg.CORBA.INTERNAL (); 60 } 61 } 62 }; 63 64 public boolean set_to_next_element_with_value( Any element ) throws IteratorInvalid, ElementInvalid { 65 synchronized( collection ){ 66 check_invalid(); 67 collection.check_element( element ); 68 try { 69 int pos = collection.data.indexOf( element ); 70 int start_pos = is_in_between()?get_pos():get_pos()+1; 71 if( pos >= 0 && start_pos < collection.data.size()-1 ){ 72 if( start_pos > pos && !collection.ops.equal( element, (Any )collection.data.elementAt(start_pos) ) ){ 73 invalidate(); 74 return false; 75 } 76 set_pos( start_pos ); 77 set_in_between( false ); 78 return true; 79 } 80 invalidate(); 81 return false; 82 } catch ( ObjectInvalid e ) { 83 e.printStackTrace( System.out ); 84 throw new org.omg.CORBA.INTERNAL (); 85 } 86 } 87 }; 88 89 public boolean set_to_next_element_with_different_value() throws IteratorInBetween, IteratorInvalid { 90 synchronized( collection ){ 91 check_iterator(); 92 Any element = (Any )collection.data.elementAt( get_pos() ); 93 int pos = get_pos()+1; 94 while( pos < collection.data.size() && collection.ops.equal( element, (Any )collection.data.elementAt( pos ) ) ){ 95 pos++; 96 } 97 if( pos >= collection.data.size() ) { 98 invalidate(); 99 return false; 100 } else { 101 set_pos( pos ); 102 return true; 103 } 104 } 105 }; 106 107 public boolean set_to_first_element_with_value( Any element, LowerBoundStyle style) throws ElementInvalid { 108 throw new org.omg.CORBA.NO_IMPLEMENT (); 109 }; 110 111 public boolean set_to_last_element_with_value( Any element, UpperBoundStyle style) throws ElementInvalid { 112 throw new org.omg.CORBA.NO_IMPLEMENT (); 113 }; 114 115 public boolean set_to_previous_element_with_value( Any element ) throws IteratorInvalid, ElementInvalid { 116 synchronized( collection ){ 117 check_invalid(); 118 collection.check_element( element ); 119 try { 120 int pos = collection.data.indexOf( element ); 121 int start_pos = get_pos()-1; 122 if( pos >= 0 && start_pos < collection.data.size() ){ 123 if( start_pos < pos && !collection.ops.equal( element, (Any )collection.data.elementAt(start_pos) ) ){ 124 invalidate(); 125 return false; 126 } 127 set_pos( start_pos ); 128 set_in_between( false ); 129 return true; 130 } 131 invalidate(); 132 return false; 133 } catch ( ObjectInvalid e ) { 134 e.printStackTrace( System.out ); 135 throw new org.omg.CORBA.INTERNAL (); 136 } 137 } 138 }; 139 140 public boolean set_to_previous_element_with_different_value() throws IteratorInBetween, IteratorInvalid { 141 synchronized( collection ){ 142 check_iterator(); 143 Any element = (Any )collection.data.elementAt( get_pos() ); 144 int pos = get_pos()-1; 145 while( pos >= 0 && collection.ops.equal( element, (Any )collection.data.elementAt( pos ) ) ){ 146 pos--; 147 } 148 if( pos < 0 ) { 149 invalidate(); 150 return false; 151 } else { 152 set_pos( pos ); 153 return true; 154 } 155 } 156 } 157 } 158 159 160 161 162 163 164 165 | Popular Tags |