Top Description Fields Constructors Methods
org.apache.commons.collections4.set

public Class PredicatedSet<E>

extends PredicatedCollection<E>
implements Set<E>
Class Inheritance
All Implemented Interfaces
java.util.Set, java.util.Collection, java.lang.Iterable
Known Direct Subclasses
org.apache.commons.collections4.set.PredicatedSortedSet
Type Parameters
<E>
the type of the elements in this set
Imports
java.util.Set, org.apache.commons.collections4.Predicate, org.apache.commons.collections4.collection.PredicatedCollection

Decorates another Set to validate that all additions match a specified predicate.

This set exists to provide validation for the decorated set. It is normally created to decorate an empty set. If an object cannot be added to the set, an IllegalArgumentException is thrown.

One usage would be to ensure that no null entries are added to the set.

Set set = PredicatedSet.decorate(new HashSet(), NotNullPredicate.INSTANCE);

This class is Serializable from Commons Collections 3.1.

Since
3.0

Field Summary

Modifier and TypeField and Description
private static final long
Inherited from org.apache.commons.collections4.collection.PredicatedCollection:
predicate

Constructor Summary

AccessConstructor and Description
protected
PredicatedSet(final Set<E>
the set to decorate, must not be null
set
,
final Predicate<? super E>
the predicate to use for validation, must not be null
predicate
)

Constructor that wraps (not copies).

Method Summary

Modifier and TypeMethod and Description
protected Set<E>

Returns:

the decorated set
decorated
()

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.decorated.

Gets the set being decorated.
public boolean
equals(final Object
object to be compared for equality with this set
object
)

Overrides java.lang.Object.equals.

Implements java.util.Set.equals, java.util.Collection.equals.

Compares the specified object with this set for equality.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Set.hashCode, java.util.Collection.hashCode.

Returns the hash code value for this set.
public static <
the element type
E
>
PredicatedSet<E>

Returns:

a decorated set
predicatedSet
(final Set<E>
the set to decorate, must not be null
set
,
final Predicate<? super E>
the predicate to use for validation, must not be null
predicate
)

Factory method to create a predicated (validating) set.

Inherited from org.apache.commons.collections4.collection.PredicatedCollection:
addaddAllbuildernotNullBuilderpredicatedCollectionvalidate

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.commons.collections4.collection.PredicatedCollection.serialVersionUID.

Serialization version

Constructor Detail

PredicatedSetback to summary
protected PredicatedSet(final Set<E> set, final Predicate<? super E> predicate)

Constructor that wraps (not copies).

If there are any elements already in the set being decorated, they are validated.

Parameters
set:Set<E>

the set to decorate, must not be null

predicate:Predicate<? super E>

the predicate to use for validation, must not be null

Exceptions
NullPointerException:
if set or predicate is null
IllegalArgumentException:
if the set contains invalid elements

Method Detail

decoratedback to summary
protected Set<E> decorated()

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.decorated.

Gets the set being decorated.

Returns:Set<E>

the decorated set

Annotations
@Override
equalsback to summary
public boolean equals(final Object object)

Overrides java.lang.Object.equals.

Implements java.util.Set.equals, java.util.Collection.equals.

Doc from java.util.Set.equals.

Compares the specified object with this set for equality. Returns true if the specified object is also a set, the two sets have the same size, and every member of the specified set is contained in this set (or equivalently, every member of this set is contained in the specified set). This definition ensures that the equals method works properly across different implementations of the set interface.

Parameters
object:Object

object to be compared for equality with this set

Returns:boolean

true if the specified object is equal to this set

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Set.hashCode, java.util.Collection.hashCode.

Doc from java.util.Set.hashCode.

Returns the hash code value for this set. The hash code of a set is defined to be the sum of the hash codes of the elements in the set, where the hash code of a null element is defined to be zero. This ensures that s1.equals(s2) implies that s1.hashCode()==s2.hashCode() for any two sets s1 and s2, as required by the general contract of Object#hashCode.

Returns:int

the hash code value for this set

Annotations
@Override
predicatedSetback to summary
public static <E> PredicatedSet<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate)

Factory method to create a predicated (validating) set.

If there are any elements already in the set being decorated, they are validated.

Parameters
<E>
the element type
set:Set<E>

the set to decorate, must not be null

predicate:Predicate<? super E>

the predicate to use for validation, must not be null

Returns:PredicatedSet<E>

a decorated set

Exceptions
NullPointerException:
if set or predicate is null
IllegalArgumentException:
if the set contains invalid elements
Since
4.0