ronantakizawa/codereview-bench huggingface dataset:
Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/maths/SecondMinMax.java (Java)

Code before:
        return secBest;
    }

    /**
     * @brief Finds the Second minimum / maximum value from the array
     * @param arr the input array
     * @exception IllegalArgumentException => if input array is of length less than 2 also if all elements are same
     * @return the second minimum / maximum value from the input array
     * @author Bharath Sanjeevi ( https://github.com/BharathSanjeeviT )
     */

    public static int findSecondMin(final int[] arr) {
        return secondBest(arr, Integer.MAX_VALUE, (a, b) -> a < b);
    }

    public static int findSecondMax(final int[] arr) {
        return secondBest(arr, Integer.MIN_VALUE, (a, b) -> a > b);
    }

    private static void checkInput(final int[] arr) {
        if (arr.length < 2) {
            throw new IllegalArgumentException("Input array must have length of at least two");
        }
    }

    private static void checkOutput(final int secNum, int initialVal) {
        if (secNum == initialVal) {
            throw new IllegalArgumentException("Input array should have at least 2 distinct elements");
        }
    }
}


Review comment (suggestion):
```suggestion
    private static void checkOutput(final int secNum, final int initialVal) {
```

Code after:
        checkOutput(secBest, initialVal);
        return secBest;
    }

    /**
     * @brief Finds the Second minimum / maximum value from the array
     * @param arr the input array
     * @exception IllegalArgumentException => if input array is of length less than 2 also if all elements are same
     * @return the second minimum / maximum value from the input array
     * @author Bharath Sanjeevi ( https://github.com/BharathSanjeeviT )
     */

    public static int findSecondMin(final int[] arr) {
        return secondBest(arr, Integer.MAX_VALUE, (a, b) -> a < b);
    }

    public static int findSecondMax(final int[] arr) {
        return secondBest(arr, Integer.MIN_VALUE, (a, b) -> a > b);
    }

    private static void checkInput(final int[] arr) {
        if (arr.length < 2) {
            throw new IllegalArgumentException("Input array must have length of at least two");
        }
    }

    private static void checkOutput(final int secNum, final int initialVal) {
        if (secNum == initialVal) {
            throw new IllegalArgumentException("Input array should have at least 2 distinct elements");
        }
    }
}
Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/strings/ReverseWordsInString.java (Java)

Code before:
package com.thealgorithms.strings;

import java.util.Arrays;
import java.util.Collections;

/**
 * Given an input string s, reverse the order of the words.
 * A word is defined as a sequence of non-space characters.
 * The words in s will be separated by at least one space.
 * Return a string of the words in reverse order concatenated by a single space.
 * Note that s may contain leading or trailing spaces or multiple spaces between two words.
 * The returned string should only have a single space separating the words.Do not include any extra spaces
 */

public final class ReverseWordsInString {

    private ReverseWordsInString() {
    }

    public static String reverseWordsInString(final String s) {
        var words = s.trim().split("\\s+");
        Collections.reverse(Arrays.asList(words));
        return String.join(" ", words);
    }
}


Review comment (suggestion):
Please update the description. Currently it is a description of the problem. Basically it could be removed.

Code after:
package com.thealgorithms.strings;

import java.util.Arrays;
import java.util.Collections;

public final class ReverseWordsInString {

    private ReverseWordsInString() {
    }

    /**
     * @brief Reverses words in the input string
     * @param s the input string
     * @return A string created by reversing the order of the words in {@code s}
     */

    public static String reverseWordsInString(final String s) {
        var words = s.trim().split("\\s+");
        Collections.reverse(Arrays.asList(words));
        return String.join(" ", words);
    }
}
Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/strings/ReverseWordsInString.java (Java)

Code before:
package com.thealgorithms.strings;

import java.util.Arrays;
import java.util.Collections;


public final class ReverseWordsInString {

    private ReverseWordsInString() {
    }

    /**
     * Reverse word in the string
     *
     * @param s contains sentence
       @return Reverse word of {@code s}
     */

    public static String reverseWordsInString(final String s) {
        var words = s.trim().split("\\s+");
        Collections.reverse(Arrays.asList(words));
        return String.join(" ", words);
    }
}


Review comment (suggestion):
```suggestion
     * @brief Reverses words in the input string
```

Code after:
package com.thealgorithms.strings;

