/** * Order two containers by their execution type, followed by * their out-of-limit status and then launch time. Opportunistic * containers are ordered before Guaranteed containers. If two * containers are of the same execution type, the one that is * out of its limits is ordered before the one that isn't. If * two containers have the same execution type and out-of-limit * status, the one that's launched later is ordered before the * other one. */ @Override public int compareTo(ContainerCandidate o) { boolean isThisOpportunistic = isOpportunistic(container); boolean isOtherOpportunistic = isOpportunistic(o.container); int ret = Boolean.compare(isOtherOpportunistic, isThisOpportunistic); if (ret == 0) { // the two containers are of the same execution type, order them // by their out-of-limit status. int outOfLimitRet = Boolean.compare(o.outOfLimit, outOfLimit); if (outOfLimitRet == 0) { // the two containers are also of the same out-of-limit status, // order them by their launch time ret = Long.compare(o.container.getContainerLaunchTime(), this.container.getContainerLaunchTime()); } else { ret = outOfLimitRet; } } return ret; }