public interface Collection4D<E>
extends java.lang.Iterable<E>
All methods of this interface that are defined to modify the collection are defined as optional. An optional operation may throw an UnsupportedOperationException if the data backing this collection does not support such a modification. This may mean that the data structure is immutable, or that it is read-only but may change ("unmodifiable"), or that it is modifiable but of fixed size (such as an array), or any number of other combinations.
A class that wishes to implement this interface should consider subclassing AbstractCollection, which provides basic implementations of most of the methods of this interface. Classes that are prepared to make guarantees about ordering or about absence of duplicate elements should consider implementing List or Set respectively, both of which are subinterfaces of Collection.
A general-purpose implementation of the Collection interface should in most cases provide at least two constructors: One which takes no arguments and creates an empty collection, and one which takes a Collection as an argument and returns a collection containing the same elements (that is, creates a copy of the argument using its own implementation).
List
,
Set
,
Map
,
SortedSet
,
SortedMap
,
HashSet
,
TreeSet
,
ArrayList
,
LinkedList
,
Vector
,
Collections
,
Arrays
,
AbstractCollection
Modifier and Type | Method and Description |
---|---|
boolean |
add(E o)
Add an element to this collection.
|
boolean |
addAll(Collection4D<? extends E> c)
Add the contents of a given collection to this collection.
|
void |
clear()
Clear the collection, such that a subsequent call to isEmpty() would
return true.
|
boolean |
contains(java.lang.Object o)
Test whether this collection contains a given object as one of its
elements.
|
boolean |
containsAll(Collection4D<?> c)
Test whether this collection contains every element in a given collection.
|
boolean |
equals(java.lang.Object o)
Test whether this collection is equal to some object.
|
int |
hashCode()
Obtain a hash code for this collection.
|
boolean |
isEmpty()
Test whether this collection is empty, that is, if size() == 0.
|
java.util.Iterator<E> |
iterator()
Obtain an Iterator over this collection.
|
boolean |
remove(java.lang.Object o)
Remove a single occurrence of an object from this collection.
|
boolean |
removeAll(Collection4D<?> c)
Remove all elements of a given collection from this collection.
|
boolean |
retainAll(Collection4D<?> c)
Remove all elements of this collection that are not contained in a given
collection.
|
int |
size()
Get the number of elements in this collection.
|
java.lang.Object[] |
toArray()
Copy the current contents of this collection into an array.
|
<T> T[] |
toArray(T[] a)
Copy the current contents of this collection into an array.
|
boolean add(E o)
o
- the object to add.java.lang.UnsupportedOperationException
- if this collection does not
support the add operation.java.lang.ClassCastException
- if o cannot be added to this collection due
to its type.java.lang.NullPointerException
- if o is null and this collection doesn't
support the addition of null values.java.lang.IllegalArgumentException
- if o cannot be added to this
collection for some other reason.boolean addAll(Collection4D<? extends E> c)
c
- the collection to add.java.lang.UnsupportedOperationException
- if this collection does not
support the addAll operation.java.lang.ClassCastException
- if some element of c cannot be added to this
collection due to its type.java.lang.NullPointerException
- if some element of c is null and this
collection does not support the addition of null values.java.lang.NullPointerException
- if c itself is null.java.lang.IllegalArgumentException
- if some element of c cannot be added
to this collection for some other reason.void clear()
java.lang.UnsupportedOperationException
- if this collection does not
support the clear operation.boolean contains(java.lang.Object o)
o
- the element to look for.o == null ? e == null : o.equals(e)
.java.lang.ClassCastException
- if the type of o is not a valid type for this
collection.java.lang.NullPointerException
- if o is null and this collection doesn't
support null values.boolean containsAll(Collection4D<?> c)
c
- the collection to test for.java.lang.ClassCastException
- if the type of any element in c is not a valid
type for this collection.java.lang.NullPointerException
- if some element of c is null and this
collection does not support null values.java.lang.NullPointerException
- if c itself is null.boolean equals(java.lang.Object o)
If an implementation of Collection, which is not also an implementation of Set or List, should choose to implement this method, it should take care to obey the contract of the equals method of Object. In particular, care should be taken to return false when o is a Set or a List, in order to preserve the symmetry of the relation.
equals
in class java.lang.Object
o
- the object to compare to this collection.int hashCode()
If an implementation of Collection, which is not also an implementation of Set or List, should choose to implement this method, it should take care to obey the contract of the hashCode method of Object. Note that this method renders it impossible to correctly implement both Set and List, as the required implementations are mutually exclusive.
hashCode
in class java.lang.Object
boolean isEmpty()
java.util.Iterator<E> iterator()
iterator
in interface java.lang.Iterable<E>
boolean remove(java.lang.Object o)
o == null ? e == null
: o.equals(e)
.o
- the object to remove.java.lang.UnsupportedOperationException
- if this collection does not
support the remove operation.java.lang.ClassCastException
- if the type of o is not a valid type
for this collection.java.lang.NullPointerException
- if o is null and the collection doesn't
support null values.boolean removeAll(Collection4D<?> c)
c
- The collection of objects to be removed.java.lang.UnsupportedOperationException
- if this collection does not
support the removeAll operation.java.lang.ClassCastException
- if the type of any element in c is not a valid
type for this collection.java.lang.NullPointerException
- if some element of c is null and this
collection does not support removing null values.java.lang.NullPointerException
- if c itself is null.boolean retainAll(Collection4D<?> c)
c
- The collection of objects to be retained.java.lang.UnsupportedOperationException
- if this collection does not
support the retainAll operation.java.lang.ClassCastException
- if the type of any element in c is not a valid
type for this collection.java.lang.NullPointerException
- if some element of c is null and this
collection does not support retaining null values.java.lang.NullPointerException
- if c itself is null.int size()
java.lang.Object[] toArray()
<T> T[] toArray(T[] a)
a
- the array to copy this collection into.java.lang.ArrayStoreException
- if the type of any element of the
collection is not a subtype of the element type of a.