@Test public void testCompareWithNulls() { InetAddressComparator comparator = new InetAddressComparator(); Assert.assertEquals(0, comparator.compare(null, null)); Assert.assertEquals(-1, comparator.compare(null, address1)); Assert.assertEquals(1, comparator.compare(address1, null)); }
@Override public int compare(InetAddress address1, InetAddress address2) { if (address1 == null && address2 == null) { return 0; } else if (address1 == null) { return -1; } else if (address2 == null) { return 1; } byte[] addr1 = address1.getAddress(); byte[] addr2 = address2.getAddress(); if (addr1.length < addr2.length) { return -1; } else if (addr1.length > addr2.length) { return 1; } for (int i = 0; i < addr1.length; i++) { int b1 = ubyte2int(addr1[i]); int b2 = ubyte2int(addr2[i]); if (b1 < b2) { return -1; } else if (b1 > b2) { return 1; } } return 0; }
InetAddressComparator implements Comparator<InetAddress>, Serializable { @Override public int compare(InetAddress address1, InetAddress address2) { if (address1 == null && address2 == null) { return 0; } else if (address1 == null) { return -1; } else if (address2 == null) { return 1; } byte[] addr1 = address1.getAddress(); byte[] addr2 = address2.getAddress(); if (addr1.length < addr2.length) { return -1; } else if (addr1.length > addr2.length) { return 1; } for (int i = 0; i < addr1.length; i++) { int b1 = ubyte2int(addr1[i]); int b2 = ubyte2int(addr2[i]); if (b1 < b2) { return -1; } else if (b1 > b2) { return 1; } } return 0; } }
InetAddressComparator implements Comparator<InetAddress>, Serializable { @Override public int compare(InetAddress address1, InetAddress address2) { if (address1 == null && address2 == null) { return 0; } else if (address1 == null) { return -1; } else if (address2 == null) { return 1; } byte[] addr1 = address1.getAddress(); byte[] addr2 = address2.getAddress(); if (addr1.length < addr2.length) { return -1; } else if (addr1.length > addr2.length) { return 1; } for (int i = 0; i < addr1.length; i++) { int b1 = ubyte2int(addr1[i]); int b2 = ubyte2int(addr2[i]); if (b1 < b2) { return -1; } else if (b1 > b2) { return 1; } } return 0; }  }
InetAddressComparator implements Comparator<InetAddress>, Serializable { @Override public int compare(InetAddress address1, InetAddress address2) { if (address1 == null && address2 == null) { return 0; } else if (address1 == null) { return -1; } else if (address2 == null) { return 1; } byte[] addr1 = address1.getAddress(); byte[] addr2 = address2.getAddress(); if (addr1.length < addr2.length) { return -1; } else if (addr1.length > addr2.length) { return 1; } for (int i = 0; i < addr1.length; i++) { int b1 = ubyte2int(addr1[i]); int b2 = ubyte2int(addr2[i]); if (b1 < b2) { return -1; } else if (b1 > b2) { return 1; } } return 0; }  static boolean greaterThan(InetAddress address1, InetAddress address2); @Override int compare(InetAddress address1, InetAddress address2); }
InetAddressComparator implements Comparator<InetAddress>, Serializable { @Override public int compare(InetAddress address1, InetAddress address2) { if (address1 == null && address2 == null) { return 0; } else if (address1 == null) { return -1; } else if (address2 == null) { return 1; } byte[] addr1 = address1.getAddress(); byte[] addr2 = address2.getAddress(); if (addr1.length < addr2.length) { return -1; } else if (addr1.length > addr2.length) { return 1; } for (int i = 0; i < addr1.length; i++) { int b1 = ubyte2int(addr1[i]); int b2 = ubyte2int(addr2[i]); if (b1 < b2) { return -1; } else if (b1 > b2) { return 1; } } return 0; }  static boolean greaterThan(InetAddress address1, InetAddress address2); @Override int compare(InetAddress address1, InetAddress address2);  }