package lambda;

import com.google.common.base.Joiner;
import org.junit.Test;
import org.testng.collections.Lists;

import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.DoubleStream;
import java.util.stream.Stream;

public class CollectorStreamTest {

    @Test
    public void test(){
        List<String> stringList = Lists.newArrayList("linuxea","l_kimboo","jina","floer","vicky","bonnie");
        String string = stringList.stream()
                .filter(s -> s.length() > 3)
                .filter(s -> s.startsWith("l"))
                .collect(Collectors.joining("*"));
        System.out.println(string);

        String newString = stringList.stream().collect(Collectors.joining("','"));
        System.out.println("'" + newString + "'");
    }


    @Test
    public void test2(){
        List<String[]> strings = Lists.newArrayList();
        strings.add(new String[]{"linuxea","kimboo","jacky"});
        strings.add(new String[]{"orange","fruit","pony"});
        strings.add(new String[]{"miaoMi","linuxea","kimmy"});
        List<String[]> list = strings.stream().distinct().collect(Collectors.toList());
        Consumer<String[]> consumer = strArr -> System.out.println(Arrays.toString(strArr));
        list.stream().forEach(consumer);
        System.out.println("ok");

        //thinking...  方法引用能否再套方法引用

        Function<String[], String> function
                = stringArr2 -> Joiner.on(",").join(stringArr2);
        strings.stream().map(function).forEach(System.out::println);

    }


    /**
     * 流的扁平化操作
     */
    @Test
    public void test3(){
        List<String[]> strings = Lists.newArrayList();
        strings.add(new String[]{"linuxea","kimboo","jacky"});
        strings.add(new String[]{"orange","fruit","pony"});
        strings.add(new String[]{"miaoMi","linuxea","kimmy"});

        strings.stream().flatMap(Arrays::stream).forEach(System.out::println);

    }



}

@@ -2033,12 +2033,518 @@
 %0A    %7D%0A%0A
+    /**%0A     * %E5%AE%9E%E7%8E%B0%E4%B8%80%E4%B8%AAString flatMap%0A     */%0A    @Test%0A    public void myStringFlatMap()%7B%0A        List%3CString%5B%5D%3E strings = Lists.newArrayList();%0A        strings.add(new String%5B%5D%7B%22linuxea%22,%22kimboo%22,%22jacky%22%7D);%0A        strings.add(new String%5B%5D%7B%22orange%22,%22fruit%22,%22pony%22%7D);%0A        strings.add(new String%5B%5D%7B%22miaoMi%22,%22linuxea%22,%22kimmy%22%7D);%0A%0A        Function%3CString%5B%5D, Stream%3CString%3E%3E bibiString = stringArray -%3E Stream.of(stringArray);%0A        strings.stream().flatMap(bibiString).forEach(System.out::println);%0A    %7D%0A%0A
 %0A%0A%7D%0A

实现一个String flatMap