org.jjoost.collections.sets.serial
Class ArraySet<V>

java.lang.Object
  extended by org.jjoost.collections.sets.base.AbstractArraySet<V>
      extended by org.jjoost.collections.sets.serial.ArraySet<V>
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<V>, AnyReadSet<V>, AnySet<V>, Set<V>, Function<V,java.lang.Boolean>

public class ArraySet<V>
extends AbstractArraySet<V>
implements Set<V>

See Also:
Serialized Form

Constructor Summary
ArraySet(int initialCapacity)
           
ArraySet(int initialCapacity, Equality<? super V> valEq)
           
 
Method Summary
 boolean add(V v)
          Attempt to add the value to the set, returning false if the value could not be added, and true if it was.
 java.lang.Iterable<V> all(V v)
          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.
 Set<V> copy()
          Returns a copy of the set.
 V get(V v)
          Returns the value stored in the set that is equal to the provided value, as determined by any provided Equality or Comparator.
 java.util.List<V> list(V v)
          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
 V put(V v)
          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 putAll(java.lang.Iterable<V> vs)
          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.
 int size()
          A convenience method returning the size of the set; this is equivalent to totalCount() or uniqueCount()
 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.AbstractArraySet
apply, clear, clearAndReturn, contains, count, equality, first, isEmpty, iterator, putIfAbsent, remove, remove, removeAndReturn, removeAndReturn, removeAndReturnFirst, removeAndReturnFirst, shrink, totalCount
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jjoost.collections.AnySet
clear, clearAndReturn, putIfAbsent, remove, remove, removeAndReturn, removeAndReturn, removeAndReturnFirst, removeAndReturnFirst, shrink
 
Methods inherited from interface org.jjoost.collections.AnyReadSet
contains, count, equality, first, isEmpty, totalCount
 
Methods inherited from interface java.lang.Iterable
iterator
 
Methods inherited from interface org.jjoost.util.Function
apply
 

Constructor Detail

ArraySet

public ArraySet(int initialCapacity)

ArraySet

public ArraySet(int initialCapacity,
                Equality<? super V> valEq)
Method Detail

copy

public Set<V> 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>

add

public boolean add(V v)
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:
v - value to insert
Returns:
true if the set was modified, false otherwise

put

public V put(V v)
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:
v - value to insert
Returns:
value that was evicted from the set as a result of the action

get

public V get(V v)
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:
v - value to find
Returns:
first matching value

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

putAll

public int putAll(java.lang.Iterable<V> vs)
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:
vs - values to insert
Returns:
number that did not displace existing values

all

public java.lang.Iterable<V> all(V v)
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:
v - value to look for
Returns:
matching values

list

public java.util.List<V> list(V v)
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:
v - value to look for
Returns:
matching values

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

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