org.jjoost.collections.sets.base
Class AbstractHashSet<V,N extends HashNode<N> & Value<V>>

java.lang.Object
  extended by org.jjoost.collections.sets.base.AbstractSet<V>
      extended by org.jjoost.collections.sets.base.AbstractHashSet<V,N>
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<V>, AnyReadSet<V>, AnySet<V>, Function<V,java.lang.Boolean>
Direct Known Subclasses:
HashSet, InlineMultiHashSet

public abstract class AbstractHashSet<V,N extends HashNode<N> & Value<V>>
extends AbstractSet<V>
implements AnySet<V>

See Also:
Serialized Form

Nested Class Summary
static class AbstractHashSet.LockFreeHashSetNode<V>
           
static class AbstractHashSet.LockFreeHashSetNodeFactory<V>
           
static class AbstractHashSet.LockFreeLinkedHashSetNode<V>
           
static class AbstractHashSet.LockFreeLinkedHashSetNodeFactory<V>
           
static class AbstractHashSet.SerialHashSetNode<V>
           
static class AbstractHashSet.SerialHashSetNodeFactory<V>
           
static class AbstractHashSet.SerialLinkedHashSetNode<V>
           
static class AbstractHashSet.SerialLinkedHashSetNodeFactory<V>
           
 
Method Summary
 java.lang.Iterable<V> all(V val)
          Returns an Iterable of all values contained in the set which are equal to the parameter, as determined by the set's definition of equality.
 java.lang.Boolean apply(V v)
          Returns the result of applying the function to the parameter
 int capacity()
           
 int clear()
          Removes all values from the set and return the number of values removed.
 java.util.Iterator<V> clearAndReturn()
          Removes all values from the set and returns an Iterator over them.
 boolean contains(V value)
          Returns a boolean indicating if the parameter occurs in the set at least once.
 int count(V value)
          Returns an integer representing the number of occurrences of the value in the set
 Equality<? super V> equality()
          Returns an object that represents the definition of equality used by this set
 V first(V value)
          The first value stored in the set that is equal to the provided value, as determined by any provided Equality or Comparator.
 boolean isEmpty()
          Indicates if the set is empty
 java.util.Iterator<V> iterator()
           
 java.util.List<V> list(V val)
          Returns a List of all values contained in the set which are equal to the parameter, as determined by the set's definition of equality.
static
<V> AbstractHashSet.LockFreeLinkedHashSetNodeFactory<V>
lockFreeLinkedNodeFactory()
           
static
<V> AbstractHashSet.LockFreeHashSetNodeFactory<V>
lockFreeNodeFactory()
           
 int putAll(java.lang.Iterable<V> vals)
          Performs the equivalent of a put() operation for every value provided, returning an int representing the total number of values that did not displace existing values.
 V putIfAbsent(V val)
          Inserts the value and returns null if an equal value does not already occur in the set; otherwise returns the first such value encountered
 int remove(V val)
          Removes all occurrences of values equal to the parameter from the set, as determined by the set's definition of equality and returns the number of values that were removed from the set.
 int remove(V val, int atMost)
          Removes at most the prescribed number of values equal to the parameter from the set; which values are removed is implementation specific, and may be arbitrary.
 java.lang.Iterable<V> removeAndReturn(V val)
          Removes all occurrences of values equal to the parameter and returns an Iterable of the values removed.
 java.lang.Iterable<V> removeAndReturn(V val, int atMost)
          Removes at most the prescribed number of values equal to the parameter from the set and returns them to the user; which values are removed is implementation specific, and may be arbitrary.
 V removeAndReturnFirst(V value)
          Removes all occurrences of values equal to the parameter from the set, as determined by the set's definition of equality, and returns the first value encountered or null if none.
 V removeAndReturnFirst(V value, int atMost)
          Removes at most the prescribed number of values equal to the parameter from the set and returns the first one encountered to the user, or null if none; which values are removed is implementation specific, and may be arbitrary.
 void resize(int capacity)
           
static
<V> AbstractHashSet.SerialLinkedHashSetNodeFactory<V>
serialLinkedNodeFactory()
           
