//////////////////////////////////////////////////////////////////////////////
// 
//                    Copyright 2015, Cornutum Project
//                             www.cornutum.org
//
//////////////////////////////////////////////////////////////////////////////

package org.cornutum.tcases.util;

import org.apache.commons.collections4.Predicate;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

/**
 * Defines methods for handling collections.
 */
public final class CollectionUtils
  {
  /**
   * Creates a new CollectionUtils object.
   */
  private CollectionUtils()
    {
    // Static methods only
    }

  /**
   * Returns a list containing a clone of each member of the given collection.
   */
  static public <T extends Cloneable<T>> List<T> clonedList( Iterable<T> list)
    {
    List<T> other = new ArrayList<T>();
    for( T member : list)
      {
      other.add( member.cloneOf());
      }
    
    return other;
    }

  /**
   * Returns the given collection after removing any member that does not satisfy the given predicate.
   */
  static public <T,C extends Iterable<T>> C filtered( C collection, Predicate<T> predicate)
    {
    for( Iterator<T> members = collection.iterator(); members.hasNext(); )
      {
      if( !predicate.evaluate( members.next()))
        {
        members.remove();
        }
      }

    return collection;
    }

  /**
   * Returns a stream that produces the sequence defined by the given Iterator.
   */
  static public <T> Stream<T> toStream( Iterator<T> iterator)
    {
    Iterable<T> iterable = () -> iterator;
    return StreamSupport.stream( iterable.spliterator(), false);
    }
  }

@@ -308,128 +308,26 @@
 ort 
-org.apache.commons.collections4.Predicate;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Iterator;%0Aimport java.util.List
+java.util.Iterator
 ;%0Aim
@@ -573,24 +573,24 @@
 ils()%0A    %7B%0A
+
     // Stati
@@ -615,761 +615,8 @@
  %7D%0A%0A
-  /**%0A   * Returns a list containing a clone of each member of the given collection.%0A   */%0A  static public %3CT extends Cloneable%3CT%3E%3E List%3CT%3E clonedList( Iterable%3CT%3E list)%0A    %7B%0A    List%3CT%3E other = new ArrayList%3CT%3E();%0A    for( T member : list)%0A      %7B%0A      other.add( member.cloneOf());%0A      %7D%0A    %0A    return other;%0A    %7D%0A%0A  /**%0A   * Returns the given collection after removing any member that does not satisfy the given predicate.%0A   */%0A  static public %3CT,C extends Iterable%3CT%3E%3E C filtered( C collection, Predicate%3CT%3E predicate)%0A    %7B%0A    for( Iterator%3CT%3E members = collection.iterator(); members.hasNext(); )%0A      %7B%0A      if( !predicate.evaluate( members.next()))%0A        %7B%0A        members.remove();%0A        %7D%0A      %7D%0A%0A    return collection;%0A    %7D%0A%0A
   /*

Remove unused methods