style: enabled InnerAssignment
in checkstyle (#5162)
* style: enabled InnerAssignment in checkstyle * Refactor code formatting in KnapsackMemoization.java and UnionFind.java * style: remove redundant blank line * style: mark `includeCurrentItem` and `excludeCurrentItem` as `final` * style: remove `KnapsackMemoization` from `pmd-exclude.properties` * style: use `final` --------- Co-authored-by: Piotr Idzik <65706193+vil02@users.noreply.github.com>
This commit is contained in:
parent
f8e62fbb90
commit
0f42e995a4
@ -164,7 +164,7 @@
|
|||||||
<module name="EqualsHashCode"/>
|
<module name="EqualsHashCode"/>
|
||||||
<!-- TODO <module name="HiddenField"/> -->
|
<!-- TODO <module name="HiddenField"/> -->
|
||||||
<module name="IllegalInstantiation"/>
|
<module name="IllegalInstantiation"/>
|
||||||
<!-- TODO <module name="InnerAssignment"/> -->
|
<module name="InnerAssignment"/>
|
||||||
<!-- TODO <module name="MagicNumber"/> -->
|
<!-- TODO <module name="MagicNumber"/> -->
|
||||||
<!-- TODO <module name="MissingSwitchDefault"/> -->
|
<!-- TODO <module name="MissingSwitchDefault"/> -->
|
||||||
<!-- TODO <module name="MultipleVariableDeclarations"/> -->
|
<!-- TODO <module name="MultipleVariableDeclarations"/> -->
|
||||||
|
@ -33,7 +33,6 @@ com.thealgorithms.devutils.nodes.SimpleTreeNode=UselessParentheses
|
|||||||
com.thealgorithms.devutils.nodes.TreeNode=UselessParentheses
|
com.thealgorithms.devutils.nodes.TreeNode=UselessParentheses
|
||||||
com.thealgorithms.divideandconquer.ClosestPair=UnnecessaryFullyQualifiedName,UselessParentheses
|
com.thealgorithms.divideandconquer.ClosestPair=UnnecessaryFullyQualifiedName,UselessParentheses
|
||||||
com.thealgorithms.divideandconquer.Point=UselessParentheses
|
com.thealgorithms.divideandconquer.Point=UselessParentheses
|
||||||
com.thealgorithms.dynamicprogramming.KnapsackMemoization=UselessParentheses
|
|
||||||
com.thealgorithms.dynamicprogramming.MatrixChainMultiplication=UselessParentheses
|
com.thealgorithms.dynamicprogramming.MatrixChainMultiplication=UselessParentheses
|
||||||
com.thealgorithms.dynamicprogramming.ShortestSuperSequence=UselessParentheses
|
com.thealgorithms.dynamicprogramming.ShortestSuperSequence=UselessParentheses
|
||||||
com.thealgorithms.dynamicprogramming.UniquePaths=UnnecessarySemicolon
|
com.thealgorithms.dynamicprogramming.UniquePaths=UnnecessarySemicolon
|
||||||
|
@ -26,8 +26,8 @@ final class ProductCipher {
|
|||||||
|
|
||||||
// Transposition encryption
|
// Transposition encryption
|
||||||
String transpositionInput = substitutionOutput.toString();
|
String transpositionInput = substitutionOutput.toString();
|
||||||
int modulus;
|
int modulus = transpositionInput.length() % n;
|
||||||
if ((modulus = transpositionInput.length() % n) != 0) {
|
if (modulus != 0) {
|
||||||
modulus = n - modulus;
|
modulus = n - modulus;
|
||||||
|
|
||||||
for (; modulus != 0; modulus--) {
|
for (; modulus != 0; modulus--) {
|
||||||
|
@ -121,7 +121,8 @@ public class DynamicArray<E> implements Iterable<E> {
|
|||||||
System.arraycopy(elements, index + 1, elements, index, newSize - index);
|
System.arraycopy(elements, index + 1, elements, index, newSize - index);
|
||||||
}
|
}
|
||||||
|
|
||||||
elements[this.size = newSize] = null;
|
this.size = newSize;
|
||||||
|
this.elements[this.size] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private E getElement(final int index) {
|
private E getElement(final int index) {
|
||||||
|
@ -20,7 +20,8 @@ public class LeftistHeap {
|
|||||||
// Node constructor setting the data element and left/right pointers to null
|
// Node constructor setting the data element and left/right pointers to null
|
||||||
private Node(int element) {
|
private Node(int element) {
|
||||||
this.element = element;
|
this.element = element;
|
||||||
left = right = null;
|
left = null;
|
||||||
|
right = null;
|
||||||
npl = 0;
|
npl = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,8 @@ public class CircularQueue {
|
|||||||
int res = arr[beginningOfQueue];
|
int res = arr[beginningOfQueue];
|
||||||
arr[beginningOfQueue] = Integer.MIN_VALUE;
|
arr[beginningOfQueue] = Integer.MIN_VALUE;
|
||||||
if (beginningOfQueue == topOfQueue) {
|
if (beginningOfQueue == topOfQueue) {
|
||||||
beginningOfQueue = topOfQueue = -1;
|
beginningOfQueue = -1;
|
||||||
|
topOfQueue = -1;
|
||||||
} else if (beginningOfQueue + 1 == size) {
|
} else if (beginningOfQueue + 1 == size) {
|
||||||
beginningOfQueue = 0;
|
beginningOfQueue = 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -44,7 +44,9 @@ public class LinkedQueue<T> implements Iterable<T> {
|
|||||||
* Init LinkedQueue
|
* Init LinkedQueue
|
||||||
*/
|
*/
|
||||||
public LinkedQueue() {
|
public LinkedQueue() {
|
||||||
front = rear = new Node<>();
|
|
||||||
|
front = new Node<>();
|
||||||
|
rear = front;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -146,7 +148,8 @@ public class LinkedQueue<T> implements Iterable<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T next() {
|
public T next() {
|
||||||
return (node = node.next).data;
|
node = node.next;
|
||||||
|
return node.data;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,8 @@ class TreeNode {
|
|||||||
// Constructor
|
// Constructor
|
||||||
TreeNode(int key) {
|
TreeNode(int key) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
left = right = null;
|
left = null;
|
||||||
|
right = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +201,8 @@ public class RedBlackBST {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean delete(Node z) {
|
boolean delete(Node z) {
|
||||||
if ((z = findNode(z, root)) == null) {
|
Node result = findNode(z, root);
|
||||||
|
if (result == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Node x;
|
Node x;
|
||||||
|
@ -40,8 +40,15 @@ public class KnapsackMemoization {
|
|||||||
dpTable[numOfItems][capacity] = solveKnapsackRecursive(capacity, weights, profits, numOfItems - 1, dpTable);
|
dpTable[numOfItems][capacity] = solveKnapsackRecursive(capacity, weights, profits, numOfItems - 1, dpTable);
|
||||||
return dpTable[numOfItems][capacity];
|
return dpTable[numOfItems][capacity];
|
||||||
} else {
|
} else {
|
||||||
// Return value of table after storing
|
// case 1. include the item, if it is less than the capacity
|
||||||
return dpTable[numOfItems][capacity] = Math.max((profits[numOfItems - 1] + solveKnapsackRecursive(capacity - weights[numOfItems - 1], weights, profits, numOfItems - 1, dpTable)), solveKnapsackRecursive(capacity, weights, profits, numOfItems - 1, dpTable));
|
final int includeCurrentItem = profits[numOfItems - 1] + solveKnapsackRecursive(capacity - weights[numOfItems - 1], weights, profits, numOfItems - 1, dpTable);
|
||||||
|
|
||||||
|
// case 2. exclude the item if it is more than the capacity
|
||||||
|
final int excludeCurrentItem = solveKnapsackRecursive(capacity, weights, profits, numOfItems - 1, dpTable);
|
||||||
|
|
||||||
|
// Store the value of function call stack in table and return
|
||||||
|
dpTable[numOfItems][capacity] = Math.max(includeCurrentItem, excludeCurrentItem);
|
||||||
|
return dpTable[numOfItems][capacity];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,8 @@ public final class LongestAlternatingSubsequence {
|
|||||||
int[][] las = new int[n][2]; // las = LongestAlternatingSubsequence
|
int[][] las = new int[n][2]; // las = LongestAlternatingSubsequence
|
||||||
|
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
las[i][0] = las[i][1] = 1;
|
las[i][0] = 1;
|
||||||
|
las[i][1] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int result = 1; // Initialize result
|
int result = 1; // Initialize result
|
||||||
|
@ -15,7 +15,8 @@ public final class NewManShanksPrime {
|
|||||||
public static boolean nthManShanksPrime(int n, int expected_answer) {
|
public static boolean nthManShanksPrime(int n, int expected_answer) {
|
||||||
int[] a = new int[n + 1];
|
int[] a = new int[n + 1];
|
||||||
// array of n+1 size is initialized
|
// array of n+1 size is initialized
|
||||||
a[0] = a[1] = 1;
|
a[0] = 1;
|
||||||
|
a[1] = 1;
|
||||||
// The 0th and 1st index position values are fixed. They are initialized as 1
|
// The 0th and 1st index position values are fixed. They are initialized as 1
|
||||||
for (int i = 2; i <= n; i++) {
|
for (int i = 2; i <= n; i++) {
|
||||||
a[i] = 2 * a[i - 1] + a[i - 2];
|
a[i] = 2 * a[i - 1] + a[i - 2];
|
||||||
|
@ -36,9 +36,11 @@ public final class LeastCommonMultiple {
|
|||||||
* value selection for the numerator
|
* value selection for the numerator
|
||||||
*/
|
*/
|
||||||
if (num1 > num2) {
|
if (num1 > num2) {
|
||||||
high = num3 = num1;
|
high = num1;
|
||||||
|
num3 = num1;
|
||||||
} else {
|
} else {
|
||||||
high = num3 = num2;
|
high = num2;
|
||||||
|
num3 = num2;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (num1 != 0) {
|
while (num1 != 0) {
|
||||||
|
@ -19,7 +19,8 @@ public final class SieveOfEratosthenes {
|
|||||||
checkInput(n);
|
checkInput(n);
|
||||||
Type[] isPrimeArray = new Type[n + 1];
|
Type[] isPrimeArray = new Type[n + 1];
|
||||||
Arrays.fill(isPrimeArray, Type.PRIME);
|
Arrays.fill(isPrimeArray, Type.PRIME);
|
||||||
isPrimeArray[0] = isPrimeArray[1] = Type.NOT_PRIME;
|
isPrimeArray[0] = Type.NOT_PRIME;
|
||||||
|
isPrimeArray[1] = Type.NOT_PRIME;
|
||||||
|
|
||||||
double cap = Math.sqrt(n);
|
double cap = Math.sqrt(n);
|
||||||
for (int i = 2; i <= cap; i++) {
|
for (int i = 2; i <= cap; i++) {
|
||||||
|
@ -25,7 +25,10 @@ public class UnionFind {
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
return p[i] = find(parent);
|
final int result = find(parent);
|
||||||
|
p[i] = result;
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void union(int x, int y) {
|
public void union(int x, int y) {
|
||||||
|
Loading…
Reference in New Issue
Block a user