static
<V> AbstractHashSet.SerialHashSetNodeFactory<V>
serialNodeFactory()
           
 void shrink()
          This method attempts to minimise the resource utilisation of the set.
 int totalCount()
          Returns the total number of values (including duplicates) in the set
 
Methods inherited from class org.jjoost.collections.sets.base.AbstractSet
equals, equals
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jjoost.collections.AnySet
add, copy, put, unique
 
Methods inherited from interface org.jjoost.collections.AnyReadSet
permitsDuplicates, uniqueCount
 

Method Detail

capacity

public int capacity()

resize

public void resize(int capacity)

putIfAbsent

public V putIfAbsent(V val)
Description copied from interface: AnySet
Inserts the value and returns null if an equal value does not already occur in the set; otherwise returns the first such value encountered

Specified by:
putIfAbsent in interface AnySet<V>
Parameters:
val - value to insert
Returns:
existing value, or null if none

remove

public int remove(V val)
Description copied from interface: AnySet
Removes all occurrences of values equal to the parameter from the set, as determined by the set's definition of equality and returns the number of values that were removed from the set. Equivalent to remove(value, Integer.MAX_VALUE).

Specified by:
remove in interface AnySet<V>
Parameters:
val - remove equal to
Returns:
number removed

removeAndReturn

public java.lang.Iterable<V> removeAndReturn(V val)
Description copied from interface: AnySet
Removes all occurrences of values equal to the parameter and returns an Iterable of the values removed. Equivalent to removeAndReturn(value, Integer.MAX_VALUE).

Specified by:
removeAndReturn in interface AnySet<V>
Parameters:
val - remove equal to
Returns:
values removed

remove

public int remove(V val,
                  int atMost)
Description copied from interface: AnySet
Removes at most the prescribed number of values equal to the parameter from the set; which values are removed is implementation specific, and may be arbitrary. Returns the number of values actually removed as a result of the action.

Specified by:
remove in interface AnySet<V>
Parameters:
val - remove equal to
atMost - remove at most
Returns:
the number removed

removeAndReturn

public java.lang.Iterable<V> removeAndReturn(V val,
                                             int atMost)
Description copied from interface: AnySet
Removes at most the prescribed number of values equal to the parameter from the set and returns them to the user; which values are removed is implementation specific, and may be arbitrary.

Specified by:
removeAndReturn in interface AnySet<V>
Parameters:
val - the value
atMost - remove at most
Returns:
values removed

clearAndReturn

public java.util.Iterator<V> clearAndReturn()
Description copied from interface: AnySet
Removes all values from the set and returns an Iterator over them. This Iterator must be exactly equal to the set of values removed from the set by the action, however this set of values may not necessarily be determined, or the clear() completed, until the Iterator has been exhausted.

Specified by:
clearAndReturn in interface AnySet<V>
Returns:
values removed

putAll

public int putAll(java.lang.Iterable<V> vals)
Description copied from interface: AnySet
Performs the equivalent of a put() operation for every value provided, returning an int representing the total number of values that did not displace existing values. In a MultiSet this will always be equal to the number of values provided, however in a Set it may be fewer.

Specified by:
putAll in interface AnySet<V>
Parameters:
vals - values to insert
Returns:
number that did not displace existing values

removeAndReturnFirst

public V removeAndReturnFirst(V value)
Description copied from interface: AnySet
Removes all occurrences of values equal to the parameter from the set, as determined by the set's definition of equality, and returns the first value encountered or null if none. Equivalent to removeAndReturnFirst(value, Integer.MAX_VALUE).

Specified by:
removeAndReturnFirst in interface AnySet<V>
Parameters:
value - remove
Returns:
first value removed

removeAndReturnFirst

public V removeAndReturnFirst(V value,
                              int atMost)
Description copied from interface: AnySet
Removes at most the prescribed number of values equal to the parameter from the set and returns the first one encountered to the user, or null if none; which values are removed is implementation specific, and may be arbitrary.

