org.jjoost.collections.sets.base
Class HashSet<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>
          extended by org.jjoost.collections.sets.base.HashSet<V,N>
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<V>, AnyReadSet<V>, AnySet<V>, Set<V>, Function<V,java.lang.Boolean>
Direct Known Subclasses:
LockFreeHashSet, LockFreeLinkedScalarHashSet, SerialHashSet, SerialLinkedHashSet

public class HashSet<V,N extends HashNode<N> & Value<V>>
extends AbstractHashSet<V,N>
implements Set<V>

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jjoost.collections.sets.base.AbstractHashSet
AbstractHashSet.LockFreeHashSetNode<V>, AbstractHashSet.LockFreeHashSetNodeFactory<V>, AbstractHashSet.LockFreeLinkedHashSetNode<V>, AbstractHashSet.LockFreeLinkedHashSetNodeFactory<V>, AbstractHashSet.SerialHashSetNode<V>, AbstractHashSet.SerialHashSetNodeFactory<V>, AbstractHashSet.SerialLinkedHashSetNode<V>, AbstractHashSet.SerialLinkedHashSetNodeFactory<V>
 
Constructor Summary
HashSet(Rehasher rehasher, Equality<? super V> equality, HashNodeFactory<V,N> nodeFactory, HashStore<N> table)
           
 
Method Summary
 boolean add(V val)
          Attempt to add the value to the set, returning false if the value could not be added, and true if it was.
 HashSet<V,N> copy()
          Returns a copy of the set.
 V get(V key)
          Returns the value stored in the set that is equal to the provided value, as determined by any provided Equality or Comparator.
 boolean permitsDuplicates()
          Indicates if the set permits a value to occur more than once
 V put(V val)
          Insert the parameter into the set, removing and returning any value equal to the parameter that was already present, as determined by the set's definition of equality.
 int size()
          A convenience method returning the size of the set; this is equivalent to totalCount() or uniqueCount()
 java.lang.String toString()
           
 Set<V> unique()
          Returns this
 int uniqueCount()
          Returns the number of unique values in the set
 
Methods inherited from class org.jjoost.collections.sets.base.AbstractHashSet
all, apply, capacity, clear, clearAndReturn, contains, count, equality, first, isEmpty, iterator, list, lockFreeLinkedNodeFactory, lockFreeNodeFactory, putAll, putIfAbsent, remove, remove, removeAndReturn, removeAndReturn, removeAndReturnFirst, removeAndReturnFirst, resize, serialLinkedNodeFactory, serialNodeFactory, shrink, totalCount
 
Methods inherited from class org.jjoost.collections.sets.base.AbstractSet
equals, equals
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jjoost.collections.AnySet
clear, clearAndReturn, putAll, putIfAbsent, remove, remove, removeAndReturn, removeAndReturn, removeAndReturnFirst, removeAndReturnFirst, shrink
 
Methods inherited from interface org.jjoost.collections.AnyReadSet
all, contains, count, equality, first, isEmpty, list, totalCount
 
Methods inherited from interface java.lang.Iterable
iterator
 
Methods inherited from interface org.jjoost.util.Function
apply
 

Constructor Detail

HashSet

public HashSet(Rehasher rehasher,
               Equality<? super V> equality,
               HashNodeFactory<V,N> nodeFactory,
               HashStore<N> table)
Method Detail

add

public boolean add(V val)
Description copied from interface: AnySet
Attempt to add the value to the set, returning false if the value could not be added, and true if it was. In a MultiSet the return value will always be true, however in a Set it will be false if a value equal to the one provided (as determined by the set's definition of equality) was already present. For values inequal to null, this is equivalent to put(value) == null

Specified by:
add in interface AnySet<V>
Parameters:
val - value to insert
Returns:
true if the set was modified, false otherwise

put

public V put(V val)
Description copied from interface: Set
Insert the parameter into the set, removing and returning any value equal to the parameter that was already present, as determined by the set's definition of equality.

Specified by:
put in interface AnySet<V>
Specified by:
put in interface Set<V>
Parameters:
val - value to insert
Returns:
value that was evicted from the set as a result of the action

get

public V get(V key)
Description copied from interface: Set
Returns the 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. Equivalent to first(key)

Specified by:
get in interface Set<V>
Parameters:
key - value to find
Returns:
first matching value

copy

public HashSet<V,N> copy()
Description copied from interface: Set
Returns a copy of the set. This method may or may not return a set of the same class as the one it was called on, however return a Set

Specified by:
copy in interface AnySet<V>
Specified by:
copy in interface Set<V>

permitsDuplicates

public boolean permitsDuplicates()
Description copied from interface: AnyReadSet
Indicates if the set permits a value to occur more than once

Specified by:
permitsDuplicates in interface AnyReadSet<V>
Returns:
true, if successful

unique

public Set<V> unique()
Description copied from interface: Set
Returns this

Specified by:
unique in interface AnyReadSet<V>
Specified by:
unique in interface AnySet<V>
Specified by:
unique in interface Set<V>
Returns:
this

size

public int size()
Description copied from interface: Set
A convenience method returning the size of the set; this is equivalent to totalCount() or uniqueCount()

Specified by:
size in interface Set<V>
Returns:
size of the set

uniqueCount

public int uniqueCount()
Description copied from interface: AnyReadSet
Returns the number of unique values in the set

Specified by:
uniqueCount in interface AnyReadSet<V>
Returns:
number of unique values in the set

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object