import java.util.Arrays;
import java.util.Collections;

public final class ReverseWordsInString {

    private ReverseWordsInString() {
    }

    /**
     * @brief Reverses words in the input string
     * @param s the input string
     * @return A string created by reversing the order of the words in {@code s}
     */

    public static String reverseWordsInString(final String s) {
        var words = s.trim().split("\\s+");
        Collections.reverse(Arrays.asList(words));
        return String.join(" ", words);
    }
}
Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/strings/ReverseWordsInString.java (Java)

Code before:
package com.thealgorithms.strings;

import java.util.Arrays;
import java.util.Collections;


public final class ReverseWordsInString {

    private ReverseWordsInString() {
    }

    /**
     * Reverse word in the string
     *
     * @param s contains sentence
       @return Reverse word of {@code s}
     */

    public static String reverseWordsInString(final String s) {
        var words = s.trim().split("\\s+");
        Collections.reverse(Arrays.asList(words));
        return String.join(" ", words);
    }
}


Review comment (suggestion):
```suggestion
     * @param s the input string
```

Code after:
package com.thealgorithms.strings;

import java.util.Arrays;
import java.util.Collections;

public final class ReverseWordsInString {

    private ReverseWordsInString() {
    }

    /**
     * @brief Reverses words in the input string
     * @param s the input string
     * @return A string created by reversing the order of the words in {@code s}
     */

    public static String reverseWordsInString(final String s) {
        var words = s.trim().split("\\s+");
        Collections.reverse(Arrays.asList(words));
        return String.join(" ", words);
    }
}
Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/strings/ReverseWordsInString.java (Java)

Code before:
package com.thealgorithms.strings;

import java.util.Arrays;
import java.util.Collections;


public final class ReverseWordsInString {

    private ReverseWordsInString() {
    }

    /**
     * Reverse word in the string
     *
     * @param s contains sentence
       @return Reverse word of {@code s}
     */

    public static String reverseWordsInString(final String s) {
        var words = s.trim().split("\\s+");
        Collections.reverse(Arrays.asList(words));
        return String.join(" ", words);
    }
}


Review comment (suggestion):
```suggestion
       * @return A string created by reversing the order of the words in{@code s}
```

Code after:
package com.thealgorithms.strings;

import java.util.Arrays;
import java.util.Collections;

public final class ReverseWordsInString {

    private ReverseWordsInString() {
    }

    /**
     * @brief Reverses words in the input string
     * @param s the input string
     * @return A string created by reversing the order of the words in {@code s}
     */

    public static String reverseWordsInString(final String s) {
        var words = s.trim().split("\\s+");
        Collections.reverse(Arrays.asList(words));
        return String.join(" ", words);
    }
}
Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/strings/ReverseWordsInString.java (Java)

Code before:
package com.thealgorithms.strings;

import java.util.Arrays;
import java.util.Collections;

public final class ReverseWordsInString {

    private ReverseWordsInString() {
    }

    /**
     * @brief Reverses words in the input string
     * @param s the input string
     * @return A string created by reversing the order of the words in{@code s}
     */

    public static String reverseWordsInString(final String s) {
        var words = s.trim().split("\\s+");
        Collections.reverse(Arrays.asList(words));
        return String.join(" ", words);
    }
}


Review comment (suggestion):
```suggestion
     * @return A string created by reversing the order of the words in {@code s}
```

Code after:
package com.thealgorithms.strings;

import java.util.Arrays;
import java.util.Collections;

public final class ReverseWordsInString {

    private ReverseWordsInString() {
    }

    /**
     * @brief Reverses words in the input string
     * @param s the input string
     * @return A string created by reversing the order of the words in {@code s}
     */

    public static String reverseWordsInString(final String s) {
        var words = s.trim().split("\\s+");
        Collections.reverse(Arrays.asList(words));
        return String.join(" ", words);
    }
}
Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/misc/MirrorOfMatrix.java (Java)

Code before:
package com.thealgorithms.misc;

import java.util.Scanner;

// Problem Statement
/*
We have given an array of m x n (where m is the number of rows and n is the number of columns).
Print the new matrix in such a way that the new matrix is the mirror image of the original matrix.

The Original matrix is:   |   The Mirror matrix is:
1	2	3	              |   3	 2	 1
4	5	6	              |   6	 5	 4
7	8	9	              |   9	 8	 7

@author - Aman (https://github.com/Aman28801)
*/
public class MirrorOfMatrix {

