/* * @(#)AttributeList.java 1.25 03/12/19 * * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package javax.management; // java import import java.util.ArrayList; /** * Represents a list of values for attributes of an * MBean. The methods used for the insertion of {@link javax.management.Attribute Attribute} objects in * the AttributeList overrides the corresponding methods in the superclass * ArrayList. This is needed in order to insure that the objects contained * in the AttributeList are only Attribute objects. This avoids getting * an exception when retrieving elements from the AttributeList. * * @since 1.5 */ public class AttributeList extends ArrayList { /* Serial version */ private static final long serialVersionUID = -4077085769279709076L; /** * Constructs an empty AttributeList. */ public AttributeList() { super(); } /** * Constructs an empty AttributeList with the initial capacity specified. * * @param initialCapacity the initial capacity of the * AttributeList, as specified by {@link * ArrayList#ArrayList(int)}. */ public AttributeList(int initialCapacity) { super(initialCapacity); } /** * Constructs an AttributeList containing the elements of the AttributeList specified, * in the order in which they are returned by the AttributeList's iterator. * The AttributeList instance has an initial capacity of 110% of the * size of the AttributeList specified. * * @param list the AttributeList that defines the initial * contents of the new AttributeList. * * @see ArrayList#ArrayList(java.util.Collection) */ public AttributeList(AttributeList list) { super(list); } /** * Adds the Attribute specified as the last element of the list. * *@param object The attribute to be added. */ public void add(Attribute object) { super.add(object); } /** * Inserts the attribute specified as an element at the position specified. * Elements with an index greater than or equal to the current position are * shifted up. If the index is out of range (index < 0 || index > * size() a RuntimeOperationsException should be raised, wrapping the * java.lang.IndexOutOfBoundsException thrown. * * @param object The Attribute object to be inserted. * @param index The position in the list where the new Attribute object is to be * inserted. */ public void add(int index, Attribute object) { try { super.add(index, object); } catch (IndexOutOfBoundsException e) { throw (new RuntimeOperationsException(e, "The specified index is out of range")); } } /** * Sets the element at the position specified to be the attribute specified. * The previous element at that position is discarded. If the index is * out of range (index < 0 || index > size() a RuntimeOperationsException should * be raised, wrapping the java.lang.IndexOutOfBoundsException thrown. * * @param object The value to which the attribute element should be set. * @param index The position specified. */ public void set(int index, Attribute object) { try { super.set(index, object); } catch (IndexOutOfBoundsException e) { throw (new RuntimeOperationsException(e, "The specified index is out of range")); } } /** * Appends all the elements in the AttributeList specified to the end * of the list, in the order in which they are returned by the Iterator of * the AttributeList specified. * * @param list Elements to be inserted into the list. * * @return true if this list changed as a result of the call. * * @see ArrayList#addAll(java.util.Collection) */ public boolean addAll(AttributeList list) { return (super.addAll(list)); } /** * Inserts all of the elements in the AttributeList specified into this * list, starting at the specified position, in the order in which they * are returned by the Iterator of the AttributeList specified. If * the index is out of range (index < 0 || index > size() a RuntimeOperationsException should * be raised, wrapping the java.lang.IndexOutOfBoundsException thrown. * * @param list Elements to be inserted into the list. * @param index Position at which to insert the first element from the AttributeList specified. * * @return true if this list changed as a result of the call. * * @see ArrayList#addAll(int, java.util.Collection) */ public boolean addAll(int index, AttributeList list) { try { return(super.addAll(index, list)); } catch (IndexOutOfBoundsException e) { throw (new RuntimeOperationsException(e, "The specified index is out of range")); } } }