jdk/src/share/classes/java/util/Set.java
author darcy
Fri, 19 Aug 2011 17:42:24 -0700
changeset 10350 6d009f117062
parent 9503 588cf31d584a
child 14342 8435a30053c1
permissions -rw-r--r--
4748706: typos in java.util.Observable documentation Reviewed-by: iris
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: 2
diff changeset
     2
 * Copyright (c) 1997, 2006, 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
 * A collection that contains no duplicate elements.  More formally, sets
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * contain no pair of elements <code>e1</code> and <code>e2</code> such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * <code>e1.equals(e2)</code>, and at most one null element.  As implied by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * its name, this interface models the mathematical <i>set</i> abstraction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <p>The <tt>Set</tt> interface places additional stipulations, beyond those
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * inherited from the <tt>Collection</tt> interface, on the contracts of all
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * constructors and on the contracts of the <tt>add</tt>, <tt>equals</tt> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <tt>hashCode</tt> methods.  Declarations for other inherited methods are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * also included here for convenience.  (The specifications accompanying these
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * declarations have been tailored to the <tt>Set</tt> interface, but they do
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * not contain any additional stipulations.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p>The additional stipulation on constructors is, not surprisingly,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * that all constructors must create a set that contains no duplicate elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * (as defined above).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <p>Note: Great care must be exercised if mutable objects are used as set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * elements.  The behavior of a set is not specified if the value of an object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * is changed in a manner that affects <tt>equals</tt> comparisons while the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * object is an element in the set.  A special case of this prohibition is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * that it is not permissible for a set to contain itself as an element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <p>Some set implementations have restrictions on the elements that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * they may contain.  For example, some implementations prohibit null elements,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * and some have restrictions on the types of their elements.  Attempting to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * add an ineligible element throws an unchecked exception, typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <tt>NullPointerException</tt> or <tt>ClassCastException</tt>.  Attempting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * to query the presence of an ineligible element may throw an exception,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * or it may simply return false; some implementations will exhibit the former
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * behavior and some will exhibit the latter.  More generally, attempting an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * operation on an ineligible element whose completion would not result in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * the insertion of an ineligible element into the set may throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * exception or it may succeed, at the option of the implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * Such exceptions are marked as "optional" in the specification for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <p>This interface is a member of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <a href="{@docRoot}/../technotes/guides/collections/index.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * Java Collections Framework</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * @param <E> the type of elements maintained by this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * @author  Josh Bloch
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * @author  Neal Gafter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * @see Collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * @see List
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * @see SortedSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * @see HashSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * @see TreeSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * @see AbstractSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * @see Collections#singleton(java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * @see Collections#EMPTY_SET
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
public interface Set<E> extends Collection<E> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    // Query Operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * Returns the number of elements in this set (its cardinality).  If this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * set contains more than <tt>Integer.MAX_VALUE</tt> elements, returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * <tt>Integer.MAX_VALUE</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @return the number of elements in this set (its cardinality)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    int size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Returns <tt>true</tt> if this set contains no elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @return <tt>true</tt> if this set contains no elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    boolean isEmpty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Returns <tt>true</tt> if this set contains the specified element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * More formally, returns <tt>true</tt> if and only if this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * contains an element <tt>e</tt> such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @param o element whose presence in this set is to be tested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @return <tt>true</tt> if this set contains the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @throws ClassCastException if the type of the specified element
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   113
     *         is incompatible with this set
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   114
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @throws NullPointerException if the specified element is null and this
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   116
     *         set does not permit null elements
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   117
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    boolean contains(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Returns an iterator over the elements in this set.  The elements are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * returned in no particular order (unless this set is an instance of some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * class that provides a guarantee).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @return an iterator over the elements in this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    Iterator<E> iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Returns an array containing all of the elements in this set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * If this set makes any guarantees as to what order its elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * are returned by its iterator, this method must return the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * elements in the same order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * <p>The returned array will be "safe" in that no references to it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * are maintained by this set.  (In other words, this method must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * allocate a new array even if this set is backed by an array).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * The caller is thus free to modify the returned array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * <p>This method acts as bridge between array-based and collection-based
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * APIs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @return an array containing all the elements in this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    Object[] toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Returns an array containing all of the elements in this set; the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * runtime type of the returned array is that of the specified array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * If the set fits in the specified array, it is returned therein.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * Otherwise, a new array is allocated with the runtime type of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * specified array and the size of this set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * <p>If this set fits in the specified array with room to spare
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * (i.e., the array has more elements than this set), the element in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * the array immediately following the end of the set is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * <tt>null</tt>.  (This is useful in determining the length of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * set <i>only</i> if the caller knows that this set does not contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * any null elements.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * <p>If this set makes any guarantees as to what order its elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * are returned by its iterator, this method must return the elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * in the same order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * <p>Like the {@link #toArray()} method, this method acts as bridge between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * array-based and collection-based APIs.  Further, this method allows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * precise control over the runtime type of the output array, and may,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * under certain circumstances, be used to save allocation costs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * <p>Suppose <tt>x</tt> is a set known to contain only strings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * The following code can be used to dump the set into a newly allocated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * array of <tt>String</tt>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *     String[] y = x.toArray(new String[0]);</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * Note that <tt>toArray(new Object[0])</tt> is identical in function to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * <tt>toArray()</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @param a the array into which the elements of this set are to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *        stored, if it is big enough; otherwise, a new array of the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *        runtime type is allocated for this purpose.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @return an array containing all the elements in this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @throws ArrayStoreException if the runtime type of the specified array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *         is not a supertype of the runtime type of every element in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *         set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @throws NullPointerException if the specified array is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    <T> T[] toArray(T[] a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    // Modification Operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * Adds the specified element to this set if it is not already present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * (optional operation).  More formally, adds the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * <tt>e</tt> to this set if the set contains no element <tt>e2</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * <tt>(e==null&nbsp;?&nbsp;e2==null&nbsp;:&nbsp;e.equals(e2))</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * If this set already contains the element, the call leaves the set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * unchanged and returns <tt>false</tt>.  In combination with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * restriction on constructors, this ensures that sets never contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * duplicate elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * <p>The stipulation above does not imply that sets must accept all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * elements; sets may refuse to add any particular element, including
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * <tt>null</tt>, and throw an exception, as described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * specification for {@link Collection#add Collection.add}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Individual set implementations should clearly document any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * restrictions on the elements that they may contain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @param e element to be added to this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @return <tt>true</tt> if this set did not already contain the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *         element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @throws UnsupportedOperationException if the <tt>add</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *         is not supported by this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *         prevents it from being added to this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @throws NullPointerException if the specified element is null and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *         set does not permit null elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @throws IllegalArgumentException if some property of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *         prevents it from being added to this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    boolean add(E e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * Removes the specified element from this set if it is present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * (optional operation).  More formally, removes an element <tt>e</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * this set contains such an element.  Returns <tt>true</tt> if this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * contained the element (or equivalently, if this set changed as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * result of the call).  (This set will not contain the element once the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * call returns.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @param o object to be removed from this set, if present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @return <tt>true</tt> if this set contained the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @throws ClassCastException if the type of the specified element
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   241
     *         is incompatible with this set
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   242
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @throws NullPointerException if the specified element is null and this
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   244
     *         set does not permit null elements
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   245
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @throws UnsupportedOperationException if the <tt>remove</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *         is not supported by this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    boolean remove(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    // Bulk Operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Returns <tt>true</tt> if this set contains all of the elements of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * specified collection.  If the specified collection is also a set, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * method returns <tt>true</tt> if it is a <i>subset</i> of this set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @param  c collection to be checked for containment in this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @return <tt>true</tt> if this set contains all of the elements of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *         specified collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @throws ClassCastException if the types of one or more elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *         in the specified collection are incompatible with this
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   264
     *         set
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   265
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @throws NullPointerException if the specified collection contains one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *         or more null elements and this set does not permit null
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   268
     *         elements
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   269
     * (<a href="Collection.html#optional-restrictions">optional</a>),
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   270
     *         or if the specified collection is null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @see    #contains(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    boolean containsAll(Collection<?> c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Adds all of the elements in the specified collection to this set if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * they're not already present (optional operation).  If the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * collection is also a set, the <tt>addAll</tt> operation effectively
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * modifies this set so that its value is the <i>union</i> of the two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * sets.  The behavior of this operation is undefined if the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * collection is modified while the operation is in progress.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @param  c collection containing elements to be added to this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @return <tt>true</tt> if this set changed as a result of the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @throws UnsupportedOperationException if the <tt>addAll</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *         is not supported by this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @throws ClassCastException if the class of an element of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *         specified collection prevents it from being added to this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @throws NullPointerException if the specified collection contains one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *         or more null elements and this set does not permit null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *         elements, or if the specified collection is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @throws IllegalArgumentException if some property of an element of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *         specified collection prevents it from being added to this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @see #add(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    boolean addAll(Collection<? extends E> c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * Retains only the elements in this set that are contained in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * specified collection (optional operation).  In other words, removes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * from this set all of its elements that are not contained in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * specified collection.  If the specified collection is also a set, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * operation effectively modifies this set so that its value is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * <i>intersection</i> of the two sets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @param  c collection containing elements to be retained in this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @return <tt>true</tt> if this set changed as a result of the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @throws UnsupportedOperationException if the <tt>retainAll</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *         is not supported by this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @throws ClassCastException if the class of an element of this set
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   312
     *         is incompatible with the specified collection
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   313
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @throws NullPointerException if this set contains a null element and the
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   315
     *         specified collection does not permit null elements
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   316
     *         (<a href="Collection.html#optional-restrictions">optional</a>),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *         or if the specified collection is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * @see #remove(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    boolean retainAll(Collection<?> c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * Removes from this set all of its elements that are contained in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * specified collection (optional operation).  If the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * collection is also a set, this operation effectively modifies this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * set so that its value is the <i>asymmetric set difference</i> of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * the two sets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * @param  c collection containing elements to be removed from this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @return <tt>true</tt> if this set changed as a result of the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * @throws UnsupportedOperationException if the <tt>removeAll</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *         is not supported by this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @throws ClassCastException if the class of an element of this set
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   334
     *         is incompatible with the specified collection
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   335
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @throws NullPointerException if this set contains a null element and the
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   337
     *         specified collection does not permit null elements
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   338
     *         (<a href="Collection.html#optional-restrictions">optional</a>),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *         or if the specified collection is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @see #remove(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @see #contains(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    boolean removeAll(Collection<?> c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * Removes all of the elements from this set (optional operation).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * The set will be empty after this call returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * @throws UnsupportedOperationException if the <tt>clear</tt> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *         is not supported by this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    void clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    // Comparison and hashing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * Compares the specified object with this set for equality.  Returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * <tt>true</tt> if the specified object is also a set, the two sets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * have the same size, and every member of the specified set is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * contained in this set (or equivalently, every member of this set is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * contained in the specified set).  This definition ensures that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * equals method works properly across different implementations of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * set interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * @param o object to be compared for equality with this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @return <tt>true</tt> if the specified object is equal to this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    boolean equals(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * Returns the hash code value for this set.  The hash code of a set is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * defined to be the sum of the hash codes of the elements in the set,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * where the hash code of a <tt>null</tt> element is defined to be zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * This ensures that <tt>s1.equals(s2)</tt> implies that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * <tt>s1.hashCode()==s2.hashCode()</tt> for any two sets <tt>s1</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * and <tt>s2</tt>, as required by the general contract of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * {@link Object#hashCode}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * @return the hash code value for this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * @see Object#equals(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * @see Set#equals(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    int hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
}