    // Function Mirror that is used to mirror the Matrix
    public static void Mirror(int[][] arr) {

        for (int i = 0; i < arr.length; i++) {
            int li = 0;
            int hi = arr[i].length - 1;
            while (li < hi) {
                int temp = arr[i][li];
                arr[i][li] = arr[i][hi];
                arr[i][hi] = temp;

                li++;
                hi--;
            }
        }
        // For printing the output of Code OR Mirror Image of Matrix
        System.out.println("The Mirror matrix is:");
        for (int[] ints : arr) {
            for (int j = 0; j < arr[0].length; j++) {
                System.out.print(ints[j] + "\t");
            }
            System.out.println();
        }
    }

Review comment (refactor):
Please make it a _proper utility class_.

```suggestion
public final class MirrorOfMatrix {
    private MirrorOfMatrix() {
    }
```

Code after:
package com.thealgorithms.misc;

// Problem Statement
/*
We have given an array of m x n (where m is the number of rows and n is the number of columns).
Print the new matrix in such a way that the new matrix is the mirror image of the original matrix.

The Original matrix is:   |   The Mirror matrix is:
1	2	3	              |   3	 2	 1
4	5	6	              |   6	 5	 4
7	8	9	              |   9	 8	 7

@author - Aman (https://github.com/Aman28801)
*/

public final class MirrorOfMatrix {
    private MirrorOfMatrix() {
    }

