### Question:
DistanceComparator implements Comparator<Peer> { @Override public int compare(Peer p1, Peer p2) { int d1 = p1.getPeerId().distanceTo(targetId); int d2 = p2.getPeerId().distanceTo(targetId); return Integer.compare(d1, d2); } DistanceComparator(byte[] targetId); @Override int compare(Peer p1, Peer p2);  }### Answer:
@Test public void compareTest() { DistanceComparator distanceComparator = new DistanceComparator(OWNER.getPeerId().getBytes()); Peer p1 = Peer.valueOf("ynode: Peer p2 = Peer.valueOf("ynode: int shortDistance = OWNER.getPeerId().distanceTo(p1.getPeerId().getBytes()); int longDistance = OWNER.getPeerId().distanceTo(p2.getPeerId().getBytes()); assert shortDistance < longDistance; assert distanceComparator.compare(p1, p2) < 0; ArrayList<Peer> peerArrayList = new ArrayList<>(); peerArrayList.add(p2); peerArrayList.add(p1); peerArrayList.sort(distanceComparator); assert peerArrayList.get(0).equals(p1); Assert.assertEquals(shortDistance,peerArrayList.get(0).getPeerId().distanceTo(OWNER.getPeerId().getBytes())); }