src/java.management/share/classes/javax/management/AttributeList.java
author darcy
Wed, 23 Oct 2019 13:01:40 -0700
changeset 58766 54ffb15c4839
parent 47216 71c04702a3d5
permissions -rw-r--r--
8232442: Suppress warnings on non-serializable non-transient instance fields in java.management.* Reviewed-by: rriggs, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21656
diff changeset
     2
 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.management;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Collection;
1571
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
    30
import java.util.LinkedHashMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.List;
1571
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
    32
import java.util.Map;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
1571
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
    35
 * <p>Represents a list of values for attributes of an MBean.  See the
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
    36
 * {@link MBeanServerConnection#getAttributes getAttributes} and
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
    37
 * {@link MBeanServerConnection#setAttributes setAttributes} methods of
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
    38
 * {@link MBeanServer} and {@link MBeanServerConnection}.</p>
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
    39
 *
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
    40
 * <p id="type-safe">For compatibility reasons, it is possible, though
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
    41
 * highly discouraged, to add objects to an {@code AttributeList} that are
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
    42
 * not instances of {@code Attribute}.  However, an {@code AttributeList}
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
    43
 * can be made <em>type-safe</em>, which means that an attempt to add
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
    44
 * an object that is not an {@code Attribute} will produce an {@code
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
    45
 * IllegalArgumentException}.  An {@code AttributeList} becomes type-safe
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
    46
 * when the method {@link #asList()} is called on it.</p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
/* We cannot extend ArrayList<Attribute> because our legacy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
   add(Attribute) method would then override add(E) in ArrayList<E>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
   and our return value is void whereas ArrayList.add(E)'s is boolean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
   Likewise for set(int,Attribute).  Grrr.  We cannot use covariance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
   to override the most important methods and have them return
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
   Attribute, either, because that would break subclasses that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
   override those methods in turn (using the original return type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
   of Object).  Finally, we cannot implement Iterable<Attribute>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
   so you could write
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
       for (Attribute a : attributeList)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
   because ArrayList<> implements Iterable<> and the same class cannot
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
   implement two versions of a generic interface.  Instead we provide
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
   the asList() method so you can write
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
       for (Attribute a : attributeList.asList())
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
public class AttributeList extends ArrayList<Object> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
1571
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
    67
    private transient volatile boolean typeSafe;
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
    68
    private transient volatile boolean tainted;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /* Serial version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private static final long serialVersionUID = -4077085769279709076L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * Constructs an empty <CODE>AttributeList</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public AttributeList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Constructs an empty <CODE>AttributeList</CODE> with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * the initial capacity specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @param initialCapacity the initial capacity of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * <code>AttributeList</code>, as specified by {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * ArrayList#ArrayList(int)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public AttributeList(int initialCapacity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        super(initialCapacity);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Constructs an <CODE>AttributeList</CODE> containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * elements of the <CODE>AttributeList</CODE> specified, in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * order in which they are returned by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * <CODE>AttributeList</CODE>'s iterator.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * <CODE>AttributeList</CODE> instance has an initial capacity of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * 110% of the size of the <CODE>AttributeList</CODE> specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @param list the <code>AttributeList</code> that defines the initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * contents of the new <code>AttributeList</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @see ArrayList#ArrayList(java.util.Collection)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public AttributeList(AttributeList list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        super(list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Constructs an {@code AttributeList} containing the elements of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * {@code List} specified, in the order in which they are returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * the {@code List}'s iterator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @param list the {@code List} that defines the initial contents of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * the new {@code AttributeList}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @exception IllegalArgumentException if the {@code list} parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * is {@code null} or if the {@code list} parameter contains any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * non-Attribute objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @see ArrayList#ArrayList(java.util.Collection)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public AttributeList(List<Attribute> list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        // Check for null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        if (list == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            throw new IllegalArgumentException("Null parameter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        // Check for non-Attribute objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        //
1571
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   133
        adding(list);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        // Build the List<Attribute>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        super.addAll(list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Return a view of this list as a {@code List<Attribute>}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Changes to the returned value are reflected by changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * to the original {@code AttributeList} and vice versa.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @return a {@code List<Attribute>} whose contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * reflect the contents of this {@code AttributeList}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * <p>If this method has ever been called on a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * {@code AttributeList} instance, a subsequent attempt to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * an object to that instance which is not an {@code Attribute}
37880
60ec48925dc6 8156661: Handful of typos in javadoc
igerasim
parents: 25859
diff changeset
   151
     * will fail with an {@code IllegalArgumentException}. For compatibility
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * reasons, an {@code AttributeList} on which this method has never
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * been called does allow objects other than {@code Attribute}s to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * be added.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @throws IllegalArgumentException if this {@code AttributeList} contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * an element that is not an {@code Attribute}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    @SuppressWarnings("unchecked")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public List<Attribute> asList() {
1571
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   163
        typeSafe = true;
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   164
        if (tainted)
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   165
            adding((Collection<?>) this);  // will throw IllegalArgumentException
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   166
        return (List<Attribute>) (List<?>) this;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Adds the {@code Attribute} specified as the last element of the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @param object  The attribute to be added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public void add(Attribute object)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        super.add(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * Inserts the attribute specified as an element at the position specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * Elements with an index greater than or equal to the current position are
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   181
     * shifted up. If the index is out of range {@literal (index < 0 || index >
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   182
     * size())} a RuntimeOperationsException should be raised, wrapping the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * java.lang.IndexOutOfBoundsException thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @param object  The <CODE>Attribute</CODE> object to be inserted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @param index The position in the list where the new {@code Attribute}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * object is to be inserted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public void add(int index, Attribute object)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            super.add(index, object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        catch (IndexOutOfBoundsException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            throw new RuntimeOperationsException(e,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                "The specified index is out of range");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * Sets the element at the position specified to be the attribute specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * The previous element at that position is discarded. If the index is
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   202
     * out of range {@literal (index < 0 || index > size())} a RuntimeOperationsException
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * should be raised, wrapping the java.lang.IndexOutOfBoundsException thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @param object  The value to which the attribute element should be set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @param index  The position specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public void set(int index, Attribute object)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            super.set(index, object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        catch (IndexOutOfBoundsException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            throw new RuntimeOperationsException(e,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                "The specified index is out of range");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Appends all the elements in the <CODE>AttributeList</CODE> specified to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * the end of the list, in the order in which they are returned by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * Iterator of the <CODE>AttributeList</CODE> specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @param list  Elements to be inserted into the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @return true if this list changed as a result of the call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @see ArrayList#addAll(java.util.Collection)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public boolean addAll(AttributeList list)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        return (super.addAll(list));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * Inserts all of the elements in the <CODE>AttributeList</CODE> specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * into this list, starting at the specified position, in the order in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * they are returned by the Iterator of the {@code AttributeList} specified.
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   237
     * If the index is out of range {@literal (index < 0 || index > size())} a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * RuntimeOperationsException should be raised, wrapping the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * java.lang.IndexOutOfBoundsException thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @param list  Elements to be inserted into the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @param index  Position at which to insert the first element from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * <CODE>AttributeList</CODE> specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @return true if this list changed as a result of the call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @see ArrayList#addAll(int, java.util.Collection)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    public boolean addAll(int index, AttributeList list)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            return super.addAll(index, list);
1571
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   252
        } catch (IndexOutOfBoundsException e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            throw new RuntimeOperationsException(e,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                "The specified index is out of range");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * Override all of the methods from ArrayList<Object> that might add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * a non-Attribute to the List, and disallow that if asList has ever
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * been called on this instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
1571
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   264
    /**
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   265
     * {@inheritDoc}
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   266
     * @throws IllegalArgumentException if this {@code AttributeList} is
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   267
     * <a href="#type-safe">type-safe</a> and {@code element} is not an
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   268
     * {@code Attribute}.
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   269
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    @Override
1571
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   271
    public boolean add(Object element) {
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   272
        adding(element);
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   273
        return super.add(element);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
1571
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   276
    /**
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   277
     * {@inheritDoc}
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   278
     * @throws IllegalArgumentException if this {@code AttributeList} is
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   279
     * <a href="#type-safe">type-safe</a> and {@code element} is not an
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   280
     * {@code Attribute}.
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   281
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    public void add(int index, Object element) {
1571
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   284
        adding(element);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        super.add(index, element);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
1571
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   288
    /**
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   289
     * {@inheritDoc}
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   290
     * @throws IllegalArgumentException if this {@code AttributeList} is
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   291
     * <a href="#type-safe">type-safe</a> and {@code c} contains an
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   292
     * element that is not an {@code Attribute}.
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   293
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public boolean addAll(Collection<?> c) {
1571
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   296
        adding(c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        return super.addAll(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /**
1571
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   301
     * {@inheritDoc}
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   302
     * @throws IllegalArgumentException if this {@code AttributeList} is
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   303
     * <a href="#type-safe">type-safe</a> and {@code c} contains an
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   304
     * element that is not an {@code Attribute}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     */
1571
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   306
    @Override
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   307
    public boolean addAll(int index, Collection<?> c) {
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   308
        adding(c);
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   309
        return super.addAll(index, c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    /**
1571
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   313
     * {@inheritDoc}
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   314
     * @throws IllegalArgumentException if this {@code AttributeList} is
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   315
     * <a href="#type-safe">type-safe</a> and {@code element} is not an
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   316
     * {@code Attribute}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     */
1571
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   318
    @Override
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   319
    public Object set(int index, Object element) {
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   320
        adding(element);
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   321
        return super.set(index, element);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
1571
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   324
    private void adding(Object x) {
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   325
        if (x == null || x instanceof Attribute)
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   326
            return;
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   327
        if (typeSafe)
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   328
            throw new IllegalArgumentException("Not an Attribute: " + x);
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   329
        else
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   330
            tainted = true;
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   331
    }
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   332
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   333
    private void adding(Collection<?> c) {
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   334
        for (Object x : c)
421ef5172dd3 6336968: Methods to convert AttributeList to/from Map
emcmanus
parents: 1510
diff changeset
   335
            adding(x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
}