KickJava   Java API By Example, From Geeks To Geeks.

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


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 SequentialCollectionImpl
31     extends OrderedCollectionImpl
32     implements SequentialCollectionOperations
33 {
34     /* ========================================================================= */
35     SequentialCollectionImpl( OperationsOperations ops, POA JavaDoc poa, IteratorFactory iterator_factory ){
36         super( ops, poa, iterator_factory );
37     }
38     /* ========================================================================= */
39     public synchronized void add_element_as_first(Any JavaDoc element) throws ElementInvalid{
40         try {
41             add_element_at_position( 0, element );
42         } catch ( PositionInvalid e ){
43             throw new ElementInvalid( ElementInvalidReason.positioning_property_invalid );
44         }
45     }
46     /* ------------------------------------------------------------------------- */
47     public synchronized void add_element_as_first_set_iterator(Any JavaDoc element, Iterator where) throws ElementInvalid,IteratorInvalid{
48         PositionalIteratorImpl i = check_iterator( where );
49         add_element_as_first( element );
50         i.set_pos(0);
51         i.set_in_between(false);
52     }
53     /* ------------------------------------------------------------------------- */
54     public synchronized void add_element_as_last(Any JavaDoc element) throws ElementInvalid{
55         int pos = data.size();
56         try {
57             add_element_at_position(pos, element );
58         } catch ( PositionInvalid e ){
59             throw new ElementInvalid( ElementInvalidReason.positioning_property_invalid );
60         }
61     }
62     /* ------------------------------------------------------------------------- */
63     public synchronized void add_element_as_last_set_iterator(Any JavaDoc element, Iterator where) throws ElementInvalid,IteratorInvalid{
64         PositionalIteratorImpl i = check_iterator( where );
65         add_element_as_last( element );
66         i.set_pos(data.size()-1);
67         i.set_in_between(false);
68     }
69     /* ------------------------------------------------------------------------- */
70     public synchronized void add_element_as_next(Any JavaDoc element, Iterator where) throws ElementInvalid,IteratorInvalid{
71         PositionalIteratorImpl i = check_iterator( where );
72         int pos = i.get_pos();
73         try {
74             add_element_at_position( pos+1, element );
75         } catch ( PositionInvalid e ){
76             throw new ElementInvalid( ElementInvalidReason.positioning_property_invalid );
77         }
78     }
79     /* ------------------------------------------------------------------------- */
80     public synchronized void add_element_as_previous(Any JavaDoc element, Iterator where) throws ElementInvalid,IteratorInvalid{
81         PositionalIteratorImpl i = check_iterator( where );
82         int pos = i.get_pos();
83         try {
84             add_element_at_position( pos, element );
85         } catch ( PositionInvalid e ){
86             throw new ElementInvalid( ElementInvalidReason.positioning_property_invalid );
87         }
88     }
89     /* ------------------------------------------------------------------------- */
90     public synchronized void add_element_at_position(int position, Any JavaDoc element) throws PositionInvalid,ElementInvalid{
91         check_element(element);
92         try {
93             if( data.insertElementAt( element, position ) ){
94                 element_inserted( position );
95             } else {
96                 throw new ElementInvalid( ElementInvalidReason.positioning_property_invalid );
97             }
98         } catch ( ObjectInvalid e ){
99             throw new ElementInvalid( ElementInvalidReason.element_type_invalid );
100         }
101     }
102     /* ------------------------------------------------------------------------- */
103     public synchronized void add_element_at_position_set_iterator(int position, Any JavaDoc element, Iterator where) throws PositionInvalid,ElementInvalid,IteratorInvalid{
104         PositionalIteratorImpl i = check_iterator( where );
105         add_element_at_position( position, element );
106         i.set_pos(position);
107         i.set_in_between(false);
108     }
109     /* ------------------------------------------------------------------------- */
110     public synchronized void replace_element_at_position( int position, Any JavaDoc element ) throws PositionInvalid,ElementInvalid{
111         element_replace( position, element );
112     }
113     /* ------------------------------------------------------------------------- */
114     public synchronized void replace_first_element(Any JavaDoc element) throws ElementInvalid,EmptyCollection{
115         try {
116             replace_element_at_position( 0, element );
117         } catch ( PositionInvalid e ){
118             throw new ElementInvalid( ElementInvalidReason.positioning_property_invalid );
119         }
120     }
121     /* ------------------------------------------------------------------------- */
122     public synchronized void replace_last_element(Any JavaDoc element) throws ElementInvalid,EmptyCollection {
123         if( data.size() == 0 ){
124             throw new EmptyCollection();
125         }
126         try {
127             replace_element_at_position( data.size()-1, element );
128         } catch ( PositionInvalid e ){
129             throw new ElementInvalid( ElementInvalidReason.positioning_property_invalid );
130         }
131     }
132     /* ------------------------------------------------------------------------- */
133     public synchronized void sort(Comparator comparison){
134         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
135     }
136     /* ------------------------------------------------------------------------- */
137     public synchronized void reverse(){
138         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
139     }
140
141
142 }
143
144
145
146
147
148
149
Popular Tags