KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > collection > EqualityKeySortedIteratorImpl


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2004 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

21 package org.jacorb.collection;
22
23 import org.omg.CosCollection.*;
24 import org.jacorb.collection.util.*;
25 import org.omg.PortableServer.POA JavaDoc;
26 import org.omg.PortableServer.Servant JavaDoc;
27 import org.omg.CORBA.Any JavaDoc;
28 import org.omg.CORBA.AnyHolder JavaDoc;
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 JavaDoc 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 JavaDoc();
60             }
61         }
62     };
63 /* ------------------------------------------------------------------------- */
64     public boolean set_to_next_element_with_value( Any JavaDoc 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 JavaDoc)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 JavaDoc();
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 JavaDoc element = (Any JavaDoc)collection.data.elementAt( get_pos() );
93             int pos = get_pos()+1;
94             while( pos < collection.data.size() && collection.ops.equal( element, (Any JavaDoc)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 JavaDoc element, LowerBoundStyle style) throws ElementInvalid {
108         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
109     };
110 /* ------------------------------------------------------------------------- */
111     public boolean set_to_last_element_with_value( Any JavaDoc element, UpperBoundStyle style) throws ElementInvalid {
112         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
113     };
114 /* ------------------------------------------------------------------------- */
115     public boolean set_to_previous_element_with_value( Any JavaDoc 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 JavaDoc)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 JavaDoc();
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 JavaDoc element = (Any JavaDoc)collection.data.elementAt( get_pos() );
144             int pos = get_pos()-1;
145             while( pos >= 0 && collection.ops.equal( element, (Any JavaDoc)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