package com.github.arteam.jgcompare;

import com.google.common.base.Splitter;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import org.assertj.core.api.Assertions;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.Spliterators;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * Date: 4/16/15
 * Time: 11:52 PM
 *
 * @author Artem Prigoda
 */
public class FluentIterablesTest {

    Iterable<String> source = Lists.newArrayList("1 18", "20 24 9", "92");
    Stream<String> stream = Stream.of("1 18", "20 24 9", "92");

    @Test
    public void testTransformAndConcat() {
        Splitter splitter = Splitter.on(" ");
        assertThat(FluentIterable.from(source)
                .transformAndConcat(splitter::split)
                .transform(Integer::parseInt)
                .toList()).containsOnly(1, 18, 20, 24, 9, 92);
        assertThat(stream.flatMap(s -> Stream.of(s.split(" ")))
                .map(Integer::parseInt)
                .collect(Collectors.toList())).containsOnly(1, 18, 20, 24, 9, 92);
    }

}

@@ -108,110 +108,9 @@
 ect.
-FluentIterable;%0Aimport com.google.common.collect.ImmutableList;%0Aimport com.google.common.collect.Lists
+*
 ;%0Aim
@@ -219,16 +219,38 @@
 l.List;%0A
+import java.util.Map;%0A
 import j
@@ -1149,10 +1149,888 @@
 %0A    %7D%0A%0A
+%0A    @Test%0A    public void index() %7B%0A        Splitter splitter = Splitter.on(%22 %22);%0A        assertThat(FluentIterable.from(source)%0A                .transformAndConcat(splitter::split)%0A                .index(s -%3E s.substring(0, 1))).isEqualTo(ImmutableListMultimap.%3CString, String%3Ebuilder()%0A                .putAll(%221%22, %221%22, %2218%22)%0A                .putAll(%222%22, %2220%22, %2224%22)%0A                .putAll(%229%22, %229%22, %2292%22)%0A                .build());%0A%0A        assertThat(stream.flatMap(s -%3E Stream.of(s.split(%22 %22)))%0A                .collect(Collectors.groupingBy(s -%3E s.substring(0, 1))))%0A                .isEqualTo(ImmutableMap.%3CString, List%3CString%3E%3Ebuilder()%0A                        .put(%221%22, ImmutableList.of(%221%22, %2218%22))%0A                        .put(%222%22, ImmutableList.of(%2220%22, %2224%22))%0A                        .put(%229%22, ImmutableList.of(%229%22, %2292%22))%0A                        .build());%0A    %7D%0A
 %7D%0A

Add FluentIterable#index