Skip to content

Commit 122b54f

Browse files
authored
Merge branch 'TheAlgorithms:master' into master
2 parents a7f8ff1 + f53bc00 commit 122b54f

32 files changed

+1761
-232
lines changed

DIRECTORY.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
* [TurkishToLatinConversion](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/TurkishToLatinConversion.java)
119119
* [UnitConversions](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/UnitConversions.java)
120120
* [UnitsConverter](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/UnitsConverter.java)
121+
* [WordsToNumber](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/conversions/WordsToNumber.java)
121122
* datastructures
122123
* bags
123124
* [Bag](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/bags/Bag.java)
@@ -425,6 +426,7 @@
425426
* [LongDivision](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/LongDivision.java)
426427
* [LucasSeries](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/LucasSeries.java)
427428
* [MagicSquare](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/MagicSquare.java)
429+
* [MathBuilder](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/MathBuilder.java)
428430
* [MaxValue](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/MaxValue.java)
429431
* [Means](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Means.java)
430432
* [Median](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/maths/Median.java)
@@ -539,6 +541,7 @@
539541
* [PageRank](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/PageRank.java)
540542
* [PasswordGen](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/PasswordGen.java)
541543
* [PerlinNoise](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/PerlinNoise.java)
544+
* [PrintAMatrixInSpiralOrder](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/PrintAMatrixInSpiralOrder.java)
542545
* [QueueUsingTwoStacks](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/QueueUsingTwoStacks.java)
543546
* [RemoveDuplicateFromString](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/RemoveDuplicateFromString.java)
544547
* [ReverseStackUsingRecursion](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/others/ReverseStackUsingRecursion.java)
@@ -838,6 +841,7 @@
838841
* [TurkishToLatinConversionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/TurkishToLatinConversionTest.java)
839842
* [UnitConversionsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/UnitConversionsTest.java)
840843
* [UnitsConverterTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/UnitsConverterTest.java)
844+
* [WordsToNumberTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/WordsToNumberTest.java)
841845
* datastructures
842846
* bag
843847
* [BagTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/datastructures/bag/BagTest.java)
@@ -1100,6 +1104,7 @@
11001104
* [LeonardoNumberTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/LeonardoNumberTest.java)
11011105
* [LongDivisionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/LongDivisionTest.java)
11021106
* [LucasSeriesTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/LucasSeriesTest.java)
1107+
* [MathBuilderTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/MathBuilderTest.java)
11031108
* [MaxValueTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/MaxValueTest.java)
11041109
* [MeansTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/MeansTest.java)
11051110
* [MedianTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/maths/MedianTest.java)
@@ -1193,6 +1198,7 @@
11931198
* [RemoveDuplicateFromStringTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/RemoveDuplicateFromStringTest.java)
11941199
* [ReverseStackUsingRecursionTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/ReverseStackUsingRecursionTest.java)
11951200
* [SkylineProblemTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/SkylineProblemTest.java)
1201+
* [TestPrintMatrixInSpiralOrder](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/TestPrintMatrixInSpiralOrder.java)
11961202
* [TwoPointersTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/TwoPointersTest.java)
11971203
* [WorstFitCPUTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/others/WorstFitCPUTest.java)
11981204
* puzzlesandgames

pmd-exclude.properties

Lines changed: 0 additions & 25 deletions
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

pom.xml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<dependency>
2121
<groupId>org.junit</groupId>
2222
<artifactId>junit-bom</artifactId>
23-
<version>5.12.0</version>
23+
<version>5.12.1</version>
2424
<type>pom</type>
2525
<scope>import</scope>
2626
</dependency>
@@ -42,7 +42,7 @@
4242
<dependency>
4343
<groupId>org.mockito</groupId>
4444
<artifactId>mockito-core</artifactId>
45-
<version>5.16.0</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,14 +115,14 @@
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>
123122
<plugin>
124123
<groupId>com.github.spotbugs</groupId>
125124
<artifactId>spotbugs-maven-plugin</artifactId>
126-
<version>4.9.2.0</version>
125+
<version>4.9.3.0</version>
127126
<configuration>
128127
<excludeFilterFile>spotbugs-exclude.xml</excludeFilterFile>
129128
<includeTests>true</includeTests>

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

Lines changed: 9 additions & 6 deletions
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);

0 commit comments

Comments
 (0)