package com.prolog.cs.biz.outbound.service.impl;

import org.apache.commons.lang.ObjectUtils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
//import lombok.Data;

//@Data
class DogForTest {
    private int age;
    private int weight;
    private String firstName;

    public DogForTest(int age, int weight, String firstName) {
        this.age = age;
        this.weight = weight;
        this.firstName = firstName;
    }

}

public class SortByFieldsTest {

    @org.junit.Test
    public void sort() {
        List<DogForTest> dogForTests = new ArrayList<>();
        DogForTest dogForTest1 = new DogForTest(1, 8, "andy");
        dogForTests.add(dogForTest1);
        DogForTest dogForTest2 = new DogForTest(2, 1, "lucy");
        dogForTests.add(dogForTest2);
        DogForTest dogForTest3 = new DogForTest(3, 2, "bob");
        dogForTests.add(dogForTest3);
        System.out.println(dogForTests);

        SortRules sortRules = new SortRules();
        SortRules.SortRule sortRule = new SortRules.SortRule("age", SortRules.SortRule.OrderBy.DESC);
        SortRules.SortRule sortRule2 = new SortRules.SortRule("weight", SortRules.SortRule.OrderBy.DESC);
        SortRules.SortRule sortRule3 = new SortRules.SortRule("firstName", SortRules.SortRule.OrderBy.DESC);
        sortRules.addRule(sortRule);
        sortRules.addRule(sortRule2);
        sortRules.addRule(sortRule3);

//        SortByFields.sort(dogForTests,sortRules);
        System.out.println(dogForTests);

    }

    @org.junit.Test
    public void testBigDecimel() {
        BigDecimal a = BigDecimal.valueOf(10);
        BigDecimal b = BigDecimal.valueOf(4);
        BigDecimal c = a.subtract(b);
        System.out.println(a.longValue());
        System.out.println(b.longValue());
        System.out.println(c.longValue());
        int i = c.compareTo(b);
        System.out.println(i);
    }

    @org.junit.Test
    public void testMapCompute() {
        Map<String, Integer> map = new HashMap<>();
        Integer caseQty = 1;
        map.computeIfPresent("buildingCode", (k, v) -> v + caseQty);
        map.putIfAbsent("buildingCode", caseQty);
        System.out.println(map);
    }

    @org.junit.Test
    public void testBigDecimel2() {
        BigDecimal caseConversionRate = BigDecimal.valueOf(400);
        BigDecimal qty = BigDecimal.valueOf(30);
        BigDecimal divide = qty.divide(caseConversionRate, 0, RoundingMode.DOWN);
        System.out.println(divide);
        divide = qty.divide(caseConversionRate, 2, RoundingMode.DOWN);

        System.out.println(divide);
        divide = qty.divide(caseConversionRate, 2, RoundingMode.UP);
        System.out.println(divide);
        divide = qty.divide(caseConversionRate, 0, RoundingMode.UP);
        System.out.println(divide);
    }


    @org.junit.Test
    public void testStream() {
        Integer a = 1;
        Boolean test = 1 == a;
        System.out.println("test interger");
        Integer b = null;
        test = ObjectUtils.equals(1, b);
        System.out.println(test);

    }

    @org.junit.Test
    public void testReduce() {
        List<String> test = new ArrayList<>();
        test.add("1");
        String reduce = test.stream().reduce((a, b) -> a.concat("|").concat(b)).orElse("3");
        System.out.println("reduce result is :" + reduce);

    }

    @org.junit.Test
    public void testHash() {
        List<Integer> lclLists = Arrays.asList(1, 2, 3, 2, null);
        lclLists = lclLists.stream().filter(Objects::nonNull).collect(Collectors.toList());
        Set<Integer> lclSet = new HashSet<>(lclLists);

        System.out.println("listSize is " + lclLists.size());
        System.out.println("set size is  is " + lclSet.size());

    }


}