src/java.management/share/classes/javax/management/relation/RoleUnresolvedList.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 25859 jdk/src/java.management/share/classes/javax/management/relation/RoleUnresolvedList.java@3317bb8137f4
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
     2
 * Copyright (c) 2000, 2008, 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: 1639
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: 1639
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: 1639
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
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.relation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
    28
import com.sun.jmx.mbeanserver.Util;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Collection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * A RoleUnresolvedList represents a list of RoleUnresolved objects,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * representing roles not retrieved from a relation due to a problem
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * encountered when trying to access (read or write) the roles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/* We cannot extend ArrayList<RoleUnresolved> because our legacy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
   add(RoleUnresolved) method would then override add(E) in ArrayList<E>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
   and our return value is void whereas ArrayList.add(E)'s is boolean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
   Likewise for set(int,RoleUnresolved).  Grrr.  We cannot use covariance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
   to override the most important methods and have them return
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
   RoleUnresolved, either, because that would break subclasses that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
   override those methods in turn (using the original return type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
   of Object).  Finally, we cannot implement Iterable<RoleUnresolved>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
   so you could write
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
       for (RoleUnresolved r : roleUnresolvedList)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
   because ArrayList<> implements Iterable<> and the same class cannot
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
   implement two versions of a generic interface.  Instead we provide
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
   the asList() method so you can write
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
       for (RoleUnresolved r : roleUnresolvedList.asList())
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
public class RoleUnresolvedList extends ArrayList<Object> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private transient boolean typeSafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private transient boolean tainted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /* Serial version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private static final long serialVersionUID = 4054902803091433324L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    // Constructors
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * Constructs an empty RoleUnresolvedList.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public RoleUnresolvedList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * Constructs an empty RoleUnresolvedList with the initial capacity
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @param initialCapacity  initial capacity
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public RoleUnresolvedList(int initialCapacity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        super(initialCapacity);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Constructs a {@code RoleUnresolvedList} containing the elements of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * {@code List} specified, in the order in which they are returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * the {@code List}'s iterator. The {@code RoleUnresolvedList} instance has
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * an initial capacity of 110% of the size of the {@code List}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @param list the {@code List} that defines the initial contents of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * the new {@code RoleUnresolvedList}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @exception IllegalArgumentException if the {@code list} parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * is {@code null} or if the {@code list} parameter contains any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * non-RoleUnresolved objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @see ArrayList#ArrayList(java.util.Collection)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public RoleUnresolvedList(List<RoleUnresolved> list)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        // Check for null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        if (list == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            throw new IllegalArgumentException("Null parameter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        // Check for non-RoleUnresolved objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        checkTypeSafe(list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        // Build the List<RoleUnresolved>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        super.addAll(list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * Return a view of this list as a {@code List<RoleUnresolved>}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Changes to the returned value are reflected by changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * to the original {@code RoleUnresolvedList} and vice versa.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @return a {@code List<RoleUnresolved>} whose contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * reflect the contents of this {@code RoleUnresolvedList}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * <p>If this method has ever been called on a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * {@code RoleUnresolvedList} instance, a subsequent attempt to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * an object to that instance which is not a {@code RoleUnresolved}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * will fail with an {@code IllegalArgumentException}. For compatibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * reasons, a {@code RoleUnresolvedList} on which this method has never
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * been called does allow objects other than {@code RoleUnresolved}s to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * be added.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @throws IllegalArgumentException if this {@code RoleUnresolvedList}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * contains an element that is not a {@code RoleUnresolved}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    @SuppressWarnings("unchecked")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public List<RoleUnresolved> asList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if (!typeSafe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            if (tainted)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                checkTypeSafe(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            typeSafe = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   144
        return Util.cast(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    // Accessors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * Adds the RoleUnresolved specified as the last element of the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @param role - the unresolved role to be added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @exception IllegalArgumentException  if the unresolved role is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public void add(RoleUnresolved role)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        if (role == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            String excMsg = "Invalid parameter";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        super.add(role);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * Inserts the unresolved role specified as an element at the position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * Elements with an index greater than or equal to the current position are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * shifted up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @param index - The position in the list where the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * RoleUnresolved object is to be inserted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @param role - The RoleUnresolved object to be inserted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @exception IllegalArgumentException  if the unresolved role is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @exception IndexOutOfBoundsException if index is out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * (<code>index &lt; 0 || index &gt; size()</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public void add(int index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                    RoleUnresolved role)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
               IndexOutOfBoundsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        if (role == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            String excMsg = "Invalid parameter";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        super.add(index, role);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * Sets the element at the position specified to be the unresolved role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * The previous element at that position is discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @param index - The position specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @param role - The value to which the unresolved role element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * should be set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @exception IllegalArgumentException   if the unresolved role is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @exception IndexOutOfBoundsException if index is out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * (<code>index &lt; 0 || index &gt;= size()</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     public void set(int index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                     RoleUnresolved role)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
         throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                IndexOutOfBoundsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        if (role == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            String excMsg = "Invalid parameter";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        super.set(index, role);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * Appends all the elements in the RoleUnresolvedList specified to the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * of the list, in the order in which they are returned by the Iterator of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * the RoleUnresolvedList specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @param roleList - Elements to be inserted into the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * (can be null).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @return true if this list changed as a result of the call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @exception IndexOutOfBoundsException  if accessing with an index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * outside of the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public boolean addAll(RoleUnresolvedList roleList)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        throws IndexOutOfBoundsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        if (roleList == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        return (super.addAll(roleList));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * Inserts all of the elements in the RoleUnresolvedList specified into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * this list, starting at the specified position, in the order in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * they are returned by the Iterator of the RoleUnresolvedList specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @param index - Position at which to insert the first element from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * RoleUnresolvedList specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @param roleList - Elements to be inserted into the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @return true if this list changed as a result of the call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @exception IllegalArgumentException  if the role is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @exception IndexOutOfBoundsException if index is out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * (<code>index &lt; 0 || index &gt; size()</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    public boolean addAll(int index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                          RoleUnresolvedList roleList)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
               IndexOutOfBoundsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        if (roleList == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            String excMsg = "Invalid parameter";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        return (super.addAll(index, roleList));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Override all of the methods from ArrayList<Object> that might add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * a non-RoleUnresolved to the List, and disallow that if asList has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * ever been called on this instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public boolean add(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        if (!tainted)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            tainted = isTainted(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        if (typeSafe)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            checkTypeSafe(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        return super.add(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public void add(int index, Object element) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        if (!tainted)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            tainted = isTainted(element);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        if (typeSafe)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            checkTypeSafe(element);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        super.add(index, element);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    public boolean addAll(Collection<?> c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        if (!tainted)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            tainted = isTainted(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        if (typeSafe)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            checkTypeSafe(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        return super.addAll(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    public boolean addAll(int index, Collection<?> c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        if (!tainted)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            tainted = isTainted(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        if (typeSafe)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            checkTypeSafe(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        return super.addAll(index, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public Object set(int index, Object element) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        if (!tainted)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            tainted = isTainted(element);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        if (typeSafe)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            checkTypeSafe(element);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        return super.set(index, element);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * IllegalArgumentException if o is a non-RoleUnresolved object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    private static void checkTypeSafe(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            o = (RoleUnresolved) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        } catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            throw new IllegalArgumentException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * IllegalArgumentException if c contains any non-RoleUnresolved objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    private static void checkTypeSafe(Collection<?> c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            RoleUnresolved r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            for (Object o : c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                r = (RoleUnresolved) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        } catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            throw new IllegalArgumentException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * Returns true if o is a non-RoleUnresolved object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    private static boolean isTainted(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            checkTypeSafe(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * Returns true if c contains any non-RoleUnresolved objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    private static boolean isTainted(Collection<?> c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            checkTypeSafe(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
}