jdk/src/share/classes/java/util/Set.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *         is incompatible with this set (optional)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @throws NullPointerException if the specified element is null and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *         set does not permit null elements (optional)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    boolean contains(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Returns an iterator over the elements in this set.  The elements are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * returned in no particular order (unless this set is an instance of some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * class that provides a guarantee).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @return an iterator over the elements in this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    Iterator<E> iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Returns an array containing all of the elements in this set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * If this set makes any guarantees as to what order its elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * are returned by its iterator, this method must return the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * elements in the same order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * <p>The returned array will be "safe" in that no references to it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * are maintained by this set.  (In other words, this method must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * allocate a new array even if this set is backed by an array).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * The caller is thus free to modify the returned array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * <p>This method acts as bridge between array-based and collection-based
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * APIs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @return an array containing all the elements in this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    Object[] toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * Returns an array containing all of the elements in this set; the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * runtime type of the returned array is that of the specified array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * If the set fits in the specified array, it is returned therein.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Otherwise, a new array is allocated with the runtime type of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * specified array and the size of this set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * <p>If this set fits in the specified array with room to spare
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * (i.e., the array has more elements than this set), the element in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * the array immediately following the end of the set is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * <tt>null</tt>.  (This is useful in determining the length of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * set <i>only</i> if the caller knows that this set does not contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * any null elements.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * <p>If this set makes any guarantees as to what order its elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * are returned by its iterator, this method must return the elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * in the same order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * <p>Like the {@link #toArray()} method, this method acts as bridge between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * array-based and collection-based APIs.  Further, this method allows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * precise control over the runtime type of the output array, and may,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * under certain circumstances, be used to save allocation costs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * <p>Suppose <tt>x</tt> is a set known to contain only strings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * The following code can be used to dump the set into a newly allocated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * array of <tt>String</tt>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *     String[] y = x.toArray(new String[0]);</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * Note that <tt>toArray(new Object[0])</tt> is identical in function to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * <tt>toArray()</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @param a the array into which the elements of this set are to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *        stored, if it is big enough; otherwise, a new array of the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *        runtime type is allocated for this purpose.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @return an array containing all the elements in this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @throws ArrayStoreException if the runtime type of the specified array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *         is not a supertype of the runtime type of every element in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *         set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @throws NullPointerException if the specified array is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    <T> T[] toArray(T[] a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    // Modification Operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * Adds the specified element to this set if it is not already present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * (optional operation).  More formally, adds the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * <tt>e</tt> to this set if the set contains no element <tt>e2</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * <tt>(e==null&nbsp;?&nbsp;e2==null&nbsp;:&nbsp;e.equals(e2))</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * If this set already contains the element, the call leaves the set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * unchanged and returns <tt>false</tt>.  In combination with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * restriction on constructors, this ensures that sets never contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * duplicate elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * <p>The stipulation above does not imply that sets must accept all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * elements; sets may refuse to add any particular element, including
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * <tt>null</tt>, and throw an exception, as described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * specification for {@link Collection#add Collection.add}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Individual set implementations should clearly document any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * restrictions on the elements that they may contain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @param e element to be added to this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @return <tt>true</tt> if this set did not already contain the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *         element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @throws UnsupportedOperationException if the <tt>add</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *         is not supported by this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @throws ClassCastException if the class of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *         prevents it from being added to this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @throws NullPointerException if the specified element is null and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *         set does not permit null elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @throws IllegalArgumentException if some property of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *         prevents it from being added to this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    boolean add(E e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * Removes the specified element from this set if it is present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * (optional operation).  More formally, removes an element <tt>e</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * this set contains such an element.  Returns <tt>true</tt> if this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * contained the element (or equivalently, if this set changed as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * result of the call).  (This set will not contain the element once the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * call returns.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @param o object to be removed from this set, if present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @return <tt>true</tt> if this set contained the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @throws ClassCastException if the type of the specified element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *         is incompatible with this set (optional)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @throws NullPointerException if the specified element is null and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *         set does not permit null elements (optional)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @throws UnsupportedOperationException if the <tt>remove</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *         is not supported by this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    boolean remove(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    // Bulk Operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Returns <tt>true</tt> if this set contains all of the elements of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * specified collection.  If the specified collection is also a set, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * method returns <tt>true</tt> if it is a <i>subset</i> of this set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @param  c collection to be checked for containment in this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @return <tt>true</tt> if this set contains all of the elements of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *         specified collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @throws ClassCastException if the types of one or more elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *         in the specified collection are incompatible with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *         set (optional)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @throws NullPointerException if the specified collection contains one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *         or more null elements and this set does not permit null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *         elements (optional), or if the specified collection is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @see    #contains(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    boolean containsAll(Collection<?> c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * Adds all of the elements in the specified collection to this set if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * they're not already present (optional operation).  If the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * collection is also a set, the <tt>addAll</tt> operation effectively
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * modifies this set so that its value is the <i>union</i> of the two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * sets.  The behavior of this operation is undefined if the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * collection is modified while the operation is in progress.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @param  c collection containing elements to be added to this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @return <tt>true</tt> if this set changed as a result of the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @throws UnsupportedOperationException if the <tt>addAll</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *         is not supported by this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @throws ClassCastException if the class of an element of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *         specified collection prevents it from being added to this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @throws NullPointerException if the specified collection contains one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *         or more null elements and this set does not permit null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *         elements, or if the specified collection is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @throws IllegalArgumentException if some property of an element of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *         specified collection prevents it from being added to this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @see #add(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    boolean addAll(Collection<? extends E> c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * Retains only the elements in this set that are contained in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * specified collection (optional operation).  In other words, removes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * from this set all of its elements that are not contained in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * specified collection.  If the specified collection is also a set, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * operation effectively modifies this set so that its value is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * <i>intersection</i> of the two sets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @param  c collection containing elements to be retained in this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @return <tt>true</tt> if this set changed as a result of the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @throws UnsupportedOperationException if the <tt>retainAll</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *         is not supported by this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @throws ClassCastException if the class of an element of this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *         is incompatible with the specified collection (optional)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @throws NullPointerException if this set contains a null element and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *         specified collection does not permit null elements (optional),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *         or if the specified collection is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @see #remove(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    boolean retainAll(Collection<?> c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * Removes from this set all of its elements that are contained in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * specified collection (optional operation).  If the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * collection is also a set, this operation effectively modifies this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * set so that its value is the <i>asymmetric set difference</i> of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * the two sets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @param  c collection containing elements to be removed from this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * @return <tt>true</tt> if this set changed as a result of the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @throws UnsupportedOperationException if the <tt>removeAll</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *         is not supported by this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @throws ClassCastException if the class of an element of this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *         is incompatible with the specified collection (optional)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * @throws NullPointerException if this set contains a null element and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *         specified collection does not permit null elements (optional),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *         or if the specified collection is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * @see #remove(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @see #contains(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    boolean removeAll(Collection<?> c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * Removes all of the elements from this set (optional operation).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * The set will be empty after this call returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @throws UnsupportedOperationException if the <tt>clear</tt> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *         is not supported by this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    void clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    // Comparison and hashing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * Compares the specified object with this set for equality.  Returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * <tt>true</tt> if the specified object is also a set, the two sets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * have the same size, and every member of the specified set is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * contained in this set (or equivalently, every member of this set is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * contained in the specified set).  This definition ensures that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * equals method works properly across different implementations of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * set interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @param o object to be compared for equality with this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @return <tt>true</tt> if the specified object is equal to this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    boolean equals(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * Returns the hash code value for this set.  The hash code of a set is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * defined to be the sum of the hash codes of the elements in the set,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * where the hash code of a <tt>null</tt> element is defined to be zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * This ensures that <tt>s1.equals(s2)</tt> implies that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * <tt>s1.hashCode()==s2.hashCode()</tt> for any two sets <tt>s1</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * and <tt>s2</tt>, as required by the general contract of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * {@link Object#hashCode}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * @return the hash code value for this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @see Object#equals(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @see Set#equals(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    int hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
}