package com.sf._01_treeset_contact;

import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

public class Test {
    public static void main(String[] args) {
        Goods goods = new Goods(1L,"电脑",10000);
        Goods goods1 = new Goods(3L,"手机",4000);
        Goods goods2 = new Goods(2L,"耳机",8000);
        Goods goods3 = new Goods(4L,"洗衣机",4000);
        // key Goods 商品  value 库存
        TreeMap<Goods,Integer> map = new TreeMap<>();
        map.put(goods,100);
        map.put(goods1,100);
        map.put(goods2,100);
        map.put(goods3,100);

        // 遍历map 观察排序结果
        for (Map.Entry<Goods, Integer> goodsIntegerEntry : map.entrySet()) {
            System.out.println(goodsIntegerEntry);
        }
        System.out.println("---------------------------------------");
        TreeMap<Goods,Integer> goodsIntegerTreeMap = new TreeMap<>(new Comparator<Goods>() {
            @Override
            public int compare(Goods o1, Goods o2) {
                if(o1.getPrice() > o2.getPrice()){
                    return -1;
                }else if(o1.getPrice() < o2.getPrice()){
                    return 1;
                }else{
                    if(o1.getGoodsId() > o2.getGoodsId()){
                        return 1;
                    }else if(o1.getGoodsId() < o2.getGoodsId()){
                        return -1;
                    }else{
                        return 0;
                    }
                }
            }
        });

        goodsIntegerTreeMap.put(goods,100);
        goodsIntegerTreeMap.put(goods1,100);
        goodsIntegerTreeMap.put(goods2,100);
        goodsIntegerTreeMap.put(goods3,100);

        int count = 0;
        for (Map.Entry<Goods, Integer> goodsIntegerEntry : goodsIntegerTreeMap.entrySet()) {
            double price = goodsIntegerEntry.getKey().getPrice();
            if(price >= 200){
                count++;
            }
        }

    }
}
