1. /*
  2. * @(#)AttributeList.java 1.25 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;
  8. // java import
  9. import java.util.ArrayList;
  10. /**
  11. * Represents a list of values for attributes of an
  12. * MBean. The methods used for the insertion of {@link javax.management.Attribute Attribute} objects in
  13. * the <CODE>AttributeList</CODE> overrides the corresponding methods in the superclass
  14. * <CODE>ArrayList</CODE>. This is needed in order to insure that the objects contained
  15. * in the <CODE>AttributeList</CODE> are only <CODE>Attribute</CODE> objects. This avoids getting
  16. * an exception when retrieving elements from the <CODE>AttributeList</CODE>.
  17. *
  18. * @since 1.5
  19. */
  20. public class AttributeList extends ArrayList {
  21. /* Serial version */
  22. private static final long serialVersionUID = -4077085769279709076L;
  23. /**
  24. * Constructs an empty <CODE>AttributeList</CODE>.
  25. */
  26. public AttributeList() {
  27. super();
  28. }
  29. /**
  30. * Constructs an empty <CODE>AttributeList</CODE> with the initial capacity specified.
  31. *
  32. * @param initialCapacity the initial capacity of the
  33. * <code>AttributeList</code>, as specified by {@link
  34. * ArrayList#ArrayList(int)}.
  35. */
  36. public AttributeList(int initialCapacity) {
  37. super(initialCapacity);
  38. }
  39. /**
  40. * Constructs an <CODE>AttributeList</CODE> containing the elements of the <CODE>AttributeList</CODE> specified,
  41. * in the order in which they are returned by the <CODE>AttributeList</CODE>'s iterator.
  42. * The <CODE>AttributeList</CODE> instance has an initial capacity of 110% of the
  43. * size of the <CODE>AttributeList</CODE> specified.
  44. *
  45. * @param list the <code>AttributeList</code> that defines the initial
  46. * contents of the new <code>AttributeList</code>.
  47. *
  48. * @see ArrayList#ArrayList(java.util.Collection)
  49. */
  50. public AttributeList(AttributeList list) {
  51. super(list);
  52. }
  53. /**
  54. * Adds the <CODE>Attribute</CODE> specified as the last element of the list.
  55. *
  56. *@param object The attribute to be added.
  57. */
  58. public void add(Attribute object) {
  59. super.add(object);
  60. }
  61. /**
  62. * Inserts the attribute specified as an element at the position specified.
  63. * Elements with an index greater than or equal to the current position are
  64. * shifted up. If the index is out of range (index < 0 || index >
  65. * size() a RuntimeOperationsException should be raised, wrapping the
  66. * java.lang.IndexOutOfBoundsException thrown.
  67. *
  68. * @param object The <CODE>Attribute</CODE> object to be inserted.
  69. * @param index The position in the list where the new <CODE>Attribute</CODE> object is to be
  70. * inserted.
  71. */
  72. public void add(int index, Attribute object) {
  73. try {
  74. super.add(index, object);
  75. }
  76. catch (IndexOutOfBoundsException e) {
  77. throw (new RuntimeOperationsException(e, "The specified index is out of range"));
  78. }
  79. }
  80. /**
  81. * Sets the element at the position specified to be the attribute specified.
  82. * The previous element at that position is discarded. If the index is
  83. * out of range (index < 0 || index > size() a RuntimeOperationsException should
  84. * be raised, wrapping the java.lang.IndexOutOfBoundsException thrown.
  85. *
  86. * @param object The value to which the attribute element should be set.
  87. * @param index The position specified.
  88. */
  89. public void set(int index, Attribute object) {
  90. try {
  91. super.set(index, object);
  92. }
  93. catch (IndexOutOfBoundsException e) {
  94. throw (new RuntimeOperationsException(e, "The specified index is out of range"));
  95. }
  96. }
  97. /**
  98. * Appends all the elements in the <CODE>AttributeList</CODE> specified to the end
  99. * of the list, in the order in which they are returned by the Iterator of
  100. * the <CODE>AttributeList</CODE> specified.
  101. *
  102. * @param list Elements to be inserted into the list.
  103. *
  104. * @return true if this list changed as a result of the call.
  105. *
  106. * @see ArrayList#addAll(java.util.Collection)
  107. */
  108. public boolean addAll(AttributeList list) {
  109. return (super.addAll(list));
  110. }
  111. /**
  112. * Inserts all of the elements in the <CODE>AttributeList</CODE> specified into this
  113. * list, starting at the specified position, in the order in which they
  114. * are returned by the Iterator of the <CODE>AttributeList</CODE> specified. If
  115. * the index is out of range (index < 0 || index > size() a RuntimeOperationsException should
  116. * be raised, wrapping the java.lang.IndexOutOfBoundsException thrown.
  117. *
  118. * @param list Elements to be inserted into the list.
  119. * @param index Position at which to insert the first element from the <CODE>AttributeList</CODE> specified.
  120. *
  121. * @return true if this list changed as a result of the call.
  122. *
  123. * @see ArrayList#addAll(int, java.util.Collection)
  124. */
  125. public boolean addAll(int index, AttributeList list) {
  126. try {
  127. return(super.addAll(index, list));
  128. }
  129. catch (IndexOutOfBoundsException e) {
  130. throw (new RuntimeOperationsException(e, "The specified index is out of range"));
  131. }
  132. }
  133. }