@Test public void testGetMaxAbsNumber() throws Exception { final IntMsdRadixSort sort = newSort(); assertEquals(Integer.valueOf(1), sort.getMaxAbsNumber(new Integer[]{1})); assertEquals(Integer.valueOf(2), sort.getMaxAbsNumber(new Integer[]{-2})); assertEquals(Integer.valueOf(Integer.MAX_VALUE), sort.getMaxAbsNumber(new Integer[]{Integer.MAX_VALUE, Integer.MIN_VALUE})); assertEquals(Integer.valueOf(Integer.MAX_VALUE), sort.getMaxAbsNumber(new Integer[]{Integer.MIN_VALUE})); assertEquals(Integer.valueOf(Integer.MAX_VALUE), sort.getMaxAbsNumber(new Integer[]{Integer.MIN_VALUE + 1})); assertEquals(Integer.valueOf(Integer.MAX_VALUE - 1), sort.getMaxAbsNumber(new Integer[]{Integer.MIN_VALUE + 2})); }
@Nonnull Integer getMaxAbsNumber(@Nonnull Integer[] numbers) { Integer maxAbsNumber = 0; for (Integer number : numbers) { if (number >= 0) { if (number > maxAbsNumber) { maxAbsNumber = number; } } else if (number == Integer.MIN_VALUE) { maxAbsNumber = Integer.MAX_VALUE; } else { if (-number > maxAbsNumber) { maxAbsNumber = -number; } } } return maxAbsNumber; }
IntMsdRadixSort implements ArrayNonComparisonSort<Integer> { @Nonnull Integer getMaxAbsNumber(@Nonnull Integer[] numbers) { Integer maxAbsNumber = 0; for (Integer number : numbers) { if (number >= 0) { if (number > maxAbsNumber) { maxAbsNumber = number; } } else if (number == Integer.MIN_VALUE) { maxAbsNumber = Integer.MAX_VALUE; } else { if (-number > maxAbsNumber) { maxAbsNumber = -number; } } } return maxAbsNumber; } }
IntMsdRadixSort implements ArrayNonComparisonSort<Integer> { @Nonnull Integer getMaxAbsNumber(@Nonnull Integer[] numbers) { Integer maxAbsNumber = 0; for (Integer number : numbers) { if (number >= 0) { if (number > maxAbsNumber) { maxAbsNumber = number; } } else if (number == Integer.MIN_VALUE) { maxAbsNumber = Integer.MAX_VALUE; } else { if (-number > maxAbsNumber) { maxAbsNumber = -number; } } } return maxAbsNumber; }  }
IntMsdRadixSort implements ArrayNonComparisonSort<Integer> { @Nonnull Integer getMaxAbsNumber(@Nonnull Integer[] numbers) { Integer maxAbsNumber = 0; for (Integer number : numbers) { if (number >= 0) { if (number > maxAbsNumber) { maxAbsNumber = number; } } else if (number == Integer.MIN_VALUE) { maxAbsNumber = Integer.MAX_VALUE; } else { if (-number > maxAbsNumber) { maxAbsNumber = -number; } } } return maxAbsNumber; }  @Override void sort(@Nonnull Integer[] numbers); }
IntMsdRadixSort implements ArrayNonComparisonSort<Integer> { @Nonnull Integer getMaxAbsNumber(@Nonnull Integer[] numbers) { Integer maxAbsNumber = 0; for (Integer number : numbers) { if (number >= 0) { if (number > maxAbsNumber) { maxAbsNumber = number; } } else if (number == Integer.MIN_VALUE) { maxAbsNumber = Integer.MAX_VALUE; } else { if (-number > maxAbsNumber) { maxAbsNumber = -number; } } } return maxAbsNumber; }  @Override void sort(@Nonnull Integer[] numbers);  }