package com.yihu.wlyy.util;

import org.json.JSONObject;

import java.util.Comparator;
import java.util.Map;
import java.util.jar.JarEntry;

/**
 * Created by Trick on 2017/5/24.
 */
public class ValueComparator implements Comparator<String> {

    Map<String, JSONObject> base;
    //这里需要将要比较的map集合传进来
    public ValueComparator(Map<String, JSONObject> base) {
        this.base = base;
    }

    // Note: this comparator imposes orderings that are inconsistent with equals.
    //比较的时候，传入的两个参数应该是map的两个key，根据上面传入的要比较的集合base，可以获取到key对应的value，然后按照value进行比较
    public int compare(String a, String b) {

        JSONObject j1 =  base.get(a);
        JSONObject j2 =  base.get(b);
        j1.get("amount");
        j2.get("amount");
        if((Long)j1.get("amount")>=(Long)j2.get("amount")){
            return -1;
        }
        return 1;
    }
}
