org.jjoost.util.filters
Class AcceptUnique<V>

java.lang.Object
  extended by org.jjoost.util.filters.AcceptUnique<V>
All Implemented Interfaces:
java.io.Serializable, Filter<V>

public class AcceptUnique<V>
extends java.lang.Object
implements Filter<V>

A Filter which returns true if and only if it has never seen the value being tested before, using the provided set to maintain the previously visited set of values.

Author:
b.elliottsmith
See Also:
Serialized Form

Constructor Summary
AcceptUnique()
          Construct a new AcceptUnique using default propreties (hash set using Object.equals() and Object.hashCode())
AcceptUnique(Set<V> set)
          Construct a new AcceptUnique using the provided set to maintain the previously visited set of values
 
Method Summary
 boolean accept(V next)
          Returns true if the Filter accepts the parameter and false otherwise
static
<V> AcceptUnique<V>
get()
          Returns a Filter which returns true if and only if it has never seen the value being tested before, using regular object equality.
static
<V> AcceptUnique<V>
get(Equality<? super V> eq)
          Returns a Filter which returns true if and only if it has never seen the value being tested before, using the provided equality.
static
<V> AcceptUnique<V>
get(Set<V> set)
          Returns a Filter which returns true if and only if it has never seen the value being tested before, using the provided set to maintain all visited values, and hence the set's definition of equality.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AcceptUnique

public AcceptUnique()
Construct a new AcceptUnique using default propreties (hash set using Object.equals() and Object.hashCode())


AcceptUnique

public AcceptUnique(Set<V> set)
Construct a new AcceptUnique using the provided set to maintain the previously visited set of values

Method Detail

accept

public boolean accept(V next)
Description copied from interface: Filter
Returns true if the Filter accepts the parameter and false otherwise

Specified by:
accept in interface Filter<V>
Parameters:
next - value to test
Returns:
true if the filter accepts test; false otherwise

toString

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

get

public static <V> AcceptUnique<V> get()
Returns a Filter which returns true if and only if it has never seen the value being tested before, using regular object equality. It maintains a set of all visited values and therefore can be expensive with respect to memory utilisation.

Returns:
a filter accepting only unique values

get

public static <V> AcceptUnique<V> get(Equality<? super V> eq)
Returns a Filter which returns true if and only if it has never seen the value being tested before, using the provided equality. It maintains a set of all visited values and therefore can be expensive with respect to memory utilisation.

Parameters:
eq - the equality determining uniqueness
Returns:
a filter accepting only unique values

get

public static <V> AcceptUnique<V> get(Set<V> set)
Returns a Filter which returns true if and only if it has never seen the value being tested before, using the provided set to maintain all visited values, and hence the set's definition of equality. This can be expensive with respect to memory utilisation.

Parameters:
set - the set to store visited values in
Returns:
a filter accepting only unique values