package org.simpleflatmapper.csv.bug;

import org.junit.Test;
import org.simpleflatmapper.csv.CsvMapper;
import org.simpleflatmapper.csv.CsvMapperFactory;
import org.simpleflatmapper.csv.CsvParser;
import org.simpleflatmapper.map.property.RenameProperty;
import org.simpleflatmapper.map.property.SetterProperty;
import org.simpleflatmapper.reflect.Setter;

import java.io.IOException;

public class Issue364 {

    public static String DATA = "Benchmark,Score\n" +
            "MyAlgo.forFile,0.23423\n" +
            "MyAlgo.forString,0.13423\n" +
            "OtherAlgo.forFile,0.34233\n" +
            "OtherAlgo.forString,0.14423";


    public static class Data {
        public String algorithm;
        public String type;
        public double score;


        public void setBenchmark(String value) {
                int indexOfDot = value.indexOf('.');
                algorithm = value.substring(0, indexOfDot);
                type = value.substring(indexOfDot + 1, value.length());

        }
        @Override
        public String toString() {
            return "Data{" +
                    "algorithm='" + algorithm + '\'' +
                    ", type='" + type + '\'' +
                    ", score=" + score +
                    '}';
        }
    }

    @Test
    public void testParse() throws IOException {

//        CsvMapper<Data> mapper = CsvMapperFactory
//                .newInstance()
//                .addColumnProperty("Benchmark", new Setter<Data, String>() {
//                    @Override
//                    public void set(Data target, String value) throws Exception {
//                        int indexOfDot = value.indexOf('.');
//                        target.algorithm = value.substring(0, indexOfDot);
//                        target.type = value.substring(indexOfDot + 1, value.length());
//                    }
//                })
//                .newMapper(Data.class);


        Setter<Data, String> setter = (target, value)  -> {
                int indexOfDot = value.indexOf('.');
                target.algorithm = value.substring(0, indexOfDot);
                target.type = value.substring(indexOfDot + 1, value.length());
            };

        CsvMapper<Data> mapper = CsvMapperFactory
                .newInstance()
//                .addColumnProperty("Benchmark", new SetterProperty(setter))
                .newMapper(Data.class);
        CsvParser.mapWith(mapper).stream(DATA).forEach(System.out::println);
    }
}

@@ -223,92 +223,22 @@
 per.
-map.property.RenameProperty;%0Aimport org.simpleflatmapper.map.property.SetterProperty
+reflect.Setter
 ;%0Aim
@@ -259,36 +259,42 @@
 eflatmapper.
-reflect.Sett
+util.CheckedConsum
 er;%0A%0Aimport 
@@ -2372,29 +2372,151 @@
 er).
-stream(DATA).forEach(
+forEach(DATA, new CheckedConsumer%3CData%3E() %7B%0A            @Override%0A            public void accept(Data data) throws Exception %7B%0A                
 Syst
@@ -2525,17 +2525,59 @@
 .out
-::
+.
 println
+(%22data = %22 + data);%0A            %7D%0A        %7D
 );%0A 

fix java6