src/share/classes/java/util/AbstractCollection.java
Print this page
*** 94,111 ****
*
* @throws ClassCastException {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
*/
public boolean contains(Object o) {
! Iterator<E> e = iterator();
if (o==null) {
! while (e.hasNext())
! if (e.next()==null)
return true;
} else {
! while (e.hasNext())
! if (o.equals(e.next()))
return true;
}
return false;
}
--- 94,111 ----
*
* @throws ClassCastException {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
*/
public boolean contains(Object o) {
! Iterator<E> it = iterator();
if (o==null) {
! while (it.hasNext())
! if (it.next()==null)
return true;
} else {
! while (it.hasNext())
! if (o.equals(it.next()))
return true;
}
return false;
}
*** 267,288 ****
* @throws UnsupportedOperationException {@inheritDoc}
* @throws ClassCastException {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
*/
public boolean remove(Object o) {
! Iterator<E> e = iterator();
if (o==null) {
! while (e.hasNext()) {
! if (e.next()==null) {
! e.remove();
return true;
}
}
} else {
! while (e.hasNext()) {
! if (o.equals(e.next())) {
! e.remove();
return true;
}
}
}
return false;
--- 267,288 ----
* @throws UnsupportedOperationException {@inheritDoc}
* @throws ClassCastException {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
*/
public boolean remove(Object o) {
! Iterator<E> it = iterator();
if (o==null) {
! while (it.hasNext()) {
! if (it.next()==null) {
! it.remove();
return true;
}
}
} else {
! while (it.hasNext()) {
! if (o.equals(it.next())) {
! it.remove();
return true;
}
}
}
return false;
*** 302,314 ****
* @throws ClassCastException {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
* @see #contains(Object)
*/
public boolean containsAll(Collection<?> c) {
! Iterator<?> e = c.iterator();
! while (e.hasNext())
! if (!contains(e.next()))
return false;
return true;
}
/**
--- 302,313 ----
* @throws ClassCastException {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
* @see #contains(Object)
*/
public boolean containsAll(Collection<?> c) {
! for (Object e : c)
! if (!contains(e))
return false;
return true;
}
/**
*** 329,343 ****
*
* @see #add(Object)
*/
public boolean addAll(Collection<? extends E> c) {
boolean modified = false;
! Iterator<? extends E> e = c.iterator();
! while (e.hasNext()) {
! if (add(e.next()))
modified = true;
- }
return modified;
}
/**
* {@inheritDoc}
--- 328,340 ----
*
* @see #add(Object)
*/
public boolean addAll(Collection<? extends E> c) {
boolean modified = false;
! for (E e : c)
! if (add(e))
modified = true;
return modified;
}
/**
* {@inheritDoc}
*** 360,373 ****
* @see #remove(Object)
* @see #contains(Object)
*/
public boolean removeAll(Collection<?> c) {
boolean modified = false;
! Iterator<?> e = iterator();
! while (e.hasNext()) {
! if (c.contains(e.next())) {
! e.remove();
modified = true;
}
}
return modified;
}
--- 357,370 ----
* @see #remove(Object)
* @see #contains(Object)
*/
public boolean removeAll(Collection<?> c) {
boolean modified = false;
! Iterator<?> it = iterator();
! while (it.hasNext()) {
! if (c.contains(it.next())) {
! it.remove();
modified = true;
}
}
return modified;
}
*** 393,406 ****
* @see #remove(Object)
* @see #contains(Object)
*/
public boolean retainAll(Collection<?> c) {
boolean modified = false;
! Iterator<E> e = iterator();
! while (e.hasNext()) {
! if (!c.contains(e.next())) {
! e.remove();
modified = true;
}
}
return modified;
}
--- 390,403 ----
* @see #remove(Object)
* @see #contains(Object)
*/
public boolean retainAll(Collection<?> c) {
boolean modified = false;
! Iterator<E> it = iterator();
! while (it.hasNext()) {
! if (!c.contains(it.next())) {
! it.remove();
modified = true;
}
}
return modified;
}
*** 419,432 ****
* <tt>remove</tt> method and this collection is non-empty.
*
* @throws UnsupportedOperationException {@inheritDoc}
*/
public void clear() {
! Iterator<E> e = iterator();
! while (e.hasNext()) {
! e.next();
! e.remove();
}
}
// String conversion
--- 416,429 ----
* <tt>remove</tt> method and this collection is non-empty.
*
* @throws UnsupportedOperationException {@inheritDoc}
*/
public void clear() {
! Iterator<E> it = iterator();
! while (it.hasNext()) {
! it.next();
! it.remove();
}
}
// String conversion
*** 440,460 ****
* by {@link String#valueOf(Object)}.
*
* @return a string representation of this collection
*/
public String toString() {
! Iterator<E> i = iterator();
! if (! i.hasNext())
return "[]";
StringBuilder sb = new StringBuilder();
sb.append('[');
for (;;) {
! E e = i.next();
sb.append(e == this ? "(this Collection)" : e);
! if (! i.hasNext())
return sb.append(']').toString();
! sb.append(", ");
}
}
}
--- 437,457 ----
* by {@link String#valueOf(Object)}.
*
* @return a string representation of this collection
*/
public String toString() {
! Iterator<E> it = iterator();
! if (! it.hasNext())
return "[]";
StringBuilder sb = new StringBuilder();
sb.append('[');
for (;;) {
! E e = it.next();
sb.append(e == this ? "(this Collection)" : e);
! if (! it.hasNext())
return sb.append(']').toString();
! sb.append(',').append(' ');
}
}
}