public abstract class AbstractCollection4D<E>
extends java.lang.Object
implements java.util.Collection<E>, java.lang.Iterable<E>
The programmer should provide a no-argument constructor, and one that accepts another Collection, as recommended by the Collection interface. Unfortunately, there is no way to enforce this in Java.
Collection
,
AbstractSet
,
AbstractList
Modifier | Constructor and Description |
---|---|
protected |
AbstractCollection4D()
The main constructor, for use by subclasses.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E o)
Add an object to the collection (optional operation).
|
boolean |
addAll(java.util.Collection<? extends E> c)
Add all the elements of a given collection to this collection (optional
operation).
|
void |
clear()
Remove all elements from the collection (optional operation).
|
boolean |
contains(java.lang.Object o)
Test whether this collection contains a given object.
|
boolean |
containsAll(java.util.Collection<?> c)
Tests whether this collection contains all the elements in a given
collection.
|
boolean |
isEmpty()
Test whether this collection is empty.
|
abstract java.util.Iterator<E> |
iterator()
Return an Iterator over this collection.
|
boolean |
remove(java.lang.Object o)
Remove a single instance of an object from this collection (optional
operation).
|
boolean |
removeAll(java.util.Collection<?> c)
Remove from this collection all its elements that are contained in a given
collection (optional operation).
|
boolean |
retainAll(java.util.Collection<?> c)
Remove from this collection all its elements that are not contained in a
given collection (optional operation).
|
abstract int |
size()
Return the number of elements in this collection.
|
java.lang.Object[] |
toArray()
Return an array containing the elements of this collection.
|
<T> T[] |
toArray(T[] a)
Copy the collection into a given array if it will fit, or into a
dynamically created array of the same run-time type as the given array if
not.
|
java.lang.String |
toString()
Creates a String representation of the Collection.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
protected AbstractCollection4D()
public abstract java.util.Iterator<E> iterator()
public abstract int size()
size
in interface java.util.Collection<E>
public boolean add(E o)
add
in interface java.util.Collection<E>
o
- the object to addjava.lang.UnsupportedOperationException
- if the add operation is not
supported on this collectionjava.lang.NullPointerException
- if the collection does not support nulljava.lang.ClassCastException
- if the object is of the wrong typejava.lang.IllegalArgumentException
- if some aspect of the object prevents
it from being addedpublic boolean addAll(java.util.Collection<? extends E> c)
addAll
in interface java.util.Collection<E>
c
- the collection to add the elements of to this collectionjava.lang.UnsupportedOperationException
- if the add operation is not
supported on this collectionjava.lang.NullPointerException
- if the specified collection is nulljava.lang.ClassCastException
- if the type of any element in c is
not a valid type for addition.java.lang.IllegalArgumentException
- if some aspect of any element
in c prevents it being added.java.lang.NullPointerException
- if any element in c is null and this
collection doesn't allow null values.add(Object)
public void clear()
clear
in interface java.util.Collection<E>
java.lang.UnsupportedOperationException
- if the Iterator returned by
iterator does not provide an implementation of removeIterator.remove()
public boolean contains(java.lang.Object o)
contains
in interface java.util.Collection<E>
o
- the object to remove from this collectionpublic boolean containsAll(java.util.Collection<?> c)
containsAll
in interface java.util.Collection<E>
c
- the collection to test againstjava.lang.NullPointerException
- if the given collection is nullcontains(Object)
public boolean isEmpty()
public boolean remove(java.lang.Object o)
(o == null ? e == null : o.equals(e))
, if such an element
exists. This implementation obtains an iterator over the collection
and iterates over it, testing each element for equality with the given
object. If it is equal, it is removed by the iterator's remove method
(thus this method will fail with an UnsupportedOperationException if
the Iterator's remove method does). After the first element has been
removed, true is returned; if the end of the collection is reached, false
is returned.remove
in interface java.util.Collection<E>
o
- the object to remove from this collectionjava.lang.UnsupportedOperationException
- if this collection's Iterator
does not support the remove methodIterator.remove()
public boolean removeAll(java.util.Collection<?> c)
removeAll
in interface java.util.Collection<E>
c
- the collection to remove the elements ofjava.lang.UnsupportedOperationException
- if this collection's Iterator
does not support the remove methodjava.lang.NullPointerException
- if the collection, c, is null.Iterator.remove()
public boolean retainAll(java.util.Collection<?> c)
retainAll
in interface java.util.Collection<E>
c
- the collection to retain the elements ofjava.lang.UnsupportedOperationException
- if this collection's Iterator
does not support the remove methodjava.lang.NullPointerException
- if the collection, c, is null.Iterator.remove()
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection<E>
public <T> T[] toArray(T[] a)
toArray
in interface java.util.Collection<E>
a
- the array to copy into, or of the correct run-time typejava.lang.NullPointerException
- if the given array is nulljava.lang.ArrayStoreException
- if the type of the array precludes holding
one of the elements of the Collectionpublic java.lang.String toString()
toString
in class java.lang.Object