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

Code before:
package com.thealgorithms.maths;

/**
 * Wikipedia for HeronsFormula => https://en.wikipedia.org/wiki/Heron%27s_formula
 * Find the area of a triangle using only side lengths
 */

public final class HeronsFormula {

    /*
     * A function to get the Area of a Triangle using Heron's Formula
     * @param s1,s2,s3 => the three sides of the Triangle
     * @return area using the formula (√(s(s – s1)(s – s2)(s – s3)))
     * here s is called semi-perimeter and it is the half of the perimeter (i.e; s = (s1+s2+s3)/2)
     * @author satyabarghav
     */
    private HeronsFormula() {
    }
    public static double Herons(final double a, final double b, final double c) {
        if (!(a + b > c && b + c > a && c + a > b)) {
            throw new IllegalArgumentException("Triangle can't be formed with the given side lengths");
        } else {
            final double s = (a + b + c) / 2.0;
            return Math.sqrt((s) * (s - a) * (s - b) * (s - c));
        }
    }
}


Review comment (suggestion):
```suggestion
        }
        final double s = (a + b + c) / 2.0;
        return Math.sqrt((s) * (s - a) * (s - b) * (s - c));
```

Code after:
package com.thealgorithms.maths;

/**
 * Wikipedia for HeronsFormula => https://en.wikipedia.org/wiki/Heron%27s_formula
 * Find the area of a triangle using only side lengths
 */

public final class HeronsFormula {

    /*
     * A function to get the Area of a Triangle using Heron's Formula
     * @param s1,s2,s3 => the three sides of the Triangle
     * @return area using the formula (√(s(s – s1)(s – s2)(s – s3)))
     * here s is called semi-perimeter and it is the half of the perimeter (i.e; s = (s1+s2+s3)/2)
     * @author satyabarghav
     */
    private HeronsFormula() {
    }

    private static boolean areAllSidesPositive(final double a, final double b, final double c) {
        return a > 0 && b > 0 && c > 0;
    }

    private static boolean canFormTriangle(final double a, final double b, final double c) {
        return a + b > c && b + c > a && c + a > b;
    }

    public static double herons(final double a, final double b, final double c) {
        if (!areAllSidesPositive(a, b, c) || !canFormTriangle(a, b, c)) {
            throw new IllegalArgumentException("Triangle can't be formed with the given side lengths");
        }
        final double s = (a + b + c) / 2.0;
        return Math.sqrt((s) * (s - a) * (s - b) * (s - c));
    }
}
Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/maths/HeronsFormula.java (Java)

Code before:
package com.thealgorithms.maths;

/**
 * Wikipedia for HeronsFormula => https://en.wikipedia.org/wiki/Heron%27s_formula
 * Find the area of a triangle using only side lengths
 */

public final class HeronsFormula {

    /*
     * A function to get the Area of a Triangle using Heron's Formula
     * @param s1,s2,s3 => the three sides of the Triangle
     * @return area using the formula (√(s(s – s1)(s – s2)(s – s3)))
     * here s is called semi-perimeter and it is the half of the perimeter (i.e; s = (s1+s2+s3)/2)
     * @author satyabarghav
     */
    private HeronsFormula() {
    }
    public static double Herons(final double a, final double b, final double c) {
        if (!(a + b > c && b + c > a && c + a > b)) {
            throw new IllegalArgumentException("Triangle can't be formed with the given side lengths");
        } else {
            final double s = (a + b + c) / 2.0;
            return Math.sqrt((s) * (s - a) * (s - b) * (s - c));
        }
    }
}


Review comment (suggestion):
Using this opportunity, I would suggest to rename the method to start with the _small_ `h`.

```suggestion
    public static double herons(final double a, final double b, final double c) {
```

Code after:
package com.thealgorithms.maths;

/**
 * Wikipedia for HeronsFormula => https://en.wikipedia.org/wiki/Heron%27s_formula
 * Find the area of a triangle using only side lengths
 */

public final class HeronsFormula {

    /*
     * A function to get the Area of a Triangle using Heron's Formula
     * @param s1,s2,s3 => the three sides of the Triangle
     * @return area using the formula (√(s(s – s1)(s – s2)(s – s3)))
     * here s is called semi-perimeter and it is the half of the perimeter (i.e; s = (s1+s2+s3)/2)
     * @author satyabarghav
     */
    private HeronsFormula() {
    }

