src/java.management/share/classes/javax/management/relation/RoleList.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/RoleList.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 RoleList represents a list of roles (Role objects). It is used as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * parameter when creating a relation, and when trying to set several roles in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * a relation (via 'setRoles()' method). It is returned as part of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * RoleResult, to provide roles successfully retrieved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/* We cannot extend ArrayList<Role> because our legacy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
   add(Role) method would then override add(E) in ArrayList<E>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
   and our return value is void whereas ArrayList.add(E)'s is boolean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
   Likewise for set(int,Role).  Grrr.  We cannot use covariance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
   to override the most important methods and have them return
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
   Role, either, because that would break subclasses that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
   override those methods in turn (using the original return type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
   of Object).  Finally, we cannot implement Iterable<Role>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
   so you could write
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
       for (Role r : roleList)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
   because ArrayList<> implements Iterable<> and the same class cannot
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
   implement two versions of a generic interface.  Instead we provide
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
   the asList() method so you can write
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
       for (Role r : roleList.asList())
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
public class RoleList extends ArrayList<Object> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private transient boolean typeSafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private transient boolean tainted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /* Serial version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private static final long serialVersionUID = 5568344346499649313L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    // Constructors
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * Constructs an empty RoleList.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public RoleList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * Constructs an empty RoleList with the initial capacity
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @param initialCapacity  initial capacity
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public RoleList(int initialCapacity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        super(initialCapacity);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Constructs a {@code RoleList} containing the elements of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * {@code List} specified, in the order in which they are returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * the {@code List}'s iterator. The {@code RoleList} instance has
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * an initial capacity of 110% of the size of the {@code List}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @param list the {@code List} that defines the initial contents of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * the new {@code RoleList}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @exception IllegalArgumentException if the {@code list} parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * is {@code null} or if the {@code list} parameter contains any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * non-Role objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @see ArrayList#ArrayList(java.util.Collection)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public RoleList(List<Role> list) 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-Role 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<Role>
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<Role>}.
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 RoleList} and vice versa.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @return a {@code List<Role>} whose contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * reflect the contents of this {@code RoleList}.
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 RoleList} instance, a subsequent attempt to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * an object to that instance which is not a {@code Role}
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 RoleList} on which this method has never
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * been called does allow objects other than {@code Role}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 RoleList} contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * an element that is not a {@code Role}.
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<Role> 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 Role 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 role to be added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @exception IllegalArgumentException  if the role is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public void add(Role 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 role specified as an element at the position specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Elements with an index greater than or equal to the current position are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * shifted up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @param index  The position in the list where the new Role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * object is to be inserted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @param role  The Role object to be inserted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @exception IllegalArgumentException  if the role is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @exception IndexOutOfBoundsException  if accessing with an index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * outside of the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public void add(int index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    Role role)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
               IndexOutOfBoundsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        if (role == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            String excMsg = "Invalid parameter";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        super.add(index, role);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Sets the element at the position specified to be the role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * The previous element at that position is discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @param index  The position specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @param role  The value to which the role element should be set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @exception IllegalArgumentException  if the role is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @exception IndexOutOfBoundsException  if accessing with an index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * outside of the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     public void set(int index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                     Role role)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
         throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                IndexOutOfBoundsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        if (role == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            // Revisit [cebro] Localize message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        super.set(index, role);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * Appends all the elements in the RoleList specified to the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * of the list, in the order in which they are returned by the Iterator of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * the RoleList specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @param roleList  Elements to be inserted into the list (can be null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @return true if this list changed as a result of the call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @exception IndexOutOfBoundsException  if accessing with an index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * outside of the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @see ArrayList#addAll(Collection)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public boolean addAll(RoleList 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 RoleList specified into this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * list, starting at the specified position, in the order in which they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * returned by the Iterator of the RoleList 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
     * RoleList 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 accessing with an index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * outside of the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @see ArrayList#addAll(int, Collection)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public boolean addAll(int index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                          RoleList roleList)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
               IndexOutOfBoundsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        if (roleList == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            // Revisit [cebro] Localize message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        return (super.addAll(index, roleList));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Override all of the methods from ArrayList<Object> that might add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * a non-Role to the List, and disallow that if asList has ever
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * been called on this instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public boolean add(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        if (!tainted)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            tainted = isTainted(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        if (typeSafe)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            checkTypeSafe(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        return super.add(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    public void add(int index, Object element) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        if (!tainted)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            tainted = isTainted(element);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        if (typeSafe)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            checkTypeSafe(element);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        super.add(index, element);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    public boolean addAll(Collection<?> c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        if (!tainted)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            tainted = isTainted(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        if (typeSafe)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            checkTypeSafe(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        return super.addAll(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    public boolean addAll(int index, Collection<?> c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        if (!tainted)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            tainted = isTainted(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        if (typeSafe)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            checkTypeSafe(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        return super.addAll(index, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    public Object set(int index, Object element) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        if (!tainted)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            tainted = isTainted(element);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        if (typeSafe)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            checkTypeSafe(element);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        return super.set(index, element);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * IllegalArgumentException if o is a non-Role object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    private static void checkTypeSafe(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            o = (Role) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        } catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            throw new IllegalArgumentException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * IllegalArgumentException if c contains any non-Role objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    private static void checkTypeSafe(Collection<?> c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            Role r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            for (Object o : c)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                r = (Role) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        } catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            throw new IllegalArgumentException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * Returns true if o is a non-Role object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    private static boolean isTainted(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            checkTypeSafe(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * Returns true if c contains any non-Role objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    private static boolean isTainted(Collection<?> c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            checkTypeSafe(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
}