Skip to content

Commit 2c147e9

Browse files
committed
style: enabled InnerAssignment in checkstyle
1 parent f8e62fb commit 2c147e9

14 files changed

+41
-18
lines changed

checkstyle.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
<module name="EqualsHashCode"/>
165165
<!-- TODO <module name="HiddenField"/> -->
166166
<module name="IllegalInstantiation"/>
167-
<!-- TODO <module name="InnerAssignment"/> -->
167+
<module name="InnerAssignment"/>
168168
<!-- TODO <module name="MagicNumber"/> -->
169169
<!-- TODO <module name="MissingSwitchDefault"/> -->
170170
<!-- TODO <module name="MultipleVariableDeclarations"/> -->

src/main/java/com/thealgorithms/ciphers/ProductCipher.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public static void main(String[] args) {
2626

2727
// Transposition encryption
2828
String transpositionInput = substitutionOutput.toString();
29-
int modulus;
30-
if ((modulus = transpositionInput.length() % n) != 0) {
29+
int modulus = transpositionInput.length() % n;
30+
if (modulus != 0) {
3131
modulus = n - modulus;
3232

3333
for (; modulus != 0; modulus--) {

src/main/java/com/thealgorithms/datastructures/dynamicarray/DynamicArray.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ private void fastRemove(final Object[] elements, final int index) {
121121
System.arraycopy(elements, index + 1, elements, index, newSize - index);
122122
}
123123

124-
elements[this.size = newSize] = null;
124+
this.size = newSize;
125+
this.elements[this.size] = null;
125126
}
126127

127128
private E getElement(final int index) {

src/main/java/com/thealgorithms/datastructures/heaps/LeftistHeap.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ private final class Node {
2020
// Node constructor setting the data element and left/right pointers to null
2121
private Node(int element) {
2222
this.element = element;
23-
left = right = null;
23+
left = null;
24+
right = null;
2425
npl = 0;
2526
}
2627
}

src/main/java/com/thealgorithms/datastructures/queues/CircularQueue.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public int deQueue() {
5454
int res = arr[beginningOfQueue];
5555
arr[beginningOfQueue] = Integer.MIN_VALUE;
5656
if (beginningOfQueue == topOfQueue) {
57-
beginningOfQueue = topOfQueue = -1;
57+
beginningOfQueue = -1;
58+
topOfQueue = -1;
5859
} else if (beginningOfQueue + 1 == size) {
5960
beginningOfQueue = 0;
6061
} else {

src/main/java/com/thealgorithms/datastructures/queues/LinkedQueue.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ static class Node<T> {
4444
* Init LinkedQueue
4545
*/
4646
public LinkedQueue() {
47-
front = rear = new Node<>();
47+
48+
front = new Node<>();
49+
rear = front;
4850
}
4951

5052
/**
@@ -146,7 +148,8 @@ public boolean hasNext() {
146148

147149
@Override
148150
public T next() {
149-
return (node = node.next).data;
151+
node = node.next;
152+
return node.data;
150153
}
151154
};
152155
}

src/main/java/com/thealgorithms/datastructures/trees/PrintTopViewofTree.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ class TreeNode {
1515
// Constructor
1616
TreeNode(int key) {
1717
this.key = key;
18-
left = right = null;
18+
left = null;
19+
right = null;
1920
}
2021
}
2122

src/main/java/com/thealgorithms/datastructures/trees/RedBlackBST.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ Node treeMinimum(Node subTreeRoot) {
201201
}
202202

203203
boolean delete(Node z) {
204-
if ((z = findNode(z, root)) == null) {
204+
Node result = findNode(z, root);
205+
if (result == null) {
205206
return false;
206207
}
207208
Node x;

src/main/java/com/thealgorithms/dynamicprogramming/KnapsackMemoization.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,16 @@ int solveKnapsackRecursive(int capacity, int[] weights, int[] profits, int numOf
4040
dpTable[numOfItems][capacity] = solveKnapsackRecursive(capacity, weights, profits, numOfItems - 1, dpTable);
4141
return dpTable[numOfItems][capacity];
4242
} else {
43-
// Return value of table after storing
44-
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));
43+
// case 1. include the item, if it is less than the capacity
44+
int includeCurrentItem = profits[numOfItems - 1]
45+
+ solveKnapsackRecursive(capacity - weights[numOfItems - 1], weights, profits, numOfItems - 1, dpTable);
46+
47+
// case 2. exclude the item if it is more than the capacity
48+
int excludeCurrentItem = solveKnapsackRecursive(capacity, weights, profits, numOfItems - 1, dpTable);
49+
50+
// Store the value of function call stack in table and return
51+
dpTable[numOfItems][capacity] = Math.max(includeCurrentItem, excludeCurrentItem);
52+
return dpTable[numOfItems][capacity];
4553
}
4654
}
4755
}

src/main/java/com/thealgorithms/dynamicprogramming/LongestAlternatingSubsequence.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ static int AlternatingLength(int[] arr, int n) {
3434
int[][] las = new int[n][2]; // las = LongestAlternatingSubsequence
3535

3636
for (int i = 0; i < n; i++) {
37-
las[i][0] = las[i][1] = 1;
37+
las[i][0] = 1;
38+
las[i][1] = 1;
3839
}
3940

4041
int result = 1; // Initialize result

src/main/java/com/thealgorithms/dynamicprogramming/NewManShanksPrime.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ private NewManShanksPrime() {
1515
public static boolean nthManShanksPrime(int n, int expected_answer) {
1616
int[] a = new int[n + 1];
1717
// array of n+1 size is initialized
18-
a[0] = a[1] = 1;
18+
a[0] = 1;
19+
a[1] = 1;
1920
// The 0th and 1st index position values are fixed. They are initialized as 1
2021
for (int i = 2; i <= n; i++) {
2122
a[i] = 2 * a[i - 1] + a[i - 2];

src/main/java/com/thealgorithms/maths/LeastCommonMultiple.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ public static int lcm(int num1, int num2) {
3636
* value selection for the numerator
3737
*/
3838
if (num1 > num2) {
39-
high = num3 = num1;
39+
high = num1;
40+
num3 = num1;
4041
} else {
41-
high = num3 = num2;
42+
high = num2;
43+
num3 = num2;
4244
}
4345

4446
while (num1 != 0) {

src/main/java/com/thealgorithms/others/SieveOfEratosthenes.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ private static Type[] sievePrimesTill(int n) {
1919
checkInput(n);
2020
Type[] isPrimeArray = new Type[n + 1];
2121
Arrays.fill(isPrimeArray, Type.PRIME);
22-
isPrimeArray[0] = isPrimeArray[1] = Type.NOT_PRIME;
22+
isPrimeArray[0] = Type.NOT_PRIME;
23+
isPrimeArray[1] = Type.NOT_PRIME;
2324

2425
double cap = Math.sqrt(n);
2526
for (int i = 2; i <= cap; i++) {

src/main/java/com/thealgorithms/searches/UnionFind.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ public int find(int i) {
2525
return i;
2626
}
2727

28-
return p[i] = find(parent);
28+
int result = find(parent);
29+
p[i] = result;
30+
return result;
2931
}
3032

3133
public void union(int x, int y) {

0 commit comments

Comments
 (0)