    private static boolean areAllSidesPositive(final double a, final double b, final double c) {
        return a > 0 && b > 0 && c > 0;
    }

    private static boolean canFormTriangle(final double a, final double b, final double c) {
        return a + b > c && b + c > a && c + a > b;
    }

    public static double herons(final double a, final double b, final double c) {
        if (!areAllSidesPositive(a, b, c) || !canFormTriangle(a, b, c)) {
            throw new IllegalArgumentException("Triangle can't be formed with the given side lengths");
        }
        final double s = (a + b + c) / 2.0;
        return Math.sqrt((s) * (s - a) * (s - b) * (s - c));
    }
}
Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/maths/HeronsFormula.java (Java)

Code before:
package com.thealgorithms.maths;

/**
 * Wikipedia for HeronsFormula => https://en.wikipedia.org/wiki/Heron%27s_formula
 * Find the area of a triangle using only side lengths
 */

public final class HeronsFormula {

    /*
     * A function to get the Area of a Triangle using Heron's Formula
     * @param s1,s2,s3 => the three sides of the Triangle
     * @return area using the formula (√(s(s – s1)(s – s2)(s – s3)))
     * here s is called semi-perimeter and it is the half of the perimeter (i.e; s = (s1+s2+s3)/2)
     * @author satyabarghav
     */
    private HeronsFormula() {
    }
    public static double Herons(final double a, final double b, final double c) {
        if (!(a + b > c && b + c > a && c + a > b)) {
            throw new IllegalArgumentException("Triangle can't be formed with the given side lengths");
        } else {
            final double s = (a + b + c) / 2.0;
            return Math.sqrt((s) * (s - a) * (s - b) * (s - c));
        }
    }
}


Review comment (suggestion):
This `else` block is not needed.

```suggestion
        }
        final double s = (a + b + c) / 2.0;
        return Math.sqrt((s) * (s - a) * (s - b) * (s - c));
```

Code after:
package com.thealgorithms.maths;

/**
 * Wikipedia for HeronsFormula => https://en.wikipedia.org/wiki/Heron%27s_formula
 * Find the area of a triangle using only side lengths
 */

public final class HeronsFormula {

    /*
     * A function to get the Area of a Triangle using Heron's Formula
     * @param s1,s2,s3 => the three sides of the Triangle
     * @return area using the formula (√(s(s – s1)(s – s2)(s – s3)))
     * here s is called semi-perimeter and it is the half of the perimeter (i.e; s = (s1+s2+s3)/2)
     * @author satyabarghav
     */
    private HeronsFormula() {
    }

    private static boolean areAllSidesPositive(final double a, final double b, final double c) {
        return a > 0 && b > 0 && c > 0;
    }

    private static boolean canFormTriangle(final double a, final double b, final double c) {
        return a + b > c && b + c > a && c + a > b;
    }

    public static double herons(final double a, final double b, final double c) {
        if (!areAllSidesPositive(a, b, c) || !canFormTriangle(a, b, c)) {
            throw new IllegalArgumentException("Triangle can't be formed with the given side lengths");
        }
        final double s = (a + b + c) / 2.0;
        return Math.sqrt((s) * (s - a) * (s - b) * (s - c));
    }
}
Repository: TheAlgorithms/Java
File: src/test/java/com/thealgorithms/maths/MinValueTest.java (Java)

Code before:
package com.thealgorithms.maths;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

public class MinValueTest {
    @Test
    public void flipBitTest() {
        assertEquals(-1, MinValue.min(-1, 3));
        assertEquals(2, MinValue.min(3, 2));
    }
}


Review comment (suggestion):
```suggestion
        assertEquals(5, MinValue.min(5, 5));
    }
```

Code after:
package com.thealgorithms.maths;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

public class MinValueTest {
    @Test
    public void minTest() {
        assertEquals(-1, MinValue.min(-1, 3));
        assertEquals(2, MinValue.min(3, 2));
        assertEquals(5, MinValue.min(5, 5));
    }
}
Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/maths/MinValue.java (Java)

Code before:
package com.thealgorithms.maths;

