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 import org.omg.CORBA.BooleanHolder ; 31 32 class KeySortedIteratorImpl extends OrderedIteratorImpl 33 implements KeySortedIteratorOperations { 34 KeyNode test_key = new KeyNode(); 35 KeySortedCollectionImpl key_collection; 36 37 KeySortedIteratorImpl( KeySortedCollectionImpl collection ){ 38 super( collection ); 39 key_collection = collection; 40 } 41 42 KeySortedIteratorImpl( KeySortedCollectionImpl collection, boolean read_only ){ 43 super( collection, read_only ); 44 key_collection = collection; 45 } 46 47 KeySortedIteratorImpl( KeySortedCollectionImpl collection, boolean read_only, boolean reverse ){ 48 super( collection, read_only, reverse ); 49 key_collection = collection; 50 } 51 52 53 55 public boolean set_to_element_with_key( Any key ) throws KeyInvalid { 56 synchronized( collection ){ 57 key_collection.check_key( key ); 58 test_key.key = key; 59 try { 60 int pos = key_collection.keys.indexOf( key ); 61 if( pos >=0 ){ 62 KeyNode node = (KeyNode)key_collection.keys.elementAt( pos ); 63 set_pos( node.start_position ); 64 set_in_between( false ); 65 return true; 66 } 67 invalidate(); 68 return false; 69 } catch ( ObjectInvalid e ) { 70 e.printStackTrace( System.out ); 71 throw new org.omg.CORBA.INTERNAL (); 72 } 73 } 74 } 75 76 public boolean set_to_next_element_with_key( Any key ) throws IteratorInvalid,KeyInvalid { 77 synchronized( collection ){ 78 check_invalid(); 79 key_collection.check_key( key ); 80 test_key.key = key; 81 try { 82 int pos = key_collection.keys.indexOf( key ); 83 if( pos >=0 ){ 84 KeyNode node = (KeyNode)key_collection.keys.elementAt( pos ); 85 int start_pos = is_in_between()?get_pos():get_pos()+1; 86 if( start_pos <= node.start_position || start_pos < node.start_position + node.count ){ 87 set_pos( start_pos ); 88 set_in_between( false ); 89 return true; 90 } 91 } 92 invalidate(); 93 return false; 94 } catch ( ObjectInvalid e ) { 95 e.printStackTrace( System.out ); 96 throw new org.omg.CORBA.INTERNAL (); 97 } 98 } 99 } 100 101 public boolean set_to_next_element_with_different_key() throws IteratorInBetween, IteratorInvalid { 102 synchronized( collection ){ 103 check_iterator(); 104 Any key = collection.ops.key( (Any )collection.data.elementAt( get_pos() ) ); 105 test_key.key = key; 106 try { 107 int pos = key_collection.keys.indexOf( key ); 108 if( pos >=0 && pos < key_collection.keys.size()-1 ){ 109 pos++; 110 KeyNode node = (KeyNode)key_collection.keys.elementAt( pos ); 111 set_pos( node.start_position ); 112 set_in_between( false ); 113 return true; 114 } 115 invalidate(); 116 return false; 117 } catch ( ObjectInvalid e ) { 118 e.printStackTrace( System.out ); 119 throw new org.omg.CORBA.INTERNAL (); 120 } 121 } 122 } 123 124 public boolean retrieve_key( AnyHolder key ) throws IteratorInBetween, IteratorInvalid { 125 synchronized( collection ){ 126 check_iterator(); 127 key.value = collection.ops.key( (Any )collection.data.elementAt( get_pos() ) ); 128 return true; 129 } 130 } 131 132 public boolean retrieve_next_n_keys( AnySequenceHolder keys ) throws IteratorInBetween, IteratorInvalid { 133 throw new org.omg.CORBA.NO_IMPLEMENT (); 134 } 135 136 138 public boolean set_to_first_element_with_key( Any key, LowerBoundStyle style) throws KeyInvalid { 139 throw new org.omg.CORBA.NO_IMPLEMENT (); 140 } 141 142 public boolean set_to_last_element_with_key( Any key, UpperBoundStyle style) throws KeyInvalid { 143 throw new org.omg.CORBA.NO_IMPLEMENT (); 144 } 145 146 public boolean set_to_previous_element_with_key( Any key ) throws IteratorInvalid, KeyInvalid { 147 synchronized( collection ){ 148 check_invalid(); 149 key_collection.check_key( key ); 150 test_key.key = key; 151 try { 152 int pos = key_collection.keys.indexOf( key ); 153 if( pos >=0 ){ 154 KeyNode node = (KeyNode)key_collection.keys.elementAt( pos ); 155 int start_pos = get_pos()-1; 156 if( start_pos <= node.start_position || start_pos < node.start_position + node.count ){ 157 set_pos( start_pos ); 158 set_in_between( false ); 159 return true; 160 } 161 } 162 invalidate(); 163 return false; 164 } catch ( ObjectInvalid e ) { 165 e.printStackTrace( System.out ); 166 throw new org.omg.CORBA.INTERNAL (); 167 } 168 } 169 } 170 171 public boolean set_to_previous_element_with_different_key() throws IteratorInBetween, IteratorInvalid { 172 synchronized( collection ){ 173 check_iterator(); 174 Any key = collection.ops.key( (Any )collection.data.elementAt( get_pos() ) ); 175 test_key.key = key; 176 try { 177 int pos = key_collection.keys.indexOf( key ); 178 if( pos > 0 ){ 179 pos--; 180 KeyNode node = (KeyNode)key_collection.keys.elementAt( pos ); 181 set_pos( node.start_position ); 182 set_in_between( false ); 183 return true; 184 } 185 invalidate(); 186 return false; 187 } catch ( ObjectInvalid e ) { 188 e.printStackTrace( System.out ); 189 throw new org.omg.CORBA.INTERNAL (); 190 } 191 } 192 } 193 194 public boolean retrieve_previous_n_keys( AnySequenceHolder keys ) throws IteratorInBetween, IteratorInvalid { 195 throw new org.omg.CORBA.NO_IMPLEMENT (); 196 } 197 198 } 199 200 201 202 203 | Popular Tags |