src/share/classes/java/util/AbstractCollection.java
Print this page
*** 78,97 ****
public abstract int size();
/**
* {@inheritDoc}
*
! * <p>This implementation returns <tt>size() == 0</tt>.
*/
public boolean isEmpty() {
return size() == 0;
}
/**
* {@inheritDoc}
*
! * <p>This implementation iterates over the elements in the collection,
* checking each element in turn for equality with the specified element.
*
* @throws ClassCastException {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
*/
--- 78,99 ----
public abstract int size();
/**
* {@inheritDoc}
*
! * @implSpec
! * This implementation returns <tt>size() == 0</tt>.
*/
public boolean isEmpty() {
return size() == 0;
}
/**
* {@inheritDoc}
*
! * @implSpec
! * This implementation iterates over the elements in the collection,
* checking each element in turn for equality with the specified element.
*
* @throws ClassCastException {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
*/
*** 110,137 ****
}
/**
* {@inheritDoc}
*
- * <p>This implementation returns an array containing all the elements
- * returned by this collection's iterator, in the same order, stored in
- * consecutive elements of the array, starting with index {@code 0}.
- * The length of the returned array is equal to the number of elements
- * returned by the iterator, even if the size of this collection changes
- * during iteration, as might happen if the collection permits
- * concurrent modification during iteration. The {@code size} method is
- * called only as an optimization hint; the correct result is returned
- * even if the iterator returns a different number of elements.
- *
* <p>This method is equivalent to:
*
* <pre> {@code
* List<E> list = new ArrayList<E>(size());
* for (E e : this)
* list.add(e);
* return list.toArray();
* }</pre>
*/
public Object[] toArray() {
// Estimate size of array; be prepared to see more or fewer elements
Object[] r = new Object[size()];
Iterator<E> it = iterator();
--- 112,140 ----
}
/**
* {@inheritDoc}
*
* <p>This method is equivalent to:
*
* <pre> {@code
* List<E> list = new ArrayList<E>(size());
* for (E e : this)
* list.add(e);
* return list.toArray();
* }</pre>
+ *
+ * @implSpec
+ * This implementation returns an array containing all the elements
+ * returned by this collection's iterator, in the same order, stored in
+ * consecutive elements of the array, starting with index {@code 0}.
+ * The length of the returned array is equal to the number of elements
+ * returned by the iterator, even if the size of this collection changes
+ * during iteration, as might happen if the collection permits
+ * concurrent modification during iteration. The {@code size} method is
+ * called only as an optimization hint; the correct result is returned
+ * even if the iterator returns a different number of elements.
*/
public Object[] toArray() {
// Estimate size of array; be prepared to see more or fewer elements
Object[] r = new Object[size()];
Iterator<E> it = iterator();
*** 144,154 ****
}
/**
* {@inheritDoc}
*
! * <p>This implementation returns an array containing all the elements
* returned by this collection's iterator in the same order, stored in
* consecutive elements of the array, starting with index {@code 0}.
* If the number of elements returned by the iterator is too large to
* fit into the specified array, then the elements are returned in a
* newly allocated array with length equal to the number of elements
--- 147,167 ----
}
/**
* {@inheritDoc}
*
! * <p>This method is equivalent to:
! *
! * <pre> {@code
! * List<E> list = new ArrayList<E>(size());
! * for (E e : this)
! * list.add(e);
! * return list.toArray(a);
! * }</pre>
! *
! * @implSpec
! * This implementation returns an array containing all the elements
* returned by this collection's iterator in the same order, stored in
* consecutive elements of the array, starting with index {@code 0}.
* If the number of elements returned by the iterator is too large to
* fit into the specified array, then the elements are returned in a
* newly allocated array with length equal to the number of elements
*** 156,174 ****
* changes during iteration, as might happen if the collection permits
* concurrent modification during iteration. The {@code size} method is
* called only as an optimization hint; the correct result is returned
* even if the iterator returns a different number of elements.
*
- * <p>This method is equivalent to:
- *
- * <pre> {@code
- * List<E> list = new ArrayList<E>(size());
- * for (E e : this)
- * list.add(e);
- * return list.toArray(a);
- * }</pre>
- *
* @throws ArrayStoreException {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
*/
@SuppressWarnings("unchecked")
public <T> T[] toArray(T[] a) {
--- 169,178 ----
*** 247,257 ****
// Modification Operations
/**
* {@inheritDoc}
*
! * <p>This implementation always throws an
* <tt>UnsupportedOperationException</tt>.
*
* @throws UnsupportedOperationException {@inheritDoc}
* @throws ClassCastException {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
--- 251,262 ----
// Modification Operations
/**
* {@inheritDoc}
*
! * @implSpec
! * This implementation always throws an
* <tt>UnsupportedOperationException</tt>.
*
* @throws UnsupportedOperationException {@inheritDoc}
* @throws ClassCastException {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
*** 263,273 ****
}
/**
* {@inheritDoc}
*
! * <p>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
--- 268,279 ----
}
/**
* {@inheritDoc}
*
! * @implSpec
! * 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
*** 302,312 ****
// Bulk Operations
/**
* {@inheritDoc}
*
! * <p>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}
--- 308,319 ----
// Bulk Operations
/**
* {@inheritDoc}
*
! * @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}
*** 321,331 ****
}
/**
* {@inheritDoc}
*
! * <p>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).
--- 328,339 ----
}
/**
* {@inheritDoc}
*
! * @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).
*** 347,357 ****
}
/**
* {@inheritDoc}
*
! * <p>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
--- 355,366 ----
}
/**
* {@inheritDoc}
*
! * @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
*** 381,391 ****
}
/**
* {@inheritDoc}
*
! * <p>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
--- 390,401 ----
}
/**
* {@inheritDoc}
*
! * @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
*** 415,425 ****
}
/**
* {@inheritDoc}
*
! * <p>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
--- 425,436 ----
}
/**
* {@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