KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > management > relation > RoleList


1 /*
2  * @(#)RoleList.java 1.20 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.management.relation;
9
10 import java.util.ArrayList JavaDoc;
11 import java.util.List JavaDoc;
12 import java.util.Iterator JavaDoc;
13 import java.util.Collection JavaDoc; // for Javadoc
14

15 /**
16  * A RoleList represents a list of roles (Role objects). It is used as
17  * parameter when creating a relation, and when trying to set several roles in
18  * a relation (via 'setRoles()' method). It is returned as part of a
19  * RoleResult, to provide roles successfully retrieved.
20  *
21  * @since 1.5
22  */

23 public class RoleList extends ArrayList JavaDoc {
24
25     /* Serial version */
26     private static final long serialVersionUID = 5568344346499649313L;
27
28     //
29
// Constructors
30
//
31

32     /**
33      * Constructs an empty RoleList.
34      */

35     public RoleList() {
36     super();
37     return;
38     }
39
40     /**
41      * Constructs an empty RoleList with the initial capacity
42      * specified.
43      *
44      * @param theInitialCapacity initial capacity
45      */

46     public RoleList(int theInitialCapacity) {
47     super(theInitialCapacity);
48     return;
49     }
50
51     /**
52      * Constructs a RoleList containing the elements of the
53      * List specified, in the order in which they are returned
54      * by the List's iterator. The RoleList instance has
55      * an initial capacity of 110% of the size of the List
56      * specified.
57      *
58      * @param theList list of Role objects
59      *
60      * @exception IllegalArgumentException if:
61      * <P>- null parameter
62      * <P>or
63      * <P>- an element in the List is not a Role
64      */

65     public RoleList(List JavaDoc theList)
66     throws IllegalArgumentException JavaDoc {
67
68     if (theList == null) {
69         String JavaDoc excMsg = "Invalid parameter";
70         throw new IllegalArgumentException JavaDoc(excMsg);
71     }
72
73     int i = 0;
74     for (Iterator JavaDoc eltIter = theList.iterator();
75          eltIter.hasNext();) {
76         Object JavaDoc currElt = eltIter.next();
77         if (!(currElt instanceof Role JavaDoc)) {
78         StringBuffer JavaDoc excMsgStrB = new StringBuffer JavaDoc();
79         String JavaDoc excMsg = "An element is not a Role at index ";
80         excMsgStrB.append(excMsg);
81         excMsgStrB.append(i);
82         throw new IllegalArgumentException JavaDoc(excMsgStrB.toString());
83         }
84         i++;
85         super.add(currElt);
86     }
87     return;
88     }
89
90     //
91
// Accessors
92
//
93

94     /**
95      * Adds the Role specified as the last element of the list.
96      *
97      * @param theRole the role to be added.
98      *
99      * @exception IllegalArgumentException if the role is null.
100      */

101     public void add(Role JavaDoc theRole)
102     throws IllegalArgumentException JavaDoc {
103
104     if (theRole == null) {
105         String JavaDoc excMsg = "Invalid parameter";
106         throw new IllegalArgumentException JavaDoc(excMsg);
107     }
108     super.add(theRole);
109     return;
110     }
111
112     /**
113      * Inserts the role specified as an element at the position specified.
114      * Elements with an index greater than or equal to the current position are
115      * shifted up.
116      *
117      * @param theIndex The position in the list where the new Role
118      * object is to be inserted.
119      * @param theRole The Role object to be inserted.
120      *
121      * @exception IllegalArgumentException if the role is null.
122      * @exception IndexOutOfBoundsException if accessing with an index
123      * outside of the list.
124      */

125     public void add(int theIndex,
126             Role JavaDoc theRole)
127     throws IllegalArgumentException JavaDoc,
128                IndexOutOfBoundsException JavaDoc {
129
130     if (theRole == null) {
131         String JavaDoc excMsg = "Invalid parameter";
132         throw new IllegalArgumentException JavaDoc(excMsg);
133     }
134
135     super.add(theIndex, theRole);
136     return;
137     }
138
139     /**
140      * Sets the element at the position specified to be the role
141      * specified.
142      * The previous element at that position is discarded.
143      *
144      * @param theIndex The position specified.
145      * @param theRole The value to which the role element should be set.
146      *
147      * @exception IllegalArgumentException if the role is null.
148      * @exception IndexOutOfBoundsException if accessing with an index
149      * outside of the list.
150      */

151      public void set(int theIndex,
152              Role JavaDoc theRole)
153      throws IllegalArgumentException JavaDoc,
154             IndexOutOfBoundsException JavaDoc {
155
156     if (theRole == null) {
157         // Revisit [cebro] Localize message
158
String JavaDoc excMsg = "Invalid parameter.";
159         throw new IllegalArgumentException JavaDoc(excMsg);
160     }
161
162     super.set(theIndex, theRole);
163     return;
164      }
165
166     /**
167      * Appends all the elements in the RoleList specified to the end
168      * of the list, in the order in which they are returned by the Iterator of
169      * the RoleList specified.
170      *
171      * @param theRoleList Elements to be inserted into the list (can be null)
172      *
173      * @return true if this list changed as a result of the call.
174      *
175      * @exception IndexOutOfBoundsException if accessing with an index
176      * outside of the list.
177      *
178      * @see ArrayList#addAll(Collection)
179      */

180     public boolean addAll(RoleList JavaDoc theRoleList)
181     throws IndexOutOfBoundsException JavaDoc {
182
183     if (theRoleList == null) {
184         return true;
185     }
186
187     return (super.addAll(theRoleList));
188     }
189
190     /**
191      * Inserts all of the elements in the RoleList specified into this
192      * list, starting at the specified position, in the order in which they are
193      * returned by the Iterator of the RoleList specified.
194      *
195      * @param theIndex Position at which to insert the first element from the
196      * RoleList specified.
197      * @param theRoleList Elements to be inserted into the list.
198      *
199      * @return true if this list changed as a result of the call.
200      *
201      * @exception IllegalArgumentException if the role is null.
202      * @exception IndexOutOfBoundsException if accessing with an index
203      * outside of the list.
204      *
205      * @see ArrayList#addAll(int, Collection)
206      */

207     public boolean addAll(int theIndex,
208               RoleList JavaDoc theRoleList)
209     throws IllegalArgumentException JavaDoc,
210                IndexOutOfBoundsException JavaDoc {
211
212     if (theRoleList == null) {
213         // Revisit [cebro] Localize message
214
String JavaDoc excMsg = "Invalid parameter.";
215         throw new IllegalArgumentException JavaDoc(excMsg);
216     }
217
218     return (super.addAll(theIndex, theRoleList));
219     }
220 }
221
Popular Tags