    public static int[][] mirrorMatrix(final int[][] originalMatrix) {
        if (originalMatrix == null) {
            // Handle invalid input
            return null;
        }
        if (originalMatrix.length == 0) {
            return new int[0][0];
        }

        checkInput(originalMatrix);

        int numRows = originalMatrix.length;
        int numCols = originalMatrix[0].length;

        int[][] mirroredMatrix = new int[numRows][numCols];

        for (int i = 0; i < numRows; i++) {
            mirroredMatrix[i] = reverseRow(originalMatrix[i]);
        }
        return mirroredMatrix;
    }
    private static int[] reverseRow(final int[] inRow) {
        int[] res = new int[inRow.length];
Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/misc/MirrorOfMatrix.java (Java)

Code before:
package com.thealgorithms.misc;

import java.util.Scanner;

// Problem Statement
/*
We have given an array of m x n (where m is the number of rows and n is the number of columns).
Print the new matrix in such a way that the new matrix is the mirror image of the original matrix.

The Original matrix is:   |   The Mirror matrix is:
1	2	3	              |   3	 2	 1
4	5	6	              |   6	 5	 4
7	8	9	              |   9	 8	 7

@author - Aman (https://github.com/Aman28801)
*/

public final class MirrorOfMatrix {
    private MirrorOfMatrix() {
    }
    // Function Mirror that is used to mirror the Matrix
    public static void Mirror(final int[][] arr) {

        for (int i = 0; i < arr.length; i++) {
            int li = 0;
            int hi = arr[i].length - 1;
            while (li < hi) {
                int temp = arr[i][li];
                arr[i][li] = arr[i][hi];
                arr[i][hi] = temp;

                li++;
                hi--;
            }
        }
        // For printing the output of Code OR Mirror Image of Matrix
        System.out.println("The Mirror matrix is:");
        for (int[] ints : arr) {
            for (int j = 0; j < arr[0].length; j++) {

Review comment (suggestion):
Please update the description of the problem. Try to explain in what sentence what your method does.

Code after:
package com.thealgorithms.misc;

// Problem Statement
/*
We have given an array of m x n (where m is the number of rows and n is the number of columns).
Print the new matrix in such a way that the new matrix is the mirror image of the original matrix.

The Original matrix is:   |   The Mirror matrix is:
1	2	3	              |   3	 2	 1
4	5	6	              |   6	 5	 4
7	8	9	              |   9	 8	 7

@author - Aman (https://github.com/Aman28801)
*/

public final class MirrorOfMatrix {
    private MirrorOfMatrix() {
    }

    public static int[][] mirrorMatrix(final int[][] originalMatrix) {
        if (originalMatrix == null) {
            // Handle invalid input
            return null;
        }
        if (originalMatrix.length == 0) {
            return new int[0][0];
        }

        checkInput(originalMatrix);

        int numRows = originalMatrix.length;
        int numCols = originalMatrix[0].length;

        int[][] mirroredMatrix = new int[numRows][numCols];

        for (int i = 0; i < numRows; i++) {
            mirroredMatrix[i] = reverseRow(originalMatrix[i]);
        }
        return mirroredMatrix;
Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/misc/MirrorOfMatrix.java (Java)

Code before:

The Original matrix is:   |   The Mirror matrix is:
1	2	3	              |   3	 2	 1
4	5	6	              |   6	 5	 4
7	8	9	              |   9	 8	 7

@author - Aman (https://github.com/Aman28801)
*/

public final class MirrorOfMatrix {
    private MirrorOfMatrix() {
    }
    public static int[][] mirrorMatrix(int[][] originalMatrix) {
        if (originalMatrix == null || originalMatrix.length == 0) {
            // Handle invalid input
            return null;
        }
        int numRows = originalMatrix.length;
        int numCols = originalMatrix[0].length;

        int[][] mirroredMatrix = new int[numRows][numCols];

        for (int i = 0; i < numRows; i++) {
            for (int j = 0; j < numCols; j++) {
                // Copy elements from the original matrix in reverse order
                mirroredMatrix[i][j] = originalMatrix[i][numCols - 1 - j];
            }
        }
        return mirroredMatrix;
    }
}


Review comment (suggestion):
This could be moved into a separate method like `reverseRow`.

Code after:
1	2	3	              |   3	 2	 1
4	5	6	              |   6	 5	 4
7	8	9	              |   9	 8	 7

@author - Aman (https://github.com/Aman28801)
*/

public final class MirrorOfMatrix {
    private MirrorOfMatrix() {
    }

    public static int[][] mirrorMatrix(final int[][] originalMatrix) {
        if (originalMatrix == null) {
            // Handle invalid input
            return null;
        }
        if (originalMatrix.length == 0) {
            return new int[0][0];
        }

        checkInput(originalMatrix);

        int numRows = originalMatrix.length;
        int numCols = originalMatrix[0].length;

        int[][] mirroredMatrix = new int[numRows][numCols];

        for (int i = 0; i < numRows; i++) {
            mirroredMatrix[i] = reverseRow(originalMatrix[i]);
        }
        return mirroredMatrix;
    }
    private static int[] reverseRow(final int[] inRow) {
        int[] res = new int[inRow.length];
        for (int i = 0; i < inRow.length; ++i) {
            res[i] = inRow[inRow.length - 1 - i];
        }
        return res;
    }

    private static void checkInput(final int[][] matrix) {
        // Check if all rows have the same number of columns
        for (int i = 1; i < matrix.length; i++) {
            if (matrix[i].length != matrix[0].length) {
                throw new IllegalArgumentException("The input is not a matrix.");
            }
        }
    }
}
Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/misc/MirrorOfMatrix.java (Java)

Code before:
package com.thealgorithms.misc;

// Problem Statement
/*
We have given an array of m x n (where m is the number of rows and n is the number of columns).
Print the new matrix in such a way that the new matrix is the mirror image of the original matrix.

The Original matrix is:   |   The Mirror matrix is:
1	2	3	              |   3	 2	 1
4	5	6	              |   6	 5	 4
7	8	9	              |   9	 8	 7

@author - Aman (https://github.com/Aman28801)
*/

public final class MirrorOfMatrix {
    private MirrorOfMatrix() {
    }
    public static int[][] mirrorMatrix(int[][] originalMatrix) {
        if (originalMatrix == null || originalMatrix.length == 0) {
            // Handle invalid input
            return new int[0][0];
        }
        int numRows = originalMatrix.length;
        int numCols = originalMatrix[0].length;

        int[][] mirroredMatrix = new int[numRows][numCols];

        for (int i = 0; i < numRows; i++) {
            for (int j = 0; j < numCols; j++) {
                // Copy elements from the original matrix in reverse order
                mirroredMatrix[i][j] = originalMatrix[i][numCols - 1 - j];
            }
        }
        return mirroredMatrix;
    }
}


Review comment (suggestion):
If the `orginalMatrix` is `null` returning `null` makes sense.

Code after:
package com.thealgorithms.misc;

// Problem Statement
/*
We have given an array of m x n (where m is the number of rows and n is the number of columns).
Print the new matrix in such a way that the new matrix is the mirror image of the original matrix.

The Original matrix is:   |   The Mirror matrix is:
1	2	3	              |   3	 2	 1
4	5	6	              |   6	 5	 4
7	8	9	              |   9	 8	 7

@author - Aman (https://github.com/Aman28801)
*/

public final class MirrorOfMatrix {
    private MirrorOfMatrix() {
    }

    public static int[][] mirrorMatrix(final int[][] originalMatrix) {
        if (originalMatrix == null) {
            // Handle invalid input
            return null;
        }
        if (originalMatrix.length == 0) {
            return new int[0][0];
        }

        checkInput(originalMatrix);

        int numRows = originalMatrix.length;
        int numCols = originalMatrix[0].length;

        int[][] mirroredMatrix = new int[numRows][numCols];

        for (int i = 0; i < numRows; i++) {
            mirroredMatrix[i] = reverseRow(originalMatrix[i]);
        }
        return mirroredMatrix;
    }
    private static int[] reverseRow(final int[] inRow) {
        int[] res = new int[inRow.length];
        for (int i = 0; i < inRow.length; ++i) {
            res[i] = inRow[inRow.length - 1 - i];
        }
        return res;
    }
Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/misc/MirrorOfMatrix.java (Java)

Code before:
The Original matrix is:   |   The Mirror matrix is:
1	2	3	              |   3	 2	 1
4	5	6	              |   6	 5	 4
7	8	9	              |   9	 8	 7

@author - Aman (https://github.com/Aman28801)
*/

public final class MirrorOfMatrix {
    private MirrorOfMatrix() {
    }
    public static int[][] mirrorMatrix(int[][] originalMatrix) {
        if (originalMatrix == null || originalMatrix.length == 0) {
            // Handle invalid input
            return new int[0][0];
        }
        int numRows = originalMatrix.length;
        int numCols = originalMatrix[0].length;

        int[][] mirroredMatrix = new int[numRows][numCols];

        for (int i = 0; i < numRows; i++) {
            for (int j = 0; j < numCols; j++) {
                // Copy elements from the original matrix in reverse order
                mirroredMatrix[i][j] = originalMatrix[i][numCols - 1 - j];
            }
        }
        return mirroredMatrix;
    }
}


Review comment (suggestion):
```suggestion
            mirroredMatrix[i] = reverseRow(originalMatrix[i]);
```
with:
```java
    private static int[] reverseRow(final int[] inRow) {
        int[] res = new int[inRow.length];
        for (int i = 0; i < inRow.length; ++i) {
            res[i] = inRow[inRow.length - 1 - i];
        }
        return res;
    }
```
The advantage is that if someone reads `mirroredMatrix[iRow] = reverseRow(originalMatrix[iRow]);` it is clear from the method name what happens there.

Code after:
The Original matrix is:   |   The Mirror matrix is:
1	2	3	              |   3	 2	 1
4	5	6	              |   6	 5	 4
7	8	9	              |   9	 8	 7

@author - Aman (https://github.com/Aman28801)
*/

public final class MirrorOfMatrix {
    private MirrorOfMatrix() {
    }

    public static int[][] mirrorMatrix(final int[][] originalMatrix) {
        if (originalMatrix == null) {
            // Handle invalid input
            return null;
        }
        if (originalMatrix.length == 0) {
            return new int[0][0];
        }

        checkInput(originalMatrix);

        int numRows = originalMatrix.length;
        int numCols = originalMatrix[0].length;

        int[][] mirroredMatrix = new int[numRows][numCols];

        for (int i = 0; i < numRows; i++) {
            mirroredMatrix[i] = reverseRow(originalMatrix[i]);
        }
        return mirroredMatrix;
    }
    private static int[] reverseRow(final int[] inRow) {
        int[] res = new int[inRow.length];
        for (int i = 0; i < inRow.length; ++i) {
            res[i] = inRow[inRow.length - 1 - i];
        }
        return res;
    }

    private static void checkInput(final int[][] matrix) {
        // Check if all rows have the same number of columns
        for (int i = 1; i < matrix.length; i++) {
            if (matrix[i].length != matrix[0].length) {
                throw new IllegalArgumentException("The input is not a matrix.");
            }
        }
    }
}