package org.cloudbus.cloudsim.power.lists;

import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.lists.HostList;
import org.cloudbus.cloudsim.power.PowerHost;

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

/**
 * ClassName PowerHostList
 * Description
 * Create by HW
 * Date 2021/5/29 17:27
 */
public class PowerHostList extends HostList {

    public static <T extends Host> void sortByPerformace(List<T> hostList) {
        Collections.sort(hostList, new Comparator<T>() {

            @Override
            public int compare(T a, T b) throws ClassCastException {
                Double aUtilization =a.getTotalProfomance();
                Double bUtilization =b.getTotalProfomance();
                return bUtilization.compareTo(aUtilization);
            }
        });
    }

    public static <T extends PowerHost> void sortByEnergyEfficiency(List<T> hostList){
        Collections.sort(hostList, new Comparator<T>() {
            @Override
            public int compare(T o1, T o2) {
                Double A_energyEfficiency=o1.getTotalMips()/o1.getMaxPower();
                Double B_energyEfficiency=o2.getTotalMips()/o2.getMaxPower();
                return B_energyEfficiency.compareTo(A_energyEfficiency);
            }
        });
    }
}
