Skip to content

Commit 7fd1a88

Browse files
authored
Merge branch 'master' into master
2 parents bfd9a93 + 2570a99 commit 7fd1a88

18 files changed

+446
-193
lines changed

Diff for: pmd-exclude.properties

-25
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
1-
com.thealgorithms.bitmanipulation.SingleBitOperations=UselessParentheses
21
com.thealgorithms.ciphers.AffineCipher=UselessParentheses
3-
com.thealgorithms.ciphers.ColumnarTranspositionCipher=UnnecessaryFullyQualifiedName
42
com.thealgorithms.ciphers.DES=UselessParentheses
5-
com.thealgorithms.ciphers.HillCipher=UselessParentheses
63
com.thealgorithms.ciphers.RSA=UselessParentheses
74
com.thealgorithms.conversions.AnyBaseToAnyBase=UselessParentheses
85
com.thealgorithms.conversions.AnytoAny=UselessParentheses
9-
com.thealgorithms.conversions.HexToOct=UselessParentheses
10-
com.thealgorithms.conversions.IntegerToRoman=UnnecessaryFullyQualifiedName
11-
com.thealgorithms.datastructures.crdt.LWWElementSet=UselessParentheses
126
com.thealgorithms.datastructures.crdt.Pair=UnusedPrivateField
137
com.thealgorithms.datastructures.graphs.AStar=UselessParentheses
148
com.thealgorithms.datastructures.graphs.AdjacencyMatrixGraph=CollapsibleIfStatements,UnnecessaryFullyQualifiedName,UselessParentheses
159
com.thealgorithms.datastructures.graphs.BipartiteGraphDFS=CollapsibleIfStatements
16-
com.thealgorithms.datastructures.graphs.Kruskal=UselessParentheses
1710
com.thealgorithms.datastructures.hashmap.hashing.HashMapCuckooHashing=UselessParentheses
1811
com.thealgorithms.datastructures.heaps.FibonacciHeap=UselessParentheses
19-
com.thealgorithms.datastructures.heaps.HeapElement=UselessParentheses
2012
com.thealgorithms.datastructures.heaps.HeapNode=UselessParentheses
2113
com.thealgorithms.datastructures.lists.DoublyLinkedList=UselessParentheses
2214
com.thealgorithms.datastructures.lists.SearchSinglyLinkedListRecursion=UselessParentheses
2315
com.thealgorithms.datastructures.lists.SinglyLinkedList=UnusedLocalVariable
2416
com.thealgorithms.datastructures.queues.PriorityQueue=UselessParentheses
25-
com.thealgorithms.datastructures.stacks.NodeStack=UnnecessaryFullyQualifiedName,UnusedFormalParameter
26-
com.thealgorithms.datastructures.stacks.StackArray=UselessParentheses
2717
com.thealgorithms.datastructures.trees.CheckBinaryTreeIsValidBST=UselessParentheses
2818
com.thealgorithms.datastructures.trees.SegmentTree=UselessParentheses
2919
com.thealgorithms.devutils.nodes.LargeTreeNode=UselessParentheses
@@ -32,9 +22,6 @@ com.thealgorithms.devutils.nodes.SimpleTreeNode=UselessParentheses
3222
com.thealgorithms.devutils.nodes.TreeNode=UselessParentheses
3323
com.thealgorithms.divideandconquer.ClosestPair=UnnecessaryFullyQualifiedName,UselessParentheses
3424
com.thealgorithms.divideandconquer.Point=UselessParentheses
35-
com.thealgorithms.dynamicprogramming.MatrixChainMultiplication=UselessParentheses
36-
com.thealgorithms.dynamicprogramming.ShortestSuperSequence=UselessParentheses
37-
com.thealgorithms.dynamicprogramming.UniquePaths=UnnecessarySemicolon
3825
com.thealgorithms.dynamicprogramming.WineProblem=UselessParentheses
3926
com.thealgorithms.maths.BinomialCoefficient=UselessParentheses
4027
com.thealgorithms.maths.Complex=UselessParentheses
@@ -46,44 +33,32 @@ com.thealgorithms.maths.KaprekarNumbers=UselessParentheses
4633
com.thealgorithms.maths.KeithNumber=UselessParentheses
4734
com.thealgorithms.maths.LeonardoNumber=UselessParentheses
4835
com.thealgorithms.maths.LinearDiophantineEquationsSolver=UselessParentheses
49-
com.thealgorithms.maths.MatrixUtil=UselessParentheses
5036
com.thealgorithms.maths.RomanNumeralUtil=UselessParentheses
5137
com.thealgorithms.maths.SecondMinMax=UselessParentheses
5238
com.thealgorithms.maths.SecondMinMaxTest=UnnecessaryFullyQualifiedName
5339
com.thealgorithms.maths.StandardDeviation=UselessParentheses
5440
com.thealgorithms.maths.SumOfArithmeticSeries=UselessParentheses
5541
com.thealgorithms.maths.TrinomialTriangle=UselessParentheses
56-
com.thealgorithms.maths.VampireNumber=CollapsibleIfStatements
5742
com.thealgorithms.maths.Volume=UselessParentheses
5843
com.thealgorithms.misc.Sparsity=UselessParentheses
59-
com.thealgorithms.misc.ThreeSumProblem=UselessParentheses
60-
com.thealgorithms.misc.WordBoggle=UselessParentheses
6144
com.thealgorithms.others.CRC16=UselessParentheses
6245
com.thealgorithms.others.Damm=UnnecessaryFullyQualifiedName
6346
com.thealgorithms.others.Luhn=UnnecessaryFullyQualifiedName
6447
com.thealgorithms.others.Mandelbrot=UselessParentheses
65-
com.thealgorithms.others.MaximumSumOfDistinctSubarraysWithLengthK=CollapsibleIfStatements
6648
com.thealgorithms.others.MiniMaxAlgorithm=UselessParentheses
6749
com.thealgorithms.others.PageRank=UselessParentheses
6850
com.thealgorithms.others.PerlinNoise=UselessParentheses
6951
com.thealgorithms.others.QueueUsingTwoStacks=UselessParentheses
70-
com.thealgorithms.others.QueueWithStack=UselessParentheses
7152
com.thealgorithms.others.Trieac=UselessParentheses
7253
com.thealgorithms.others.Verhoeff=UnnecessaryFullyQualifiedName
7354
com.thealgorithms.searches.InterpolationSearch=UselessParentheses
7455
com.thealgorithms.searches.KMPSearch=UselessParentheses
75-
com.thealgorithms.searches.LinearSearchThread=EmptyCatchBlock
7656
com.thealgorithms.searches.RabinKarpAlgorithm=UselessParentheses
7757
com.thealgorithms.sorts.CircleSort=EmptyControlStatement
78-
com.thealgorithms.sorts.CombSort=UselessParentheses
7958
com.thealgorithms.sorts.DutchNationalFlagSort=UselessParentheses
80-
com.thealgorithms.sorts.LinkListSort=EmptyControlStatement,UnusedLocalVariable
8159
com.thealgorithms.sorts.MergeSortNoExtraSpace=UselessParentheses
82-
com.thealgorithms.sorts.PigeonholeSort=UselessParentheses
8360
com.thealgorithms.sorts.RadixSort=UselessParentheses
8461
com.thealgorithms.sorts.WiggleSort=UselessParentheses
8562
com.thealgorithms.stacks.PostfixToInfix=UselessParentheses
8663
com.thealgorithms.strings.HorspoolSearch=UnnecessaryFullyQualifiedName,UselessParentheses
87-
com.thealgorithms.strings.MyAtoi=UselessParentheses
8864
com.thealgorithms.strings.Palindrome=UselessParentheses
89-
com.thealgorithms.strings.Solution=CollapsibleIfStatements

