com.devexperts.util
Class AbstractConcurrentSet<E>

java.lang.Object
  extended by com.devexperts.util.AbstractConcurrentSet<E>
All Implemented Interfaces:
Iterable<E>, Collection<E>, Set<E>
Direct Known Subclasses:
IndexedSet

public abstract class AbstractConcurrentSet<E>
extends Object
implements Set<E>

Provides a skeletal implementation of the Set interface to minimize the effort required to implement this interface. Unlike AbstractSet skeletal implementation, this one is more forgiving to concurrent modifications of this set during implemented bulk operations.


Constructor Summary
protected AbstractConcurrentSet()
          Sole constructor; for invocation by subclass constructors, typically implicit.
 
Method Summary
 boolean addAll(Collection<? extends E> c)
          Adds all of the elements in the specified collection into this set and returns true if this operation has increased the size of this set.
 void clear()
          Removes all of the elements from this set.
 boolean containsAll(Collection<?> c)
          Tests if this set contains all of the elements in the specified collection.
 boolean equals(Object o)
          Compares the specified object with this set for equality.
 int hashCode()
          Returns the hash code value for this set.
 boolean isEmpty()
          Tests if this set has no elements.
 boolean removeAll(Collection<?> c)
          Removes all of the elements in the specified collection from this set and returns true if this operation has decreased the size of this set.
 boolean retainAll(Collection<?> c)
          Retains only the elements in this set that are contained in the specified collection.
 Object[] toArray()
          Returns an array containing all of the elements in this set.
<T> T[]
toArray(T[] a)
          Returns an array containing all of the elements in this set whose runtime type is that of the specified array.
 String toString()
          Returns a string representation of this set.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
add, contains, iterator, remove, size
 

Constructor Detail

AbstractConcurrentSet

protected AbstractConcurrentSet()
Sole constructor; for invocation by subclass constructors, typically implicit.

Method Detail

clear

public void clear()
Removes all of the elements from this set.

This implementation iterates all elements of this set and removes them using Iterator.remove() method.

Specified by:
clear in interface Collection<E>
Specified by:
clear in interface Set<E>

isEmpty

public boolean isEmpty()
Tests if this set has no elements.

This implementation checks emptiness using Set.size() method.

Specified by:
isEmpty in interface Collection<E>
Specified by:
isEmpty in interface Set<E>

toArray

public Object[] toArray()
Returns an array containing all of the elements in this set. Obeys the general contract of the Collection.toArray() method.

This implementation iterates all elements of this set and adds them into the array.

Specified by:
toArray in interface Collection<E>
Specified by:
toArray in interface Set<E>

toArray

public <T> T[] toArray(T[] a)
Returns an array containing all of the elements in this set whose runtime type is that of the specified array. Obeys the general contract of the Collection.toArray(Object[]) method.

This implementation iterates all elements of this set and adds them into the array.

Specified by:
toArray in interface Collection<E>
Specified by:
toArray in interface Set<E>

containsAll

public boolean containsAll(Collection<?> c)
Tests if this set contains all of the elements in the specified collection.

This implementation iterates all elements of specified collection and tests them one-by-one using contains(element) method.

Specified by:
containsAll in interface Collection<E>
Specified by:
containsAll in interface Set<E>

addAll

public boolean addAll(Collection<? extends E> c)
Adds all of the elements in the specified collection into this set and returns true if this operation has increased the size of this set.

This implementation iterates all elements of specified collection and adds them one-by-one using add(element) method.

Specified by:
addAll in interface Collection<E>
Specified by:
addAll in interface Set<E>

removeAll

public boolean removeAll(Collection<?> c)
Removes all of the elements in the specified collection from this set and returns true if this operation has decreased the size of this set.

This implementation compares size of specified collection with the size of this set, then iterates smaller collection and removes elements that need to be removed.

Specified by:
removeAll in interface Collection<E>
Specified by:
removeAll in interface Set<E>

retainAll

public boolean retainAll(Collection<?> c)
Retains only the elements in this set that are contained in the specified collection.

This implementation iterates all elements of this set, checks if they are contained in the specified collection, and removes them if needed using Iterator.remove() method.

Specified by:
retainAll in interface Collection<E>
Specified by:
retainAll in interface Set<E>

equals

public boolean equals(Object o)
Compares the specified object with this set for equality. Obeys the general contract of the Set.equals(Object) method.

This implementation compares size of specified set with the size of this set and then checks element containment using containsAll((Set)o) method.

Specified by:
equals in interface Collection<E>
Specified by:
equals in interface Set<E>
Overrides:
equals in class Object

hashCode

public int hashCode()
Returns the hash code value for this set. Obeys the general contract of the Set.hashCode() method.

This implementation iterates all elements of this set and adds their hash codes.

Specified by:
hashCode in interface Collection<E>
Specified by:
hashCode in interface Set<E>
Overrides:
hashCode in class Object

toString

public String toString()
Returns a string representation of this set.

This implementation iterates all elements of this set and concatenates their string representations.

Overrides:
toString in class Object


Copyright © 2013 Devexperts. All Rights Reserved.