style: enable LocalVariableName in CheckStyle (#5191)

* style: enable LocalVariableName in checkstyle

* Removed minor bug

* Resolved Method Name Bug

* Changed names according to suggestions
This commit is contained in:
S. Utkarsh
2024-05-28 23:59:28 +05:30
committed by GitHub
parent 81cb09b1f8
commit 25d711c5d8
45 changed files with 418 additions and 417 deletions

View File

@ -22,7 +22,7 @@ public final class CrossCorrelation {
public static double[] crossCorrelation(double[] x, double[] y) {
// The result signal's length is the sum of the input signals' lengths minus 1
double[] result = new double[x.length + y.length - 1];
int N = result.length;
int n = result.length;
/*
To find the cross-correlation between 2 discrete signals x & y, we start by "placing" the second signal
@ -60,13 +60,13 @@ public final class CrossCorrelation {
To find the result[i] value for each i:0->N-1, the positions of x-signal in which the 2 signals meet
To find the result[i] value for each i:0->n-1, the positions of x-signal in which the 2 signals meet
are calculated: kMin<=k<=kMax.
The variable 'yStart' indicates the starting index of y in each sum calculation.
The variable 'count' increases the index of y-signal by 1, to move to the next value.
*/
int yStart = y.length;
for (int i = 0; i < N; i++) {
for (int i = 0; i < n; i++) {
result[i] = 0;
int kMin = Math.max(i - (y.length - 1), 0);

View File

@ -186,16 +186,16 @@ public final class FFT {
public static ArrayList<Complex> fft(ArrayList<Complex> x, boolean inverse) {
/* Pad the signal with zeros if necessary */
paddingPowerOfTwo(x);
int N = x.size();
int log2N = findLog2(N);
x = fftBitReversal(N, log2N, x);
int n = x.size();
int log2n = findLog2(n);
x = fftBitReversal(n, log2n, x);
int direction = inverse ? -1 : 1;
/* Main loop of the algorithm */
for (int len = 2; len <= N; len *= 2) {
for (int len = 2; len <= n; len *= 2) {
double angle = -2 * Math.PI / len * direction;
Complex wlen = new Complex(Math.cos(angle), Math.sin(angle));
for (int i = 0; i < N; i += len) {
for (int i = 0; i < n; i += len) {
Complex w = new Complex(1, 0);
for (int j = 0; j < len / 2; j++) {
Complex u = x.get(i + j);
@ -206,24 +206,24 @@ public final class FFT {
}
}
}
x = inverseFFT(N, inverse, x);
x = inverseFFT(n, inverse, x);
return x;
}
/* Find the log2(N) */
public static int findLog2(int N) {
int log2N = 0;
while ((1 << log2N) < N) {
log2N++;
/* Find the log2(n) */
public static int findLog2(int n) {
int log2n = 0;
while ((1 << log2n) < n) {
log2n++;
}
return log2N;
return log2n;
}
/* Swap the values of the signal with bit-reversal method */
public static ArrayList<Complex> fftBitReversal(int N, int log2N, ArrayList<Complex> x) {
public static ArrayList<Complex> fftBitReversal(int n, int log2n, ArrayList<Complex> x) {
int reverse;
for (int i = 0; i < N; i++) {
reverse = reverseBits(i, log2N);
for (int i = 0; i < n; i++) {
reverse = reverseBits(i, log2n);
if (i < reverse) {
Collections.swap(x, i, reverse);
}
@ -231,12 +231,12 @@ public final class FFT {
return x;
}
/* Divide by N if we want the inverse FFT */
public static ArrayList<Complex> inverseFFT(int N, boolean inverse, ArrayList<Complex> x) {
/* Divide by n if we want the inverse FFT */
public static ArrayList<Complex> inverseFFT(int n, boolean inverse, ArrayList<Complex> x) {
if (inverse) {
for (int i = 0; i < x.size(); i++) {
Complex z = x.get(i);
x.set(i, z.divide(N));
x.set(i, z.divide(n));
}
}
return x;
@ -247,7 +247,7 @@ public final class FFT {
* FFT algorithm.
*
* <p>
* E.g. num = 13 = 00001101 in binary log2N = 8 Then reversed = 176 =
* E.g. num = 13 = 00001101 in binary log2n = 8 Then reversed = 176 =
* 10110000 in binary
*
* <p>
@ -255,14 +255,14 @@ public final class FFT {
* https://www.geeksforgeeks.org/write-an-efficient-c-program-to-reverse-bits-of-a-number/
*
* @param num The integer you want to reverse its bits.
* @param log2N The number of bits you want to reverse.
* @param log2n The number of bits you want to reverse.
* @return The reversed number
*/
private static int reverseBits(int num, int log2N) {
private static int reverseBits(int num, int log2n) {
int reversed = 0;
for (int i = 0; i < log2N; i++) {
for (int i = 0; i < log2n; i++) {
if ((num & (1 << i)) != 0) {
reversed |= 1 << (log2N - 1 - i);
reversed |= 1 << (log2n - 1 - i);
}
}
return reversed;

View File

@ -26,8 +26,8 @@ public final class FFTBluestein {
* @param inverse True if you want to find the inverse FFT.
*/
public static void fftBluestein(ArrayList<FFT.Complex> x, boolean inverse) {
int N = x.size();
int bnSize = 2 * N - 1;
int n = x.size();
int bnSize = 2 * n - 1;
int direction = inverse ? -1 : 1;
ArrayList<FFT.Complex> an = new ArrayList<>();
ArrayList<FFT.Complex> bn = new ArrayList<>();
@ -38,32 +38,32 @@ public final class FFTBluestein {
bn.add(new FFT.Complex());
}
for (int i = 0; i < N; i++) {
double angle = (i - N + 1) * (i - N + 1) * Math.PI / N * direction;
for (int i = 0; i < n; i++) {
double angle = (i - n + 1) * (i - n + 1) * Math.PI / n * direction;
bn.set(i, new FFT.Complex(Math.cos(angle), Math.sin(angle)));
bn.set(bnSize - i - 1, new FFT.Complex(Math.cos(angle), Math.sin(angle)));
}
/* Initialization of the a(n) sequence */
for (int i = 0; i < N; i++) {
double angle = -i * i * Math.PI / N * direction;
for (int i = 0; i < n; i++) {
double angle = -i * i * Math.PI / n * direction;
an.add(x.get(i).multiply(new FFT.Complex(Math.cos(angle), Math.sin(angle))));
}
ArrayList<FFT.Complex> convolution = ConvolutionFFT.convolutionFFT(an, bn);
/* The final multiplication of the convolution with the b*(k) factor */
for (int i = 0; i < N; i++) {
double angle = -1 * i * i * Math.PI / N * direction;
for (int i = 0; i < n; i++) {
double angle = -1 * i * i * Math.PI / n * direction;
FFT.Complex bk = new FFT.Complex(Math.cos(angle), Math.sin(angle));
x.set(i, bk.multiply(convolution.get(i + N - 1)));
x.set(i, bk.multiply(convolution.get(i + n - 1)));
}
/* Divide by N if we want the inverse FFT */
/* Divide by n if we want the inverse FFT */
if (inverse) {
for (int i = 0; i < N; i++) {
for (int i = 0; i < n; i++) {
FFT.Complex z = x.get(i);
x.set(i, z.divide(N));
x.set(i, z.divide(n));
}
}
}

View File

@ -26,24 +26,24 @@ final class KeithNumber {
}
// reverse the List
Collections.reverse(terms);
int next_term = 0;
int nextTerm = 0;
int i = n;
// finds next term for the series
// loop executes until the condition returns true
while (next_term < x) {
next_term = 0;
while (nextTerm < x) {
nextTerm = 0;
// next term is the sum of previous n terms (it depends on number of digits the number
// has)
for (int j = 1; j <= n; j++) {
next_term = next_term + terms.get(i - j);
nextTerm = nextTerm + terms.get(i - j);
}
terms.add(next_term);
terms.add(nextTerm);
i++;
}
// when the control comes out of the while loop, there will be two conditions:
// either next_term will be equal to x or greater than x
// either nextTerm will be equal to x or greater than x
// if equal, the given number is Keith, else not
return (next_term == x);
return (nextTerm == x);
}
// driver code

View File

@ -12,59 +12,59 @@ public final class LongDivision {
private LongDivision() {
}
public static int divide(int dividend, int divisor) {
long new_dividend_1 = dividend;
long new_divisor_1 = divisor;
long newDividend1 = dividend;
long newDivisor1 = divisor;
if (divisor == 0) {
return 0;
}
if (dividend < 0) {
new_dividend_1 = new_dividend_1 * -1;
newDividend1 = newDividend1 * -1;
}
if (divisor < 0) {
new_divisor_1 = new_divisor_1 * -1;
newDivisor1 = newDivisor1 * -1;
}
if (dividend == 0 || new_dividend_1 < new_divisor_1) {
if (dividend == 0 || newDividend1 < newDivisor1) {
return 0;
}
StringBuilder answer = new StringBuilder();
String dividend_string = "" + new_dividend_1;
int last_index = 0;
String dividendString = "" + newDividend1;
int lastIndex = 0;
String remainder = "";
for (int i = 0; i < dividend_string.length(); i++) {
String part_v1 = remainder + "" + dividend_string.substring(last_index, i + 1);
long part_1 = Long.parseLong(part_v1);
if (part_1 > new_divisor_1) {
for (int i = 0; i < dividendString.length(); i++) {
String partV1 = remainder + "" + dividendString.substring(lastIndex, i + 1);
long part1 = Long.parseLong(partV1);
if (part1 > newDivisor1) {
int quotient = 0;
while (part_1 >= new_divisor_1) {
part_1 = part_1 - new_divisor_1;
while (part1 >= newDivisor1) {
part1 = part1 - newDivisor1;
quotient++;
}
answer.append(quotient);
} else if (part_1 == new_divisor_1) {
} else if (part1 == newDivisor1) {
int quotient = 0;
while (part_1 >= new_divisor_1) {
part_1 = part_1 - new_divisor_1;
while (part1 >= newDivisor1) {
part1 = part1 - newDivisor1;
quotient++;
}
answer.append(quotient);
} else if (part_1 == 0) {
} else if (part1 == 0) {
answer.append(0);
} else if (part_1 < new_divisor_1) {
} else if (part1 < newDivisor1) {
answer.append(0);
}
if (!(part_1 == 0)) {
remainder = String.valueOf(part_1);
if (!(part1 == 0)) {
remainder = String.valueOf(part1);
} else {
remainder = "";
}
last_index++;
lastIndex++;
}
if ((dividend < 0 && divisor > 0) || (dividend > 0 && divisor < 0)) {

View File

@ -18,32 +18,32 @@ public final class MagicSquare {
System.exit(0);
}
int[][] magic_square = new int[num][num];
int[][] magicSquare = new int[num][num];
int row_num = num / 2;
int col_num = num - 1;
magic_square[row_num][col_num] = 1;
int rowNum = num / 2;
int colNum = num - 1;
magicSquare[rowNum][colNum] = 1;
for (int i = 2; i <= num * num; i++) {
if (magic_square[(row_num - 1 + num) % num][(col_num + 1) % num] == 0) {
row_num = (row_num - 1 + num) % num;
col_num = (col_num + 1) % num;
if (magicSquare[(rowNum - 1 + num) % num][(colNum + 1) % num] == 0) {
rowNum = (rowNum - 1 + num) % num;
colNum = (colNum + 1) % num;
} else {
col_num = (col_num - 1 + num) % num;
colNum = (colNum - 1 + num) % num;
}
magic_square[row_num][col_num] = i;
magicSquare[rowNum][colNum] = i;
}
// print the square
for (int i = 0; i < num; i++) {
for (int j = 0; j < num; j++) {
if (magic_square[i][j] < 10) {
if (magicSquare[i][j] < 10) {
System.out.print(" ");
}
if (magic_square[i][j] < 100) {
if (magicSquare[i][j] < 100) {
System.out.print(" ");
}
System.out.print(magic_square[i][j] + " ");
System.out.print(magicSquare[i][j] + " ");
}
System.out.println();
}

View File

@ -19,19 +19,19 @@ public class SimpsonIntegration {
SimpsonIntegration integration = new SimpsonIntegration();
// Give random data for the example purposes
int N = 16;
int n = 16;
double a = 1;
double b = 3;
// Check so that N is even
if (N % 2 != 0) {
System.out.println("N must be even number for Simpsons method. Aborted");
// Check so that n is even
if (n % 2 != 0) {
System.out.println("n must be even number for Simpsons method. Aborted");
System.exit(1);
}
// Calculate step h and evaluate the integral
double h = (b - a) / (double) N;
double integralEvaluation = integration.simpsonsMethod(N, h, a);
double h = (b - a) / (double) n;
double integralEvaluation = integration.simpsonsMethod(n, h, a);
System.out.println("The integral is equal to: " + integralEvaluation);
}
@ -45,13 +45,13 @@ public class SimpsonIntegration {
*
* @return result of the integral evaluation
*/
public double simpsonsMethod(int N, double h, double a) {
public double simpsonsMethod(int n, double h, double a) {
TreeMap<Integer, Double> data = new TreeMap<>(); // Key: i, Value: f(xi)
double temp;
double xi = a; // Initialize the variable xi = x0 + 0*h
// Create the table of xi and yi points
for (int i = 0; i <= N; i++) {
for (int i = 0; i <= n; i++) {
temp = f(xi); // Get the value of the function at that point
data.put(i, temp);
xi += h; // Increase the xi to the next point

View File

@ -111,15 +111,15 @@ public class VectorCrossProduct {
static void test() {
// Create two vectors
VectorCrossProduct A = new VectorCrossProduct(1, -2, 3);
VectorCrossProduct B = new VectorCrossProduct(2, 0, 3);
VectorCrossProduct a = new VectorCrossProduct(1, -2, 3);
VectorCrossProduct b = new VectorCrossProduct(2, 0, 3);
// Determine cross product
VectorCrossProduct crossProd = A.crossProduct(B);
VectorCrossProduct crossProd = a.crossProduct(b);
crossProd.displayVector();
// Determine dot product
int dotProd = A.dotProduct(B);
System.out.println("Dot Product of A and B: " + dotProd);
int dotProd = a.dotProduct(b);
System.out.println("Dot Product of a and b: " + dotProd);
}
}