org.jjoost.collections
Interface AnyReadSet<V>

All Superinterfaces:
Function<V,java.lang.Boolean>, java.lang.Iterable<V>, java.io.Serializable
All Known Subinterfaces:
AnySet<V>, MultiSet<V>, Set<V>, UnitarySet<V>
All Known Implementing Classes:
AbstractArraySet, AbstractHashSet, AbstractSet, AbstractUniqueSetAdapter, AdapterFromJDKSet, ArraySet, HashSet, InlineMultiHashSet, IterableSet, LockFreeCountingMultiHashSet, LockFreeHashSet, LockFreeInlineMultiHashSet, LockFreeLinkedCountingMultiHashSet, LockFreeLinkedInlineMultiHashSet, LockFreeLinkedNestedMultiHashSet, LockFreeLinkedScalarHashSet, LockFreeNestedMultiHashSet, MultiArraySet, NestedMultiHashSet, SerialCountingMultiHashSet, SerialHashSet, SerialInlineMultiHashSet, SerialLinkedCountingMultiHashSet, SerialLinkedHashSet, SerialLinkedInlineMultiHashSet, SerialLinkedNestedMultiHashSet, SerialNestedMultiHashSet, SynchronizedArbitrarySet, SynchronizedMultiSet, SynchronizedSet

public interface AnyReadSet<V>
extends java.lang.Iterable<V>, Function<V,java.lang.Boolean>, java.io.Serializable

This interface is the common ancestor of all Jjoost sets.

The methods declared here make no assumptions about the number of occurences of a given value and declare no actions that may modify the set, so is the most general form of set. No concrete class should implement this interface directly.

WARNING: Note that in a MultiSet the iterator() method will return an Iterator that enumerates every occurence of every value. If you want to get unique occurences of values, call the unique() method.

Also note that an Iterator returned by concurrent implementors of this class is permitted to return values more times than they actually ever occurred if a valid sequence of deletes and inserts happens to cause the Iterator to see the values multiple times. See the javadoc of the implementing classes to determine their behaviour in this case.

Author:
b.elliottsmith

Method Summary
 java.lang.Iterable<V> all(V find)
          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.
 boolean contains(V find)
          Returns a boolean indicating if the parameter occurs in the set at least once.
 int count(V find)
          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 find)
          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.List<V> list(V find)
          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.
 boolean permitsDuplicates()
          Indicates if the set permits a value to occur more than once
 int totalCount()
          Returns the total number of values (including duplicates) in the set
 java.lang.Iterable<V> unique()
          Returns an Iterable of only unique values in the set, as determined by the set's definition of equality.
 int uniqueCount()
          Returns the number of unique values in the set
 
Methods inherited from interface java.lang.Iterable
iterator
 
Methods inherited from interface org.jjoost.util.Function
apply
 

Method Detail

first

V first(V find)
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.

Parameters:
find - value to look for
Returns:
first matching value

all

java.lang.Iterable<V> all(V find)
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.

Parameters:
find - value to look for
Returns:
matching values

list

java.util.List<V> list(V find)
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.

Parameters:
find - value to look for
Returns:
matching values

contains

boolean contains(V find)
Returns a boolean indicating if the parameter occurs in the set at least once.

Parameters:
find - value to look for
Returns:
true, if present

count

int count(V find)
Returns an integer representing the number of occurrences of the value in the set

Parameters:
find - value to look for
Returns:
number of occurrences

unique

java.lang.Iterable<V> unique()
Returns an Iterable of only unique values in the set, as determined by the set's definition of equality. This method is guaranteed not to return duplicates, even under concurrent reads/writes of the same value in the middle of iteration.

Returns:
unique values

totalCount

int totalCount()
Returns the total number of values (including duplicates) in the set

Returns:
total number of values in the set

uniqueCount

int uniqueCount()
Returns the number of unique values in the set

Returns:
number of unique values in the set

isEmpty

boolean isEmpty()
Indicates if the set is empty

Returns:
true, if is empty

permitsDuplicates

boolean permitsDuplicates()
Indicates if the set permits a value to occur more than once

Returns:
true, if successful

equality

Equality<? super V> equality()
Returns an object that represents the definition of equality used by this set

Returns:
an object representing the equality used by this set