Skip to content

Commit

Permalink
NUMBERS-166: removing BiConsumer implementation from SortInPlace
Browse files Browse the repository at this point in the history
  • Loading branch information
darkma773r committed Jul 10, 2021
1 parent 4457bfd commit 4374325
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
Expand Up @@ -17,12 +17,11 @@

package org.apache.commons.numbers.arrays;

import java.util.Comparator;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Arrays;
import java.util.function.BiConsumer;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
* Sort an array and perform the same reordering of entries on other arrays.
Expand All @@ -32,14 +31,14 @@
* <li>{@code y = [1, 2, 3]}</li>
* <li>{@code z = [0, 5, 7]}</li>
* </ul>
* then {@code Sort.ASCENDING.accept(x, y, z)} will update those arrays:
* then {@code Sort.ASCENDING.apply(x, y, z)} will update those arrays:
* <ul>
* <li>{@code x = [1, 2, 3]}</li>
* <li>{@code y = [2, 3, 1]}</li>
* <li>{@code z = [5, 7, 0]}</li>
* </ul>
*/
public enum SortInPlace implements BiConsumer<double[], double[][]> {
public enum SortInPlace {
/** Sort in ascending order. */
ASCENDING((o1, o2) -> Double.compare(o1.key(), o2.key())),
/** Sort in descending order. */
Expand All @@ -64,9 +63,8 @@ public enum SortInPlace implements BiConsumer<double[], double[][]> {
* those performed on {@code x}.
* @throws IllegalArgumentException if not all arrays have the same size.
*/
@Override
public void accept(double[] x,
double[]... yList) {
public void apply(double[] x,
double[]... yList) {
final int yListLen = yList.length;
final int len = x.length;

Expand Down
Expand Up @@ -31,7 +31,7 @@ void testAscending() {
final double[] y = {4, 25, 9, 1, 16};
final double[] z = {8, -125, 27, 1, 64};

SortInPlace.ASCENDING.accept(x, y, z);
SortInPlace.ASCENDING.apply(x, y, z);

final double[] xE = {-3, 1, 2, 4, 5};
final double[] yE = {9, 1, 4, 16, 25};
Expand All @@ -48,7 +48,7 @@ void testDescending() {
final double[] y = {4, 25, 9, 1, 16};
final double[] z = {8, -125, 27, 1, 64};

SortInPlace.DESCENDING.accept(x, y, z);
SortInPlace.DESCENDING.apply(x, y, z);

final double[] xE = {5, 4, 2, 1, -3};
final double[] yE = {25, 16, 4, 1, 9};
Expand All @@ -66,7 +66,7 @@ void testJavadocExample() {
final double[] y = {1, 2, 3};
final double[] z = {0, 5, 7};

SortInPlace.ASCENDING.accept(x, y, z);
SortInPlace.ASCENDING.apply(x, y, z);

final double[] xE = {1, 2, 3};
final double[] yE = {2, 3, 1};
Expand All @@ -84,8 +84,8 @@ void testPreconditions() {
final double[] two = {1, 2};
final double[] onep = {2};

Assertions.assertThrows(IllegalArgumentException.class, () -> SortInPlace.ASCENDING.accept(one, two));
Assertions.assertThrows(NullPointerException.class, () -> SortInPlace.ASCENDING.accept(one, nullArray));
Assertions.assertThrows(NullPointerException.class, () -> SortInPlace.ASCENDING.accept(one, onep, nullArray));
Assertions.assertThrows(IllegalArgumentException.class, () -> SortInPlace.ASCENDING.apply(one, two));
Assertions.assertThrows(NullPointerException.class, () -> SortInPlace.ASCENDING.apply(one, nullArray));
Assertions.assertThrows(NullPointerException.class, () -> SortInPlace.ASCENDING.apply(one, onep, nullArray));
}
}

0 comments on commit 4374325

Please sign in to comment.