package kr.co.jinwoosi.clfd.framework.cd.mapper;

import kr.co.jinwoosi.clfd.framework.cd.model.CdDtl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.Comparator;
import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
        "classpath:config/spring/context-datasource.xml",
        "classpath:config/spring/context-mybatis.xml",
        "classpath:config/spring/context-common.xml",
        "classpath:config/spring/context-transaction.xml"
})
public class CdDtlMapperTest {

    @Autowired
    private CdDtlMapper cdDtlMapper;

    @Test
    public void dgnsTyCdSortTest() {
        List<CdDtl> cdDtlList = cdDtlMapper.selectList(new CdDtl("dgnsTyCd"));
        cdDtlList.forEach(cdDtl1 -> {
            System.out.println(cdDtl1.getCdDtlOrd() + " " + cdDtl1.getCdDtlId());
        });
        Comparator<CdDtl> cdDtlComparator = new Comparator<CdDtl>(){
            @Override
            public int compare(CdDtl o1, CdDtl o2) {
                if (Integer.parseInt(o1.getCdDtlOrd()) > Integer.parseInt(o2.getCdDtlOrd())) {
                    return -1;
                } else {
                    return 1;
                }
            }
        };

        cdDtlList.sort(CdDtl::compareTo);
        cdDtlList.sort(cdDtlComparator);
        cdDtlList.sort((o1, o2) -> {
            if (Integer.parseInt(o1.getCdDtlOrd()) > Integer.parseInt(o2.getCdDtlOrd())) {
                return -1;
            } else {
                return 1;
            }
        });



//        cdDtlList.stream().sorted((o1, o2) -> cdDtlComparator.compare(o1, o2)).collect(Collectors.toList()).forEach(cdDtl1 -> {
//            System.out.println(cdDtl1.getCdDtlOrd() + " " + cdDtl1.getCdDtlId());
//        });
        cdDtlList.forEach(cdDtl1 -> {
            System.out.println(cdDtl1.getCdDtlOrd() + " " + cdDtl1.getCdDtlId());
        });


    }
}
