Methods Summary |
---|
public boolean | add(E object)
throw new UnsupportedOperationException();
|
public boolean | addAll(java.util.Collection collection)Attempts to add all of the objects contained in {@code collection}
to the contents of this {@code Collection} (optional). This implementation
iterates over the given {@code Collection} and calls {@code add} for each
element. If any of these calls return {@code true}, then {@code true} is
returned as result of this method call, {@code false} otherwise. If this
{@code Collection} does not support adding elements, an {@code
UnsupportedOperationException} is thrown.
If the passed {@code Collection} is changed during the process of adding elements
to this {@code Collection}, the behavior depends on the behavior of the passed
{@code Collection}.
boolean result = false;
Iterator<? extends E> it = collection.iterator();
while (it.hasNext()) {
if (add(it.next())) {
result = true;
}
}
return result;
|
public void | clear()Removes all elements from this {@code Collection}, leaving it empty (optional).
This implementation iterates over this {@code Collection} and calls the {@code
remove} method on each element. If the iterator does not support removal
of elements, an {@code UnsupportedOperationException} is thrown.
Concrete implementations usually can clear a {@code Collection} more efficiently
and should therefore overwrite this method.
Iterator<E> it = iterator();
while (it.hasNext()) {
it.next();
it.remove();
}
|
public boolean | contains(java.lang.Object object)Tests whether this {@code Collection} contains the specified object. This
implementation iterates over this {@code Collection} and tests, whether any
element is equal to the given object. If {@code object != null} then
{@code object.equals(e)} is called for each element {@code e} returned by
the iterator until the element is found. If {@code object == null} then
each element {@code e} returned by the iterator is compared with the test
{@code e == null}.
Iterator<E> it = iterator();
if (object != null) {
while (it.hasNext()) {
if (object.equals(it.next())) {
return true;
}
}
} else {
while (it.hasNext()) {
if (it.next() == null) {
return true;
}
}
}
return false;
|
public boolean | containsAll(java.util.Collection collection)Tests whether this {@code Collection} contains all objects contained in the
specified {@code Collection}. This implementation iterates over the specified
{@code Collection}. If one element returned by the iterator is not contained in
this {@code Collection}, then {@code false} is returned; {@code true} otherwise.
Iterator<?> it = collection.iterator();
while (it.hasNext()) {
if (!contains(it.next())) {
return false;
}
}
return true;
|
public boolean | isEmpty()Returns if this {@code Collection} contains no elements. This implementation
tests, whether {@code size} returns 0.
return size() == 0;
|
public abstract java.util.Iterator | iterator()Returns an instance of {@link Iterator} that may be used to access the
objects contained by this {@code Collection}. The order in which the elements are
returned by the {@link Iterator} is not defined unless the instance of the
{@code Collection} has a defined order. In that case, the elements are returned in that order.
In this class this method is declared abstract and has to be implemented
by concrete {@code Collection} implementations.
|
public boolean | remove(java.lang.Object object)Removes one instance of the specified object from this {@code Collection} if one
is contained (optional). This implementation iterates over this
{@code Collection} and tests for each element {@code e} returned by the iterator,
whether {@code e} is equal to the given object. If {@code object != null}
then this test is performed using {@code object.equals(e)}, otherwise
using {@code object == null}. If an element equal to the given object is
found, then the {@code remove} method is called on the iterator and
{@code true} is returned, {@code false} otherwise. If the iterator does
not support removing elements, an {@code UnsupportedOperationException}
is thrown.
Iterator<?> it = iterator();
if (object != null) {
while (it.hasNext()) {
if (object.equals(it.next())) {
it.remove();
return true;
}
}
} else {
while (it.hasNext()) {
if (it.next() == null) {
it.remove();
return true;
}
}
}
return false;
|
public boolean | removeAll(java.util.Collection collection)Removes all occurrences in this {@code Collection} of each object in the
specified {@code Collection} (optional). After this method returns none of the
elements in the passed {@code Collection} can be found in this {@code Collection}
anymore.
This implementation iterates over this {@code Collection} and tests for each
element {@code e} returned by the iterator, whether it is contained in
the specified {@code Collection}. If this test is positive, then the {@code
remove} method is called on the iterator. If the iterator does not
support removing elements, an {@code UnsupportedOperationException} is
thrown.
boolean result = false;
Iterator<?> it = iterator();
while (it.hasNext()) {
if (collection.contains(it.next())) {
it.remove();
result = true;
}
}
return result;
|
public boolean | retainAll(java.util.Collection collection)Removes all objects from this {@code Collection} that are not also found in the
{@code Collection} passed (optional). After this method returns this {@code Collection}
will only contain elements that also can be found in the {@code Collection}
passed to this method.
This implementation iterates over this {@code Collection} and tests for each
element {@code e} returned by the iterator, whether it is contained in
the specified {@code Collection}. If this test is negative, then the {@code
remove} method is called on the iterator. If the iterator does not
support removing elements, an {@code UnsupportedOperationException} is
thrown.
boolean result = false;
Iterator<?> it = iterator();
while (it.hasNext()) {
if (!collection.contains(it.next())) {
it.remove();
result = true;
}
}
return result;
|
public abstract int | size()Returns a count of how many objects this {@code Collection} contains.
In this class this method is declared abstract and has to be implemented
by concrete {@code Collection} implementations.
|
public java.lang.Object[] | toArray()
int size = size(), index = 0;
Iterator<?> it = iterator();
Object[] array = new Object[size];
while (index < size) {
array[index++] = it.next();
}
return array;
|
public T[] | toArray(T[] contents)
int size = size(), index = 0;
if (size > contents.length) {
Class<?> ct = contents.getClass().getComponentType();
contents = (T[])Array.newInstance(ct, size);
}
for (E entry: this) {
contents[index++] = (T)entry;
}
if (index < contents.length) {
contents[index] = null;
}
return contents;
|
public java.lang.String | toString()Returns the string representation of this {@code Collection}. The presentation
has a specific format. It is enclosed by square brackets ("[]"). Elements
are separated by ', ' (comma and space).
if (isEmpty()) {
return "[]"; //$NON-NLS-1$
}
StringBuilder buffer = new StringBuilder(size() * 16);
buffer.append('[");
Iterator<?> it = iterator();
while (it.hasNext()) {
Object next = it.next();
if (next != this) {
buffer.append(next);
} else {
buffer.append("(this Collection)"); //$NON-NLS-1$
}
if(it.hasNext()) {
buffer.append(", "); //$NON-NLS-1$
}
}
buffer.append(']");
return buffer.toString();
|