com.artima.lookup.util
Class ConsistentSet
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet
com.artima.lookup.util.ConsistentSet
- All Implemented Interfaces:
- Serializable, Iterable, Collection, Set
public class ConsistentSet
- extends AbstractSet
- implements Serializable
An implementation of the 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.
- Author:
- Bill Venners
- See Also:
- Serialized Form
Constructor Summary |
ConsistentSet()
Constructs a new, empty ConsistentSet . |
ConsistentSet(Collection init)
Constructs a new ConsistentSet containing the elements
in the passed collection. |
Method Summary |
Iterator |
iterator()
Returns an iterator over the elements in this set. |
int |
size()
Returns the number of elements in this ConsistentSet (its cardinality). |
Methods inherited from class java.util.AbstractCollection |
add, addAll, clear, contains, containsAll, isEmpty, remove, retainAll, toArray, toArray, toString |
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
elements
private Object[] elements
ConsistentSet
public ConsistentSet()
- Constructs a new, empty
ConsistentSet
. All instances
of ConsistentSet
are unmodifiable.
ConsistentSet
public ConsistentSet(Collection init)
- Constructs a new
ConsistentSet
containing the elements
in the passed collection. All instances of ConsistentSet
are unmodifiable.
- Parameters:
init
- the collection whose elements are to be placed into this set.
- Throws:
NullPointerException
- if the passed init
reference
is null
iterator
public Iterator iterator()
- Returns an
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
.
- Specified by:
iterator
in interface Iterable
- Specified by:
iterator
in interface Collection
- Specified by:
iterator
in interface Set
- Specified by:
iterator
in class AbstractCollection
- Returns:
- an
Iterator
over the elements in this
ConsistentSet
.
size
public int size()
- Returns the number of elements in this
ConsistentSet
(its cardinality).
- Specified by:
size
in interface Collection
- Specified by:
size
in interface Set
- Specified by:
size
in class AbstractCollection
- Returns:
- the number of elements in this
ConsistentSet
(its cardinality).
Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.