< prev index next >
src/java.base/share/classes/java/util/AbstractCollection.java
Print this page
*** 24,50 ****
*/
package java.util;
/**
! * This class provides a skeletal implementation of the <tt>Collection</tt>
* interface, to minimize the effort required to implement this interface. <p>
*
* To implement an unmodifiable collection, the programmer needs only to
! * extend this class and provide implementations for the <tt>iterator</tt> and
! * <tt>size</tt> methods. (The iterator returned by the <tt>iterator</tt>
! * method must implement <tt>hasNext</tt> and <tt>next</tt>.)<p>
*
* To implement a modifiable collection, the programmer must additionally
! * override this class's <tt>add</tt> method (which otherwise throws an
! * <tt>UnsupportedOperationException</tt>), and the iterator returned by the
! * <tt>iterator</tt> method must additionally implement its <tt>remove</tt>
* method.<p>
*
* The programmer should generally provide a void (no argument) and
! * <tt>Collection</tt> constructor, as per the recommendation in the
! * <tt>Collection</tt> interface specification.<p>
*
* The documentation for each non-abstract method in this class describes its
* implementation in detail. Each of these methods may be overridden if
* the collection being implemented admits a more efficient implementation.<p>
*
--- 24,50 ----
*/
package java.util;
/**
! * This class provides a skeletal implementation of the {@code Collection}
* interface, to minimize the effort required to implement this interface. <p>
*
* To implement an unmodifiable collection, the programmer needs only to
! * extend this class and provide implementations for the {@code iterator} and
! * {@code size} methods. (The iterator returned by the {@code iterator}
! * method must implement {@code hasNext} and {@code next}.)<p>
*
* To implement a modifiable collection, the programmer must additionally
! * override this class's {@code add} method (which otherwise throws an
! * {@code UnsupportedOperationException}), and the iterator returned by the
! * {@code iterator} method must additionally implement its {@code remove}
* method.<p>
*
* The programmer should generally provide a void (no argument) and
! * {@code Collection} constructor, as per the recommendation in the
! * {@code Collection} interface specification.<p>
*
* The documentation for each non-abstract method in this class describes its
* implementation in detail. Each of these methods may be overridden if
* the collection being implemented admits a more efficient implementation.<p>
*
*** 79,89 ****
/**
* {@inheritDoc}
*
* @implSpec
! * This implementation returns <tt>size() == 0</tt>.
*/
public boolean isEmpty() {
return size() == 0;
}
--- 79,89 ----
/**
* {@inheritDoc}
*
* @implSpec
! * This implementation returns {@code size() == 0}.
*/
public boolean isEmpty() {
return size() == 0;
}
*** 253,263 ****
/**
* {@inheritDoc}
*
* @implSpec
* This implementation always throws an
! * <tt>UnsupportedOperationException</tt>.
*
* @throws UnsupportedOperationException {@inheritDoc}
* @throws ClassCastException {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
* @throws IllegalArgumentException {@inheritDoc}
--- 253,263 ----
/**
* {@inheritDoc}
*
* @implSpec
* This implementation always throws an
! * {@code UnsupportedOperationException}.
*
* @throws UnsupportedOperationException {@inheritDoc}
* @throws ClassCastException {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
* @throws IllegalArgumentException {@inheritDoc}
*** 274,285 ****
* This implementation iterates over the collection looking for the
* specified element. If it finds the element, it removes the element
* from the collection using the iterator's remove method.
*
* <p>Note that this implementation throws an
! * <tt>UnsupportedOperationException</tt> if the iterator returned by this
! * collection's iterator method does not implement the <tt>remove</tt>
* method and this collection contains the specified object.
*
* @throws UnsupportedOperationException {@inheritDoc}
* @throws ClassCastException {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
--- 274,285 ----
* This implementation iterates over the collection looking for the
* specified element. If it finds the element, it removes the element
* from the collection using the iterator's remove method.
*
* <p>Note that this implementation throws an
! * {@code UnsupportedOperationException} if the iterator returned by this
! * collection's iterator method does not implement the {@code remove}
* method and this collection contains the specified object.
*
* @throws UnsupportedOperationException {@inheritDoc}
* @throws ClassCastException {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
*** 312,322 ****
*
* @implSpec
* This implementation iterates over the specified collection,
* checking each element returned by the iterator in turn to see
* if it's contained in this collection. If all elements are so
! * contained <tt>true</tt> is returned, otherwise <tt>false</tt>.
*
* @throws ClassCastException {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
* @see #contains(Object)
*/
--- 312,322 ----
*
* @implSpec
* This implementation iterates over the specified collection,
* checking each element returned by the iterator in turn to see
* if it's contained in this collection. If all elements are so
! * contained {@code true} is returned, otherwise {@code false}.
*
* @throws ClassCastException {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
* @see #contains(Object)
*/
*** 333,343 ****
* @implSpec
* This implementation iterates over the specified collection, and adds
* each object returned by the iterator to this collection, in turn.
*
* <p>Note that this implementation will throw an
! * <tt>UnsupportedOperationException</tt> unless <tt>add</tt> is
* overridden (assuming the specified collection is non-empty).
*
* @throws UnsupportedOperationException {@inheritDoc}
* @throws ClassCastException {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
--- 333,343 ----
* @implSpec
* This implementation iterates over the specified collection, and adds
* each object returned by the iterator to this collection, in turn.
*
* <p>Note that this implementation will throw an
! * {@code UnsupportedOperationException} unless {@code add} is
* overridden (assuming the specified collection is non-empty).
*
* @throws UnsupportedOperationException {@inheritDoc}
* @throws ClassCastException {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
*** 359,373 ****
*
* @implSpec
* This implementation iterates over this collection, checking each
* element returned by the iterator in turn to see if it's contained
* in the specified collection. If it's so contained, it's removed from
! * this collection with the iterator's <tt>remove</tt> method.
*
* <p>Note that this implementation will throw an
! * <tt>UnsupportedOperationException</tt> if the iterator returned by the
! * <tt>iterator</tt> method does not implement the <tt>remove</tt> method
* and this collection contains one or more elements in common with the
* specified collection.
*
* @throws UnsupportedOperationException {@inheritDoc}
* @throws ClassCastException {@inheritDoc}
--- 359,373 ----
*
* @implSpec
* This implementation iterates over this collection, checking each
* element returned by the iterator in turn to see if it's contained
* in the specified collection. If it's so contained, it's removed from
! * this collection with the iterator's {@code remove} method.
*
* <p>Note that this implementation will throw an
! * {@code UnsupportedOperationException} if the iterator returned by the
! * {@code iterator} method does not implement the {@code remove} method
* and this collection contains one or more elements in common with the
* specified collection.
*
* @throws UnsupportedOperationException {@inheritDoc}
* @throws ClassCastException {@inheritDoc}
*** 394,408 ****
*
* @implSpec
* This implementation iterates over this collection, checking each
* element returned by the iterator in turn to see if it's contained
* in the specified collection. If it's not so contained, it's removed
! * from this collection with the iterator's <tt>remove</tt> method.
*
* <p>Note that this implementation will throw an
! * <tt>UnsupportedOperationException</tt> if the iterator returned by the
! * <tt>iterator</tt> method does not implement the <tt>remove</tt> method
* and this collection contains one or more elements not present in the
* specified collection.
*
* @throws UnsupportedOperationException {@inheritDoc}
* @throws ClassCastException {@inheritDoc}
--- 394,408 ----
*
* @implSpec
* This implementation iterates over this collection, checking each
* element returned by the iterator in turn to see if it's contained
* in the specified collection. If it's not so contained, it's removed
! * from this collection with the iterator's {@code remove} method.
*
* <p>Note that this implementation will throw an
! * {@code UnsupportedOperationException} if the iterator returned by the
! * {@code iterator} method does not implement the {@code remove} method
* and this collection contains one or more elements not present in the
* specified collection.
*
* @throws UnsupportedOperationException {@inheritDoc}
* @throws ClassCastException {@inheritDoc}
*** 427,444 ****
/**
* {@inheritDoc}
*
* @implSpec
* This implementation iterates over this collection, removing each
! * element using the <tt>Iterator.remove</tt> operation. Most
* implementations will probably choose to override this method for
* efficiency.
*
* <p>Note that this implementation will throw an
! * <tt>UnsupportedOperationException</tt> if the iterator returned by this
! * collection's <tt>iterator</tt> method does not implement the
! * <tt>remove</tt> method and this collection is non-empty.
*
* @throws UnsupportedOperationException {@inheritDoc}
*/
public void clear() {
Iterator<E> it = iterator();
--- 427,444 ----
/**
* {@inheritDoc}
*
* @implSpec
* This implementation iterates over this collection, removing each
! * element using the {@code Iterator.remove} operation. Most
* implementations will probably choose to override this method for
* efficiency.
*
* <p>Note that this implementation will throw an
! * {@code UnsupportedOperationException} if the iterator returned by this
! * collection's {@code iterator} method does not implement the
! * {@code remove} method and this collection is non-empty.
*
* @throws UnsupportedOperationException {@inheritDoc}
*/
public void clear() {
Iterator<E> it = iterator();
*** 453,464 ****
/**
* Returns a string representation of this collection. The string
* representation consists of a list of the collection's elements in the
* order they are returned by its iterator, enclosed in square brackets
! * (<tt>"[]"</tt>). Adjacent elements are separated by the characters
! * <tt>", "</tt> (comma and space). Elements are converted to strings as
* by {@link String#valueOf(Object)}.
*
* @return a string representation of this collection
*/
public String toString() {
--- 453,464 ----
/**
* Returns a string representation of this collection. The string
* representation consists of a list of the collection's elements in the
* order they are returned by its iterator, enclosed in square brackets
! * ({@code "[]"}). Adjacent elements are separated by the characters
! * {@code ", "} (comma and space). Elements are converted to strings as
* by {@link String#valueOf(Object)}.
*
* @return a string representation of this collection
*/
public String toString() {
< prev index next >