public class ConsistentSet extends AbstractSet implements Serializable
java.util.Set
interface that has
a serialized form consistent in all virtual machines. ConsistentSet
instances are unmodifiable. All mutator methods, such as add
and
remove
, throw UnsupportedOperationException
.
This class permits the null
element.
Although instances of this class are unmodifiable, they are not necessarily
immutable. If a client retrieves a mutable object contained in a
ConsistentSet
and mutates that object, the client in effect
mutates the state of the ConsistentSet
. In this case, the
serialized form of the ConsistentSet
will also most likely
have been mutated. A ConsistentSet
that contains only immutable
objects will maintain a consistent serialized form indefinitely. But a
ConsistentSet
that contains mutable objects will maintain a
consistent serialized form only so long as the mutable objects are not
mutated.
Modifier and Type | Field and Description |
---|---|
private Object[] |
elements |
private static long |
serialVersionUID |
Constructor and Description |
---|
ConsistentSet()
Constructs a new, empty
ConsistentSet . |
ConsistentSet(Collection init)
Constructs a new
ConsistentSet containing the elements
in the passed collection. |
Modifier and Type | Method and Description |
---|---|
Iterator |
iterator()
Returns an
iterator over the elements in this set. |
int |
size()
Returns the number of elements in this
ConsistentSet (its cardinality). |
equals, hashCode, removeAll
add, addAll, clear, contains, containsAll, isEmpty, remove, retainAll, toArray, toArray, toString
private static final long serialVersionUID
private Object[] elements
public ConsistentSet()
ConsistentSet
. All instances
of ConsistentSet
are unmodifiable.public ConsistentSet(Collection init)
ConsistentSet
containing the elements
in the passed collection. All instances of ConsistentSet
are unmodifiable.init
- the collection whose elements are to be placed into this set.NullPointerException
- if the passed init
reference
is null
public Iterator iterator()
iterator
over the elements in this set. The elements
are returned in no particular order. Because all instances of
ConsistentSet
are unmodifiable, the remove
method
of the returned Iterator
throws
UnsupportedOperationException
.iterator
in interface Iterable
iterator
in interface Collection
iterator
in interface Set
iterator
in class AbstractCollection
Iterator
over the elements in this
ConsistentSet
.public int size()
ConsistentSet
(its cardinality).size
in interface Collection
size
in interface Set
size
in class AbstractCollection
ConsistentSet
(its cardinality).Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.