Specified by:
removeAndReturnFirst in interface AnySet<V>
Parameters:
value - remove
atMost - remove at most
Returns:
first value removed

contains

public boolean contains(V value)
Description copied from interface: AnyReadSet
Returns a boolean indicating if the parameter occurs in the set at least once.

Specified by:
contains in interface AnyReadSet<V>
Parameters:
value - value to look for
Returns:
true, if present

count

public int count(V value)
Description copied from interface: AnyReadSet
Returns an integer representing the number of occurrences of the value in the set

Specified by:
count in interface AnyReadSet<V>
Parameters:
value - value to look for
Returns:
number of occurrences

shrink

public void shrink()
Description copied from interface: AnySet
This method attempts to minimise the resource utilisation of the set. It may be a no-op.

Specified by:
shrink in interface AnySet<V>

first

public V first(V value)
Description copied from interface: AnyReadSet
The first value stored in the set that is equal to the provided value, as determined by any provided Equality or Comparator. Returns null if no matching item is stored in the set.

Specified by:
first in interface AnyReadSet<V>
Parameters:
value - value to look for
Returns:
first matching value

list

public java.util.List<V> list(V val)
Description copied from interface: AnyReadSet
Returns a List of all values contained in the set which are equal to the parameter, as determined by the set's definition of equality. This list should be constructed "eagerly" and should be a consistent snapshot of the values valid at some point between the method being called and it returning.

Specified by:
list in interface AnyReadSet<V>
Parameters:
val - value to look for
Returns:
matching values

totalCount

public int totalCount()
Description copied from interface: AnyReadSet
Returns the total number of values (including duplicates) in the set

Specified by:
totalCount in interface AnyReadSet<V>
Returns:
total number of values in the set

isEmpty

public boolean isEmpty()
Description copied from interface: AnyReadSet
Indicates if the set is empty

Specified by:
isEmpty in interface AnyReadSet<V>
Returns:
true, if is empty

all

public java.lang.Iterable<V> all(V val)
Description copied from interface: AnyReadSet
Returns an Iterable of all values contained in the set which are equal to the parameter, as determined by the set's definition of equality.

Changes to the set that happen prior to retrieving an Iterator from the Iterable should be reflected in the resulting Iterator. Changes to the set once an Iterator has been obtained may or may not be reflected in the Iterator at the discretion of the implementing class.

In a concurrent set it is acceptable for values to occur extra times if they are deleted and re-inserted in between method calls on the Iterator.

Specified by:
all in interface AnyReadSet<V>
Parameters:
val - value to look for
Returns:
matching values

clear

public int clear()
Description copied from interface: AnySet
Removes all values from the set and return the number of values removed. In a concurrent set this number should be a atomically determined; i.e. even if the set is no longer clear by the time this method returns, the number of values it reports to have removed should be the actual number removed.

Specified by:
clear in interface AnySet<V>
Returns:
number removed

iterator

public java.util.Iterator<V> iterator()
Specified by:
iterator in interface java.lang.Iterable<V>

apply

public java.lang.Boolean apply(V v)
Description copied from interface: Function
Returns the result of applying the function to the parameter

Specified by:
apply in interface Function<V,java.lang.Boolean>
Parameters:
v - something of type domain
Returns:
the result of the function (something of type range)

equality

public Equality<? super V> equality()
Description copied from interface: AnyReadSet
Returns an object that represents the definition of equality used by this set

Specified by:
equality in interface AnyReadSet<V>
Returns:
an object representing the equality used by this set

serialNodeFactory

public static <V> AbstractHashSet.SerialHashSetNodeFactory<V> serialNodeFactory()

serialLinkedNodeFactory

public static <V> AbstractHashSet.SerialLinkedHashSetNodeFactory<V> serialLinkedNodeFactory()

lockFreeNodeFactory

public static <V> AbstractHashSet.LockFreeHashSetNodeFactory<V> lockFreeNodeFactory()

lockFreeLinkedNodeFactory

public static <V> AbstractHashSet.LockFreeLinkedHashSetNodeFactory<V> lockFreeLinkedNodeFactory()