public class MinValue {
    /**
     * Returns the smaller of two {@code int} values. That is, the result the
     * argument closer to the value of {@link Integer#MIN_VALUE}. If the
     * arguments have the same value, the result is that same value.
     *
     * @param a an argument.
     * @param b another argument.
     * @return the smaller of {@code a} and {@code b}.
     */
    public static int min(int a, int b) {
        return a <= b ? a : b;
    }
}


Review comment (suggestion):
```suggestion
public final class MinValue {
    private MinValue() {
    }
```

Code after:
package com.thealgorithms.maths;

public final class MinValue {
    private MinValue() {
    }
    /**
     * Returns the smaller of two {@code int} values. That is, the result the
     * argument closer to the value of {@link Integer#MIN_VALUE}. If the
     * arguments have the same value, the result is that same value.
     *
     * @param a an argument.
     * @param b another argument.
     * @return the smaller of {@code a} and {@code b}.
     */
    public static int min(int a, int b) {
        return a <= b ? a : b;
    }
}
Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/bitmanipulation/BitSwap.java (Java)

Code before:
package com.thealgorithms.bitmanipulation;

public final class BitSwap {
    private BitSwap() {
    }
    /*
     * Swaps the bits at the position swap1 and swap2 from bit
     */
    public static int bitSwap(int bit, int swap1, int swap2) {
        int val1 = (bit >> swap1) & 1;
        int val2 = (bit >> swap2) & 1;

        if (val1 != val2) {
            bit = bit ^ (1 << swap1);
            bit = bit ^ (1 << swap2);
        }
        return bit;
    }
}


Review comment (suggestion):
```suggestion
    public static int bitSwap(int data, final int posA, final int posB) {
```

Code after:
package com.thealgorithms.bitmanipulation;

public final class BitSwap {
    private BitSwap() {
    }
    /*
     * @brief Swaps the bits at the position posA and posB from data
     */
    public static int bitSwap(int data, final int posA, final int posB) {
        if (SingleBitOperations.getBit(data, posA) != SingleBitOperations.getBit(data, posB)) {
            data ^= (1 << posA) ^ (1 << posB);
        }
        return data;
    }
}
Repository: TheAlgorithms/Java
File: src/test/java/com/thealgorithms/bitmanipulation/BitSwapTest.java (Java)

Code before:
package com.thealgorithms.bitmanipulation;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;
public class BitSwapTest {
    @Test
    void testHighestSetBit() {
        assertEquals(3, BitSwap.bitSwap(3, 0, 1));
        assertEquals(5, BitSwap.bitSwap(6, 0, 1));
    }
}


Review comment (suggestion):
I would suggest to add a test case with equal positions.

```suggestion
        assertEquals(5, BitSwap.bitSwap(6, 0, 1));
        assertEquals(7, BitSwap.bitSwap(7, 1, 1));
    }
```

Code after:
package com.thealgorithms.bitmanipulation;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;
public class BitSwapTest {
    @Test
    void testHighestSetBit() {
        assertEquals(3, BitSwap.bitSwap(3, 0, 1));
        assertEquals(5, BitSwap.bitSwap(6, 0, 1));
        assertEquals(7, BitSwap.bitSwap(7, 1, 1));
    }
}
Repository: TheAlgorithms/Java
File: src/test/java/com/thealgorithms/bitmanipulation/BitSwapTest.java (Java)

Code before:
package com.thealgorithms.bitmanipulation;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;
public class BitSwapTest {
    @Test
    void testHighestSetBit() {
        assertEquals(3, BitSwap.bitSwap(3, 0, 1));
        assertEquals(5, BitSwap.bitSwap(6, 0, 1));
        assertEquals(7, BitSwap.bitSwap(7, 1, 1));
    }
}


Review comment (suggestion):
```suggestion
import static org.junit.jupiter.api.Assertions.assertEquals;
```

Code after:
package com.thealgorithms.bitmanipulation;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;
public class BitSwapTest {
    @Test
    void testHighestSetBit() {
        assertEquals(3, BitSwap.bitSwap(3, 0, 1));
        assertEquals(5, BitSwap.bitSwap(6, 0, 1));
        assertEquals(7, BitSwap.bitSwap(7, 1, 1));
    }
}
Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/bitmanipulation/BitSwap.java (Java)

