1. /*
  2. * @(#)RoleUnresolvedList.java 1.21 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. package javax.management.relation;
  8. import java.util.ArrayList;
  9. import java.util.List;
  10. import java.util.Iterator;
  11. /**
  12. * A RoleUnresolvedList represents a list of RoleUnresolved objects,
  13. * representing roles not retrieved from a relation due to a problem
  14. * encountered when trying to access (read or write to roles).
  15. *
  16. * @since 1.5
  17. */
  18. public class RoleUnresolvedList extends ArrayList {
  19. /* Serial version */
  20. private static final long serialVersionUID = 4054902803091433324L;
  21. //
  22. // Constructors
  23. //
  24. /**
  25. * Constructs an empty RoleUnresolvedList.
  26. */
  27. public RoleUnresolvedList() {
  28. super();
  29. return;
  30. }
  31. /**
  32. * Constructs an empty RoleUnresolvedList with the initial capacity
  33. * specified.
  34. *
  35. * @param theInitialCapacity initial capacity
  36. */
  37. public RoleUnresolvedList(int theInitialCapacity) {
  38. super(theInitialCapacity);
  39. return;
  40. }
  41. /**
  42. * Constructs a RoleUnresolvedList containing the elements of the
  43. * List specified, in the order in which they are returned
  44. * by the List's iterator. The RoleUnresolvedList instance has
  45. * an initial capacity of 110% of the size of the List
  46. * specified.
  47. *
  48. * @param theList list of RoleUnresolved objects
  49. *
  50. * @exception IllegalArgumentException if:
  51. * <P>- null parameter
  52. * <P>or
  53. * <P>- an element in the List is not a RoleUnresolved
  54. */
  55. public RoleUnresolvedList(List theList)
  56. throws IllegalArgumentException {
  57. if (theList == null) {
  58. String excMsg = "Invalid parameter";
  59. throw new IllegalArgumentException(excMsg);
  60. }
  61. int i = 0;
  62. for (Iterator eltIter = theList.iterator();
  63. eltIter.hasNext();) {
  64. Object currElt = eltIter.next();
  65. if (!(currElt instanceof RoleUnresolved)) {
  66. StringBuffer excMsgStrB = new StringBuffer();
  67. String excMsg = "An element is not a RoleUnresolved at index ";
  68. excMsgStrB.append(excMsg);
  69. excMsgStrB.append(i);
  70. throw new IllegalArgumentException(excMsgStrB.toString());
  71. }
  72. i++;
  73. super.add(currElt);
  74. }
  75. return;
  76. }
  77. //
  78. // Accessors
  79. //
  80. /**
  81. * Adds the RoleUnresolved specified as the last element of the list.
  82. *
  83. * @param theRoleUnres - the unresolved role to be added.
  84. *
  85. * @exception IllegalArgumentException if the unresolved role is null.
  86. */
  87. public void add(RoleUnresolved theRoleUnres)
  88. throws IllegalArgumentException {
  89. if (theRoleUnres == null) {
  90. String excMsg = "Invalid parameter";
  91. throw new IllegalArgumentException(excMsg);
  92. }
  93. super.add(theRoleUnres);
  94. return;
  95. }
  96. /**
  97. * Inserts the unresolved role specified as an element at the position
  98. * specified.
  99. * Elements with an index greater than or equal to the current position are
  100. * shifted up.
  101. *
  102. * @param index - The position in the list where the new
  103. * RoleUnresolved object is to be inserted.
  104. * @param theRoleUnres - The RoleUnresolved object to be inserted.
  105. *
  106. * @exception IllegalArgumentException if the unresolved role is null.
  107. * @exception IndexOutOfBoundsException if index is out of range
  108. * (<code>index < 0 || index > size()</code>).
  109. */
  110. public void add(int index,
  111. RoleUnresolved theRoleUnres)
  112. throws IllegalArgumentException,
  113. IndexOutOfBoundsException {
  114. if (theRoleUnres == null) {
  115. String excMsg = "Invalid parameter";
  116. throw new IllegalArgumentException(excMsg);
  117. }
  118. super.add(index, theRoleUnres);
  119. return;
  120. }
  121. /**
  122. * Sets the element at the position specified to be the unresolved role
  123. * specified.
  124. * The previous element at that position is discarded.
  125. *
  126. * @param index - The position specified.
  127. * @param theRoleUnres - The value to which the unresolved role element
  128. * should be set.
  129. *
  130. * @exception IllegalArgumentException if the unresolved role is null.
  131. * @exception IndexOutOfBoundsException if index is out of range
  132. * (<code>index < 0 || index >= size()</code>).
  133. */
  134. public void set(int index,
  135. RoleUnresolved theRoleUnres)
  136. throws IllegalArgumentException,
  137. IndexOutOfBoundsException {
  138. if (theRoleUnres == null) {
  139. String excMsg = "Invalid parameter";
  140. throw new IllegalArgumentException(excMsg);
  141. }
  142. super.set(index, theRoleUnres);
  143. return;
  144. }
  145. /**
  146. * Appends all the elements in the RoleUnresolvedList specified to the end
  147. * of the list, in the order in which they are returned by the Iterator of
  148. * the RoleUnresolvedList specified.
  149. *
  150. * @param theRoleUnresolvedList - Elements to be inserted into the list
  151. * (can be null).
  152. *
  153. * @return true if this list changed as a result of the call.
  154. *
  155. * @exception IndexOutOfBoundsException if accessing with an index
  156. * outside of the list.
  157. */
  158. public boolean addAll(RoleUnresolvedList theRoleUnresolvedList)
  159. throws IndexOutOfBoundsException {
  160. if (theRoleUnresolvedList == null) {
  161. return true;
  162. }
  163. return (super.addAll(theRoleUnresolvedList));
  164. }
  165. /**
  166. * Inserts all of the elements in the RoleUnresolvedList specified into
  167. * this list, starting at the specified position, in the order in which
  168. * they are returned by the Iterator of the RoleUnresolvedList specified.
  169. *
  170. * @param index - Position at which to insert the first element from the
  171. * RoleUnresolvedList specified.
  172. * @param theRoleUnresolvedList - Elements to be inserted into the list.
  173. *
  174. * @return true if this list changed as a result of the call.
  175. *
  176. * @exception IllegalArgumentException if the role is null.
  177. * @exception IndexOutOfBoundsException if index is out of range
  178. * (<code>index < 0 || index > size()</code>).
  179. */
  180. public boolean addAll(int index,
  181. RoleUnresolvedList theRoleUnresolvedList)
  182. throws IllegalArgumentException,
  183. IndexOutOfBoundsException {
  184. if (theRoleUnresolvedList == null) {
  185. String excMsg = "Invalid parameter";
  186. throw new IllegalArgumentException(excMsg);
  187. }
  188. return (super.addAll(index, theRoleUnresolvedList));
  189. }
  190. }