/*
 * Created on Jan 28, 2011
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this Throwable except in compliance
 * with the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 * 
 * Copyright @2011 the original author or authors.
 */
package org.assertj.core.groups;

import java.util.List;

import org.assertj.core.api.AbstractIterableAssert;
import org.assertj.core.api.AbstractObjectArrayAssert;
import org.assertj.core.api.iterable.Extractor;
import org.assertj.core.util.Iterables;
import org.assertj.core.util.Lists;

/**
 * 
 * Understands how to retrieve fields or values from a collection/array of objects.
 * <p>
 * You just have to give the field/property name or an {@link Extractor} implementation, a collection/array of objects
 * and it will extract the list of field/values from the given objects.
 * 
 * @author Joel Costigliola
 * @author Mateusz Haligowski
 * 
 */
public class FieldsOrPropertiesExtractor {
  
  /**
   * Call {@link #extract(Iterable, Extractor)} after converting objects to an iterable.
   * <p>
   * Behavior is described in javadoc {@link AbstractObjectArrayAssert#extracting(Extractor)}
   */
  public static <F, T> T[] extract(F[] objects, Extractor<? super F, T> extractor) {
    List<T> result = Lists.newArrayList();
            
    for (F object : objects) {
      final T newValue = extractor.extract(object);
      result.add(newValue);
    }
    
    return result.toArray(Iterables.toArray(result));
  }

  /**
   * Behavior is described in {@link AbstractIterableAssert#extracting(Extractor)} 
   */
  public static <F, T> List<T> extract(Iterable<F> objects, Extractor<? super F, T> extractor) {
    List<T> result = Lists.newArrayList();
    
    for (F object : objects) {
      final T newValue = extractor.extract(object);
      result.add(newValue);
    }
    
    return result;
  }

}

@@ -669,16 +669,128 @@
 roups;%0A%0A
+import static org.assertj.core.util.Iterables.toArray;%0Aimport static org.assertj.core.util.Lists.newArrayList;%0A%0A
 import j
@@ -964,48 +964,8 @@
 or;%0A
-import org.assertj.core.util.Iterables;%0A
 impo
@@ -1683,32 +1683,36 @@
  T%3E extractor) %7B
+    
 %0A    List%3CT%3E res
@@ -1709,38 +1709,40 @@
 ist%3CT%3E result = 
-Lists.
+extract(
 newArrayList();%0A
@@ -1742,182 +1742,41 @@
 ist(
-);%0A            %0A    for (F object : objects) %7B%0A      final T newValue = extractor.extract(object);%0A      result.add(newValue);%0A    %7D%0A    %0A    return result.toArray(Iterables.
+objects), extractor);%0A    return 
 toAr
@@ -1786,17 +1786,16 @@
 (result)
-)
 ;%0A  %7D%0A%0A 

Remove code duplication in FieldsOrPropertiesExtractor with a minor performance penalty.