@Test public void testCompare() { List<IVector2> points = new ArrayList<>(); Random rnd = new Random(43); for (int i = 0; i < 100; i++) { points.add(Vector2.fromXY(rnd.nextDouble() * 5000 - 2500, rnd.nextDouble() * 5000 - 2500)); } points.add(Vector2.zero()); points.add(Vector2.zero()); points.sort(new VectorLengthComparator()); double smallestValue = -1; for (IVector2 p : points) { double len = p.getLength2(); assertThat(len).isGreaterThanOrEqualTo(smallestValue); smallestValue = len; } }
@Override public int compare(final IVector2 o1, final IVector2 o2) { double len1 = o1.getLength2(); double len2 = o2.getLength2(); if (len1 < len2) { return -1; } if (len2 < len1) { return 1; } return 0; }
VectorLengthComparator implements Comparator<IVector2> { @Override public int compare(final IVector2 o1, final IVector2 o2) { double len1 = o1.getLength2(); double len2 = o2.getLength2(); if (len1 < len2) { return -1; } if (len2 < len1) { return 1; } return 0; } }
VectorLengthComparator implements Comparator<IVector2> { @Override public int compare(final IVector2 o1, final IVector2 o2) { double len1 = o1.getLength2(); double len2 = o2.getLength2(); if (len1 < len2) { return -1; } if (len2 < len1) { return 1; } return 0; }  }
VectorLengthComparator implements Comparator<IVector2> { @Override public int compare(final IVector2 o1, final IVector2 o2) { double len1 = o1.getLength2(); double len2 = o2.getLength2(); if (len1 < len2) { return -1; } if (len2 < len1) { return 1; } return 0; }  @Override int compare(final IVector2 o1, final IVector2 o2); }
VectorLengthComparator implements Comparator<IVector2> { @Override public int compare(final IVector2 o1, final IVector2 o2) { double len1 = o1.getLength2(); double len2 = o2.getLength2(); if (len1 < len2) { return -1; } if (len2 < len1) { return 1; } return 0; }  @Override int compare(final IVector2 o1, final IVector2 o2);  }