package com.tzld.piaoquan.ad.engine.commons.util;

import com.tzld.piaoquan.recommend.feature.domain.ad.base.AdRankItem;

import java.util.Comparator;

public class ComparatorUtil {

    public static Comparator<AdRankItem> equalsRandomComparator() {
        return new Comparator<AdRankItem>() {
            @Override
            public int compare(AdRankItem o1, AdRankItem o2) {
                int comparison = o1.compareTo(o2);
                if (comparison != 0) {
                    return comparison;
                }

                return Integer.compare(o1.getRandom(), o2.getRandom());

                // 数字相等时随机排列
                // return new Random().nextInt(3) - 1; // 产生-1、0或1的随机值
            }
        };
    }
}
