@Test public void testCompare() { List<Range> ranges = new ArrayList<Range>(); Range addMe = new Range(); addMe.setBegin("192.168.101.1"); addMe.setEnd("192.168.101.254"); ranges.add(addMe); addMe = new Range(); addMe.setBegin("192.168.100.1"); addMe.setEnd("192.168.100.254"); ranges.add(addMe); addMe = new Range(); addMe.setBegin("10.1.2.1"); addMe.setEnd("10.1.2.100"); ranges.add(addMe); addMe = new Range(); addMe.setBegin("11.1.2.1"); addMe.setEnd("11.1.2.100"); ranges.add(addMe); addMe = new Range(); addMe.setBegin("12.1.2.1"); addMe.setEnd("12.1.2.100"); ranges.add(addMe); Collections.sort(ranges, new RangeComparator()); assertEquals("10.1.2.1", ranges.get(0).getBegin()); assertEquals("10.1.2.100", ranges.get(0).getEnd()); assertEquals("11.1.2.1", ranges.get(1).getBegin()); assertEquals("11.1.2.100", ranges.get(1).getEnd()); assertEquals("12.1.2.1", ranges.get(2).getBegin()); assertEquals("12.1.2.100", ranges.get(2).getEnd()); assertEquals("192.168.100.1", ranges.get(3).getBegin()); assertEquals("192.168.100.254", ranges.get(3).getEnd()); assertEquals("192.168.101.1", ranges.get(4).getBegin()); assertEquals("192.168.101.254", ranges.get(4).getEnd()); }
public int compare(final Range rng1, final Range rng2) { final InetAddress addr1 = InetAddressUtils.addr(rng1.getBegin()); final InetAddress addr2 = InetAddressUtils.addr(rng2.getBegin()); return new ByteArrayComparator().compare(addr1 == null? null : addr1.getAddress(), addr2 == null? null : addr2.getAddress()); }
RangeComparator implements Comparator<Range>, Serializable { public int compare(final Range rng1, final Range rng2) { final InetAddress addr1 = InetAddressUtils.addr(rng1.getBegin()); final InetAddress addr2 = InetAddressUtils.addr(rng2.getBegin()); return new ByteArrayComparator().compare(addr1 == null? null : addr1.getAddress(), addr2 == null? null : addr2.getAddress()); } }
RangeComparator implements Comparator<Range>, Serializable { public int compare(final Range rng1, final Range rng2) { final InetAddress addr1 = InetAddressUtils.addr(rng1.getBegin()); final InetAddress addr2 = InetAddressUtils.addr(rng2.getBegin()); return new ByteArrayComparator().compare(addr1 == null? null : addr1.getAddress(), addr2 == null? null : addr2.getAddress()); }  }
RangeComparator implements Comparator<Range>, Serializable { public int compare(final Range rng1, final Range rng2) { final InetAddress addr1 = InetAddressUtils.addr(rng1.getBegin()); final InetAddress addr2 = InetAddressUtils.addr(rng2.getBegin()); return new ByteArrayComparator().compare(addr1 == null? null : addr1.getAddress(), addr2 == null? null : addr2.getAddress()); }  int compare(final Range rng1, final Range rng2); }
RangeComparator implements Comparator<Range>, Serializable { public int compare(final Range rng1, final Range rng2) { final InetAddress addr1 = InetAddressUtils.addr(rng1.getBegin()); final InetAddress addr2 = InetAddressUtils.addr(rng2.getBegin()); return new ByteArrayComparator().compare(addr1 == null? null : addr1.getAddress(), addr2 == null? null : addr2.getAddress()); }  int compare(final Range rng1, final Range rng2);  }