class UrlIpComparator implements Comparator<URL> {

  @Override
  public int compare(URL first, URL second) {
    //对象为空校验
    if (null == first && null == second) {
      return 0;
    } else if (null == first) {
      return -1;
    } else if (null == second) {
      return 1;
    }

    String firstIp = first.getIp();
    String secendIp = second.getIp();

    if (firstIp == secendIp) {
      return 0;
    }

    // return a negative integer, zero, or a positive integer as the first
    // argument is less than, equal to, or greater than the second.
    if (firstIp != null && secendIp != null) {
      return firstIp.compareTo(secendIp);
    } else if (firstIp != null && secendIp == null) {
      return 1;
    } else if (firstIp == null && secendIp != null) {
      return -1;
    }

    return 0;
  }

}