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

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

public class MultiArraySet<V>
extends AbstractArraySet<V>
implements MultiSet<V>

See Also:
Serialized Form

Constructor Summary
MultiArraySet(int initialCapacity)
           
MultiArraySet(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.
 MultiSet<V> copy()
          Returns a copy of the set.
 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 value into the set.
 void put(V v, int c)
          Insert the value into the set the specified number of times.
 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.
 Set<V> unique()
          Returns a Set representing only the unique values present in this set.
 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

MultiArraySet

public MultiArraySet(int initialCapacity)

MultiArraySet

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

copy

public MultiSet<V> copy()
Description copied from interface: MultiSet
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 must return a MultiSet

Specified by:
copy in interface AnySet<V>
Specified by:
copy in interface MultiSet<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: MultiSet
Insert the value into the set. This method will always succeed and the return value will always be null.

Specified by:
put in interface AnySet<V>
Specified by:
put in interface MultiSet<V>
Parameters:
v - the val
Returns:
null

put

public void put(V v,
                int c)
Description copied from interface: MultiSet
Insert the value into the set the specified number of times.

Specified by:
put in interface MultiSet<V>
Parameters:
v - the val
c - the number of times

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: MultiSet
Returns a Set representing only the unique values present in this set. Changes to each set should be reflected in the other, however put() operations on the unique() set are not supported.

Specified by:
unique in interface AnyReadSet<V>
Specified by:
unique in interface AnySet<V>
Specified by:
unique in interface MultiSet<V>
Returns:
unique values

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