Code before:
package com.thealgorithms.bitmanipulation;

public final class BitSwap {
    private BitSwap() {
    }
    /*
     * Swaps the bits at the position swap1 and swap2 from bit
     */
    public static int bitSwap(int data, final int posA, final int posB) {

        if (SingleBitOperations.getBit(data, posA) != SingleBitOperations.getBit(data, posB)) {
            data = data ^ (1 << posA);
            data = data ^ (1 << posB);
        }
        return data;
    }
}


Review comment (suggestion):
```suggestion
     * @brief Swaps the bits at the position posA and posB from data
```

Code after:
package com.thealgorithms.bitmanipulation;

public final class BitSwap {
    private BitSwap() {
    }
    /*
     * @brief Swaps the bits at the position posA and posB from data
     */
    public static int bitSwap(int data, final int posA, final int posB) {
        if (SingleBitOperations.getBit(data, posA) != SingleBitOperations.getBit(data, posB)) {
            data ^= (1 << posA) ^ (1 << posB);
        }
        return data;
    }
}
Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/others/BoyerMoore.java (Java)

Code before:
/* this Code is the illustration of Boyer moore's voting algorithm to
find the majority element is an array that appears more than n/2 times in an array
where "n" is the length of the array.
For more information on the algorithm refer
https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_majority_vote_algorithm
 */
package com.thealgorithms.others;
import java.util.Optional;

public final class BoyerMoore {
    private BoyerMoore() {
    }