Diff for: pom.xml

+4-5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<dependency>
4343
<groupId>org.mockito</groupId>
4444
<artifactId>mockito-core</artifactId>
45-
<version>5.16.1</version>
45+
<version>5.17.0</version>
4646
<scope>test</scope>
4747
</dependency>
4848
<dependency>
@@ -61,7 +61,7 @@
6161
<plugins>
6262
<plugin>
6363
<artifactId>maven-surefire-plugin</artifactId>
64-
<version>3.5.2</version>
64+
<version>3.5.3</version>
6565
<configuration>
6666
<forkNode implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory"/>
6767
</configuration>
@@ -78,15 +78,14 @@
7878
<arg>-Xlint:-auxiliaryclass</arg>
7979
<arg>-Xlint:-rawtypes</arg>
8080
<arg>-Xlint:-unchecked</arg>
81-
<arg>-Xlint:-lossy-conversions</arg>
8281
<arg>-Werror</arg>
8382
</compilerArgs>
8483
</configuration>
8584
</plugin>
8685
<plugin>
8786
<groupId>org.jacoco</groupId>
8887
<artifactId>jacoco-maven-plugin</artifactId>
89-
<version>0.8.12</version>
88+
<version>0.8.13</version>
9089
<executions>
9190
<execution>
9291
<goals>
@@ -116,7 +115,7 @@
116115
<dependency>
117116
<groupId>com.puppycrawl.tools</groupId>
118117
<artifactId>checkstyle</artifactId>
119-
<version>10.21.4</version>
118+
<version>10.23.0</version>
120119
</dependency>
121120
</dependencies>
122121
</plugin>

