net.sf.staccatocommons.collections.iterable
Class ModifiableIterables

java.lang.Object
  extended by net.sf.staccatocommons.collections.iterable.ModifiableIterables

public class ModifiableIterables
extends Object

A bunch of static methods that extend the Collections functionality, providing common algorithms for collections and iterables. These methods will not work with unmodifiable collections, as may modify input collections state, and thus we highly encourage to use Iterables instead, when possible

Author:
flbulgarelli

Constructor Summary
ModifiableIterables()
           
 
Method Summary
static
<T,C extends Collection<T>>
C
addAll(C collection, Iterable<? extends T> iterable)
          Adds all the elements from a given Iterable to a given collection
static
<T,C extends Collection<T>>
C
move(Iterable<T> iterable, C collection, Evaluable<T> predicate)
          Removes all elements from the given iterable that evalute to true, and adds them to the given collection
static
<T,C extends Collection<T>>
C
move(Iterable<T> iterable, int amountOfElements, C collection)
          Removes at most n elements from the given iterable, and adds it to the output collection
static
<I extends Iterable<?>>
I
remove(I iterable, int amountOfElements)
          Removes up to N elements from the given iterable
static
<T,I extends Iterable<T>>
I
removeAll(I iterable, Evaluable<? super T> predicate)
          Removes from the given iterable all the elements that evaluate to true
static
<T,I extends Iterable<T>>
I
removeWhile(I iterable, Evaluable<? super T> predicate)
          Removes elements from the given iterable, while each element evaluates to true
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModifiableIterables

public ModifiableIterables()
Method Detail

removeAll

@NonNull
public static <T,I extends Iterable<T>> I removeAll(@NonNull
                                                            I iterable,
                                                            @NonNull
                                                            Evaluable<? super T> predicate)
Removes from the given iterable all the elements that evaluate to true

Type Parameters:
T -
I -
Parameters:
iterable -
predicate -
Returns:
the given iterable

removeWhile

public static <T,I extends Iterable<T>> I removeWhile(@NonNull
                                                      I iterable,
                                                      @NonNull
                                                      Evaluable<? super T> predicate)
Removes elements from the given iterable, while each element evaluates to true

Type Parameters:
T -
Parameters:
iterable -
predicate -

remove

@NonNull
public static <I extends Iterable<?>> I remove(@NonNull
                                                       I iterable,
                                                       @NotNegative
                                                       int amountOfElements)
Removes up to N elements from the given iterable

Type Parameters:
I -
Parameters:
iterable -
amountOfElements - Non negative
Returns:
the given iterable

addAll

@NonNull
public static <T,C extends Collection<T>> C addAll(@NonNull
                                                           C collection,
                                                           @NonNull
                                                           Iterable<? extends T> iterable)
Adds all the elements from a given Iterable to a given collection

Type Parameters:
T -
C -
Parameters:
collection -
iterable -
Returns:
the given collection

move

@NonNull
public static <T,C extends Collection<T>> C move(@NonNull
                                                         Iterable<T> iterable,
                                                         @NonNull
                                                         C collection,
                                                         @NonNull
                                                         Evaluable<T> predicate)
Removes all elements from the given iterable that evalute to true, and adds them to the given collection

Type Parameters:
T -
C -
Parameters:
iterable -
collection -
predicate -
Returns:
the given collection

move

@NonNull
public static <T,C extends Collection<T>> C move(@NonNull
                                                         Iterable<T> iterable,
                                                         @NotNegative
                                                         int amountOfElements,
                                                         @NonNull
                                                         C collection)
Removes at most n elements from the given iterable, and adds it to the output collection

Type Parameters:
T -
C -
Parameters:
iterable -
amountOfElements - the max amount of elements to select from the iterable. Must be >= 0
collection -
Returns:
the output collection


Get Staccatocommons at SourceForge.net. Fast, secure and Free Open Source software downloads