    public static Optional<Integer> findMajor(final int[] a) {
        int candidate = findCandidate(a);
        int count = countOccurrences(a, candidate);
        
        if (count > (a.length / 2)) {
            return Optional.of(candidate);
        }
        
        return Optional.empty();
    }


    
    private static int findCandidate(final int[] a) {
        int count = 0;
        int candidate = -1;
        for (final int k : a) {
            if (count == 0) {
                candidate = k;
                count = 1;
            } else {
                if (k == candidate) {
                    count++;
                } else {
                    count--;
                }
            }
        }

Review comment (suggestion):
```suggestion
        final var candidate = findCandidate(a);
        final var count = countOccurrences(a, candidate);
```

Code after:
/* this Code is the illustration of Boyer moore's voting algorithm to
find the majority element is an array that appears more than n/2 times in an array
where "n" is the length of the array.
For more information on the algorithm refer
https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_majority_vote_algorithm
 */
package com.thealgorithms.others;
import java.util.Optional;

public final class BoyerMoore {
    private BoyerMoore() {
    }

    public static Optional<Integer> findMajor(final int[] a) {
        final var candidate = findCandidate(a);
        final var count = countOccurrences(candidate, a);
        if (isMajority(count, a.length)) {
            return Optional.of(candidate);
        }
        return Optional.empty();
    }

    private static int findCandidate(final int[] a) {
        int count = 0;
        int candidate = -1;
        for (final var k : a) {
            if (count == 0) {
                candidate = k;
                count = 1;
            } else {
                if (k == candidate) {
                    count++;
                } else {
                    count--;
                }
            }
        }
        return candidate;
    }

    private static int countOccurrences(final int candidate, final int[] a) {
Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/others/BoyerMoore.java (Java)

Code before:
/* this Code is the illustration of Boyer moore's voting algorithm to
find the majority element is an array that appears more than n/2 times in an array
where "n" is the length of the array.
For more information on the algorithm refer
https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_majority_vote_algorithm
 */
package com.thealgorithms.others;
import java.util.Optional;

public final class BoyerMoore {
    private BoyerMoore() {
    }

    public static Optional<Integer> findMajor(final int[] a) {
        int candidate = findCandidate(a);
        int count = countOccurrences(a, candidate);
        
        if (count > (a.length / 2)) {
            return Optional.of(candidate);
        }
        
        return Optional.empty();
    }


    
    private static int findCandidate(final int[] a) {
        int count = 0;
        int candidate = -1;
        for (final int k : a) {
            if (count == 0) {
                candidate = k;
                count = 1;
            } else {
                if (k == candidate) {
                    count++;
                } else {
                    count--;
                }
            }
        }
        return candidate;
    }

    private static int countOccurrences(final int[] a, int candidate) {
        int count = 0;
        for (final int j : a) {
            if (j == candidate) {
                count++;
            }
        }

Review comment (suggestion):
This should fix clang-tidy warning.
```suggestion
```

Code after:
/* this Code is the illustration of Boyer moore's voting algorithm to
find the majority element is an array that appears more than n/2 times in an array
where "n" is the length of the array.
For more information on the algorithm refer
https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_majority_vote_algorithm
 */
package com.thealgorithms.others;
import java.util.Optional;

public final class BoyerMoore {
    private BoyerMoore() {
    }

    public static Optional<Integer> findMajor(final int[] a) {
        final var candidate = findCandidate(a);
        final var count = countOccurrences(candidate, a);
        if (isMajority(count, a.length)) {
            return Optional.of(candidate);
        }
        return Optional.empty();
    }

    private static int findCandidate(final int[] a) {
        int count = 0;
        int candidate = -1;
        for (final var k : a) {
            if (count == 0) {
                candidate = k;
                count = 1;
            } else {
                if (k == candidate) {
                    count++;
                } else {
                    count--;
                }
            }
        }
        return candidate;
    }

    private static int countOccurrences(final int candidate, final int[] a) {
        int count = 0;
        for (final var j : a) {
            if (j == candidate) {
                count++;
            }
        }
        return count;
    }

    private static boolean isMajority(final int count, final int totalCount) {
Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/others/BoyerMoore.java (Java)

Code before:
        }
        
        return Optional.empty();
    }


    
    private static int findCandidate(final int[] a) {
        int count = 0;
        int candidate = -1;
        for (final int k : a) {
            if (count == 0) {
                candidate = k;
                count = 1;
            } else {
                if (k == candidate) {
                    count++;
                } else {
                    count--;
                }
            }
        }
        return candidate;
    }

    private static int countOccurrences(final int[] a, int candidate) {
        int count = 0;
        for (final int j : a) {
            if (j == candidate) {
                count++;
            }
        }
        return count;
    }

}


Review comment (suggestion):
I would swap the arguments here. And make them final.
```suggestion
    private static int countOccurrences(final int candidate, final int[] a) {
```

Code after:
        return Optional.empty();
    }

    private static int findCandidate(final int[] a) {
        int count = 0;
        int candidate = -1;
        for (final var k : a) {
            if (count == 0) {
                candidate = k;
                count = 1;
            } else {
                if (k == candidate) {
                    count++;
                } else {
                    count--;
                }
            }
        }
        return candidate;
    }

    private static int countOccurrences(final int candidate, final int[] a) {
        int count = 0;
        for (final var j : a) {
            if (j == candidate) {
                count++;
            }
        }
        return count;
    }

    private static boolean isMajority(final int count, final int totalCount) {
        return 2 * count > totalCount;
    }
}
Repository: TheAlgorithms/Java
File: src/main/java/com/thealgorithms/others/BoyerMoore.java (Java)

Code before:
        return Optional.empty();
    }


    
    private static int findCandidate(final int[] a) {
        int count = 0;
        int candidate = -1;
        for (final int k : a) {
            if (count == 0) {
                candidate = k;
                count = 1;
            } else {
                if (k == candidate) {
                    count++;
                } else {
                    count--;
                }
            }
        }
        return candidate;
    }

    private static int countOccurrences(final int[] a, int candidate) {
        int count = 0;
        for (final int j : a) {
            if (j == candidate) {
                count++;
            }
        }
        return count;
    }

}


Review comment (suggestion):
Is it important that `j` is an `int`?

```suggestion
        for (final var j : a) {
```

Code after:

    private static int findCandidate(final int[] a) {
        int count = 0;
        int candidate = -1;
        for (final var k : a) {
            if (count == 0) {
                candidate = k;
                count = 1;
            } else {
                if (k == candidate) {
                    count++;
                } else {
                    count--;
                }
            }
        }
        return candidate;
    }

    private static int countOccurrences(final int candidate, final int[] a) {
        int count = 0;
        for (final var j : a) {
            if (j == candidate) {
                count++;
            }
        }
        return count;
    }

    private static boolean isMajority(final int count, final int totalCount) {
        return 2 * count > totalCount;
    }
}