Diff for: src/main/java/com/thealgorithms/ciphers/Caesar.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
* @author khalil2535
1010
*/
1111
public class Caesar {
12+
private static char normalizeShift(final int shift) {
13+
return (char) (shift % 26);
14+
}
1215

1316
/**
1417
* Encrypt text by shifting every Latin char by add number shift for ASCII
@@ -19,7 +22,7 @@ public class Caesar {
1922
public String encode(String message, int shift) {
2023
StringBuilder encoded = new StringBuilder();
2124

22-
shift %= 26;
25+
final char shiftChar = normalizeShift(shift);
2326

2427
final int length = message.length();
2528
for (int i = 0; i < length; i++) {
@@ -29,10 +32,10 @@ public String encode(String message, int shift) {
2932
char current = message.charAt(i); // Java law : char + int = char
3033

3134
if (isCapitalLatinLetter(current)) {
32-
current += shift;
35+
current += shiftChar;
3336
encoded.append((char) (current > 'Z' ? current - 26 : current)); // 26 = number of latin letters
3437
} else if (isSmallLatinLetter(current)) {
35-
current += shift;
38+
current += shiftChar;
3639
encoded.append((char) (current > 'z' ? current - 26 : current)); // 26 = number of latin letters
3740
} else {
3841
encoded.append(current);
@@ -50,16 +53,16 @@ public String encode(String message, int shift) {
5053
public String decode(String encryptedMessage, int shift) {
5154
StringBuilder decoded = new StringBuilder();
5255

53-
shift %= 26;
56+
final char shiftChar = normalizeShift(shift);
5457

5558
final int length = encryptedMessage.length();
5659
for (int i = 0; i < length; i++) {
5760
char current = encryptedMessage.charAt(i);
5861
if (isCapitalLatinLetter(current)) {
59-
current -= shift;
62+
current -= shiftChar;
6063
decoded.append((char) (current < 'A' ? current + 26 : current)); // 26 = number of latin letters
6164
} else if (isSmallLatinLetter(current)) {
62-
current -= shift;
65+
current -= shiftChar;
6366
decoded.append((char) (current < 'a' ? current + 26 : current)); // 26 = number of latin letters
6467
} else {
6568
decoded.append(current);

Diff for: src/main/java/com/thealgorithms/datastructures/lists/CountSinglyLinkedListRecursion.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class CountSinglyLinkedListRecursion extends SinglyLinkedList {
1212
* @param head the head node of the list segment being counted.
1313
* @return the count of nodes from the given head node onward.
1414
*/
15-
private int countRecursion(Node head) {
15+
private int countRecursion(SinglyLinkedListNode head) {
1616
return head == null ? 0 : 1 + countRecursion(head.next);
1717
}
1818

Diff for: src/main/java/com/thealgorithms/datastructures/lists/MergeSortedSinglyLinkedList.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public static SinglyLinkedList merge(SinglyLinkedList listA, SinglyLinkedList li
4242
throw new NullPointerException("Input lists must not be null.");
4343
}
4444

45-
Node headA = listA.getHead();
46-
Node headB = listB.getHead();
45+
SinglyLinkedListNode headA = listA.getHead();
46+
SinglyLinkedListNode headB = listB.getHead();
4747
int size = listA.size() + listB.size();
4848

49-
Node head = new Node();
50-
Node tail = head;
49+
SinglyLinkedListNode head = new SinglyLinkedListNode();
50+
SinglyLinkedListNode tail = head;
5151
while (headA != null && headB != null) {
5252
if (headA.value <= headB.value) {
5353
tail.next = headA;

Diff for: src/main/java/com/thealgorithms/datastructures/lists/QuickSortLinkedList.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
public class QuickSortLinkedList {
106106

107107
private final SinglyLinkedList list; // The linked list to be sorted
108-
private Node head; // Head of the list
108+
private SinglyLinkedListNode head; // Head of the list
109109

110110
/**
111111
* Constructor that initializes the QuickSortLinkedList with a given linked list.
@@ -136,19 +136,19 @@ public void sortList() {
136136
* @param head The head node of the list to sort
137137
* @return The head node of the sorted linked list
138138
*/
139-
private Node sortList(Node head) {
139+
private SinglyLinkedListNode sortList(SinglyLinkedListNode head) {
140140
if (head == null || head.next == null) {
141141
return head;
142142
}
143143

144-
Node pivot = head;
144+
SinglyLinkedListNode pivot = head;
145145
head = head.next;
146146
pivot.next = null;
147147

148-
Node lessHead = new Node();
149-
Node lessTail = lessHead;
150-
Node greaterHead = new Node();
151-
Node greaterTail = greaterHead;
148+
SinglyLinkedListNode lessHead = new SinglyLinkedListNode();
149+
SinglyLinkedListNode lessTail = lessHead;
150+
SinglyLinkedListNode greaterHead = new SinglyLinkedListNode();
151+
SinglyLinkedListNode greaterTail = greaterHead;
152152

153153
while (head != null) {
154154
if (head.value < pivot.value) {
@@ -164,14 +164,14 @@ private Node sortList(Node head) {
164164
lessTail.next = null;
165165
greaterTail.next = null;
166166

167-
Node sortedLess = sortList(lessHead.next);
168-
Node sortedGreater = sortList(greaterHead.next);
167+
SinglyLinkedListNode sortedLess = sortList(lessHead.next);
168+
SinglyLinkedListNode sortedGreater = sortList(greaterHead.next);
169169

170170
if (sortedLess == null) {
171171
pivot.next = sortedGreater;
172172
return pivot;
173173
} else {
174-
Node current = sortedLess;
174+
SinglyLinkedListNode current = sortedLess;
175175
while (current.next != null) {
176176
current = current.next;
177177
}

Diff for: src/main/java/com/thealgorithms/datastructures/lists/ReverseKGroup.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* </p>
1515
* <p>
1616
* The implementation contains:
17-
* - {@code length(Node head)}: A method to calculate the length of the linked list.
18-
* - {@code reverse(Node head, int count, int k)}: A helper method that reverses the nodes
17+
* - {@code length(SinglyLinkedListNode head)}: A method to calculate the length of the linked list.
18+
* - {@code reverse(SinglyLinkedListNode head, int count, int k)}: A helper method that reverses the nodes
1919
* in the linked list in groups of k.
20-
* - {@code reverseKGroup(Node head, int k)}: The main method that initiates the reversal
20+
* - {@code reverseKGroup(SinglyLinkedListNode head, int k)}: The main method that initiates the reversal
2121
* process by calling the reverse method.
2222
* </p>
2323
* <p>
@@ -38,8 +38,8 @@ public class ReverseKGroup {
3838
* @param head The head node of the linked list.
3939
* @return The total number of nodes in the linked list.
4040
*/
41-
public int length(Node head) {
42-
Node curr = head;
41+
public int length(SinglyLinkedListNode head) {
42+
SinglyLinkedListNode curr = head;
4343
int count = 0;
4444
while (curr != null) {
4545
curr = curr.next;
@@ -56,14 +56,14 @@ public int length(Node head) {
5656
* @param k The size of the group to reverse.
5757
* @return The new head of the reversed linked list segment.
5858
*/
59-
public Node reverse(Node head, int count, int k) {
59+
public SinglyLinkedListNode reverse(SinglyLinkedListNode head, int count, int k) {
6060
if (count < k) {
6161
return head;
6262
}
63-
Node prev = null;
63+
SinglyLinkedListNode prev = null;
6464
int count1 = 0;
65-
Node curr = head;
66-
Node next = null;
65+
SinglyLinkedListNode curr = head;
66+
SinglyLinkedListNode next = null;
6767
while (curr != null && count1 < k) {
6868
next = curr.next;
6969
curr.next = prev;
@@ -85,7 +85,7 @@ public Node reverse(Node head, int count, int k) {
8585
* @param k The size of the group to reverse.
8686
* @return The head of the modified linked list after reversal.
8787
*/
88-
public Node reverseKGroup(Node head, int k) {
88+
public SinglyLinkedListNode reverseKGroup(SinglyLinkedListNode head, int k) {
8989
int count = length(head);
9090
return reverse(head, count, k);
9191
}

Diff for: src/main/java/com/thealgorithms/datastructures/lists/RotateSinglyLinkedLists.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ public class RotateSinglyLinkedLists {
3838
* @param k The number of positions to rotate the list to the right.
3939
* @return The head of the rotated linked list.
4040
*/
41-
public Node rotateRight(Node head, int k) {
41+
public SinglyLinkedListNode rotateRight(SinglyLinkedListNode head, int k) {
4242
if (head == null || head.next == null || k == 0) {
4343
return head;
4444
}
4545

46-
Node curr = head;
46+
SinglyLinkedListNode curr = head;
4747
int len = 1;
4848
while (curr.next != null) {
4949
curr = curr.next;

Diff for: src/main/java/com/thealgorithms/datastructures/lists/SearchSinglyLinkedListRecursion.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class SearchSinglyLinkedListRecursion extends SinglyLinkedList {
3030
* @param key the integer value to be searched for.
3131
* @return {@code true} if the value `key` is present in the list; otherwise, {@code false}.
3232
*/
33-
private boolean searchRecursion(Node node, int key) {
33+
private boolean searchRecursion(SinglyLinkedListNode node, int key) {
3434
return (node != null && (node.value == key || searchRecursion(node.next, key)));
3535
}
3636

0 commit comments

Comments
 (0)