jdk/src/share/classes/java/util/RegularEnumSet.java
author alanb
Mon, 01 Oct 2012 15:36:57 +0100
changeset 14014 da3648e13e67
parent 12448 b95438b17098
child 14342 8435a30053c1
permissions -rw-r--r--
8000269: Cleanup javadoc warnings Reviewed-by: lancea, darcy, ulfzibis, iris, naoto, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8800
diff changeset
     2
 * Copyright (c) 2003, 2011, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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 java.util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * Private implementation class for EnumSet, for "regular sized" enum types
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * (i.e., those with 64 or fewer enum constants).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @author Josh Bloch
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @serial exclude
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> {
8800
e658ae923d53 7028133: Specify serialVersionUID for RegularEnumSet and JumboEnumSet
mduigou
parents: 8787
diff changeset
    37
    private static final long serialVersionUID = 3411599620347842686L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
     * Bit vector representation of this set.  The 2^k bit indicates the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     * presence of universe[k] in this set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private long elements = 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
12448
b95438b17098 7157893: Warnings Cleanup in java.util.*
khazra
parents: 9035
diff changeset
    44
    RegularEnumSet(Class<E>elementType, Enum<?>[] universe) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        super(elementType, universe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    void addRange(E from, E to) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        elements = (-1L >>>  (from.ordinal() - to.ordinal() - 1)) << from.ordinal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    void addAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        if (universe.length != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            elements = -1L >>> -universe.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    void complement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        if (universe.length != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            elements = ~elements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            elements &= -1L >>> -universe.length;  // Mask unused bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Returns an iterator over the elements contained in this set.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * iterator traverses the elements in their <i>natural order</i> (which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * the order in which the enum constants are declared). The returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * Iterator is a "snapshot" iterator that will never throw {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * ConcurrentModificationException}; the elements are traversed as they
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * existed when this call was invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * @return an iterator over the elements contained in this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public Iterator<E> iterator() {
7803
56bc97d69d93 6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents: 5506
diff changeset
    75
        return new EnumSetIterator<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private class EnumSetIterator<E extends Enum<E>> implements Iterator<E> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
         * A bit vector representing the elements in the set not yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
         * returned by this iterator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        long unseen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
         * The bit representing the last element returned by this iterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
         * but not removed, or zero if no such element exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        long lastReturned = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        EnumSetIterator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            unseen = elements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        public boolean hasNext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            return unseen != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
12448
b95438b17098 7157893: Warnings Cleanup in java.util.*
khazra
parents: 9035
diff changeset
    99
        @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        public E next() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            if (unseen == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                throw new NoSuchElementException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            lastReturned = unseen & -unseen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            unseen -= lastReturned;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            return (E) universe[Long.numberOfTrailingZeros(lastReturned)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        public void remove() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            if (lastReturned == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                throw new IllegalStateException();
8787
4b055daf8dd0 7014637: Improve behavior of EnumSet Iterator.remove()
mduigou
parents: 7803
diff changeset
   111
            elements &= ~lastReturned;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            lastReturned = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
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
     * Returns the number of elements in this set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @return the number of elements in this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public int size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        return Long.bitCount(elements);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Returns <tt>true</tt> if this set contains no elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @return <tt>true</tt> if this set contains no elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public boolean isEmpty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        return elements == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Returns <tt>true</tt> if this set contains the specified element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @param e element to be checked for containment in this collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @return <tt>true</tt> if this set contains the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public boolean contains(Object e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            return false;
12448
b95438b17098 7157893: Warnings Cleanup in java.util.*
khazra
parents: 9035
diff changeset
   143
        Class<?> eClass = e.getClass();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        if (eClass != elementType && eClass.getSuperclass() != elementType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
12448
b95438b17098 7157893: Warnings Cleanup in java.util.*
khazra
parents: 9035
diff changeset
   147
        return (elements & (1L << ((Enum<?>)e).ordinal())) != 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    // Modification Operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Adds the specified element to this set if it is not already present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @param e element to be added to this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @return <tt>true</tt> if the set changed as a result of the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @throws NullPointerException if <tt>e</tt> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public boolean add(E e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        typeCheck(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        long oldElements = elements;
12448
b95438b17098 7157893: Warnings Cleanup in java.util.*
khazra
parents: 9035
diff changeset
   164
        elements |= (1L << ((Enum<?>)e).ordinal());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        return elements != oldElements;
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
     * Removes the specified element from this set if it is present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @param e element to be removed from this set, if present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @return <tt>true</tt> if the set contained the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public boolean remove(Object e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            return false;
12448
b95438b17098 7157893: Warnings Cleanup in java.util.*
khazra
parents: 9035
diff changeset
   177
        Class<?> eClass = e.getClass();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        if (eClass != elementType && eClass.getSuperclass() != elementType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        long oldElements = elements;
12448
b95438b17098 7157893: Warnings Cleanup in java.util.*
khazra
parents: 9035
diff changeset
   182
        elements &= ~(1L << ((Enum<?>)e).ordinal());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        return elements != oldElements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    // Bulk Operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * Returns <tt>true</tt> if this set contains all of the elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * in the specified collection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @param c collection to be checked for containment in this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @return <tt>true</tt> if this set contains all of the elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *        in the specified collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @throws NullPointerException if the specified collection is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public boolean containsAll(Collection<?> c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        if (!(c instanceof RegularEnumSet))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            return super.containsAll(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
12448
b95438b17098 7157893: Warnings Cleanup in java.util.*
khazra
parents: 9035
diff changeset
   201
        RegularEnumSet<?> es = (RegularEnumSet<?>)c;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (es.elementType != elementType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            return es.isEmpty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        return (es.elements & ~elements) == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * Adds all of the elements in the specified collection to this set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @param c collection whose elements are to be added to this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @return <tt>true</tt> if this set changed as a result of the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @throws NullPointerException if the specified collection or any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *     of its elements are null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    public boolean addAll(Collection<? extends E> c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        if (!(c instanceof RegularEnumSet))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            return super.addAll(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
12448
b95438b17098 7157893: Warnings Cleanup in java.util.*
khazra
parents: 9035
diff changeset
   220
        RegularEnumSet<?> es = (RegularEnumSet<?>)c;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        if (es.elementType != elementType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            if (es.isEmpty())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                throw new ClassCastException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    es.elementType + " != " + elementType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        long oldElements = elements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        elements |= es.elements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return elements != oldElements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Removes from this set all of its elements that are contained in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * the specified collection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @param c elements to be removed from this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @return <tt>true</tt> if this set changed as a result of the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @throws NullPointerException if the specified collection is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public boolean removeAll(Collection<?> c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (!(c instanceof RegularEnumSet))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            return super.removeAll(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
12448
b95438b17098 7157893: Warnings Cleanup in java.util.*
khazra
parents: 9035
diff changeset
   246
        RegularEnumSet<?> es = (RegularEnumSet<?>)c;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        if (es.elementType != elementType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        long oldElements = elements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        elements &= ~es.elements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        return elements != oldElements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * Retains only the elements in this set that are contained in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * specified collection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @param c elements to be retained in this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @return <tt>true</tt> if this set changed as a result of the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @throws NullPointerException if the specified collection is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public boolean retainAll(Collection<?> c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        if (!(c instanceof RegularEnumSet))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            return super.retainAll(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        RegularEnumSet<?> es = (RegularEnumSet<?>)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        if (es.elementType != elementType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            boolean changed = (elements != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            elements = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            return changed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        long oldElements = elements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        elements &= es.elements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        return elements != oldElements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * Removes all of the elements from this set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public void clear() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        elements = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * Compares the specified object with this set for equality.  Returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * <tt>true</tt> if the given object is also a set, the two sets have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * the same size, and every member of the given set is contained in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * this set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 12448
diff changeset
   292
     * @param o object to be compared for equality with this set
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @return <tt>true</tt> if the specified object is equal to this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        if (!(o instanceof RegularEnumSet))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            return super.equals(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
12448
b95438b17098 7157893: Warnings Cleanup in java.util.*
khazra
parents: 9035
diff changeset
   299
        RegularEnumSet<?> es = (RegularEnumSet<?>)o;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        if (es.elementType != elementType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            return elements == 0 && es.elements == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        return es.elements == elements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
}