Repository: TheAlgorithms/Java
Pull request #6120 (2025-01-08 20:26:46)

Refactoring the files to be in correctly nested packages
<!--
Thank you for your contribution!
In order to reduce the number of notifications sent to the maintainers, please:
- create your PR as draft, cf. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests#draft-pull-requests,
- make sure that all of the CI checks pass,
- mark your PR as ready for review, cf. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-stage-of-a-pull-request#marking-a-pull-request-as-ready-for-review
-->

<!-- For completed items, change [ ] to [x] -->

- [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Java/blob/master/CONTRIBUTING.md).
- [x] This pull request is all my own work -- I have not plagiarized it.
- [ ] All filenames are in PascalCase.
- [ ] All functions and variable names follow Java naming conventions.
- [ ] All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
- [ ] All new code is formatted with `clang-format -i --style=file path/to/your/file.java`

codecov-commenter: ## [Codecov](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6120?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms) Report
Attention: Patch coverage is `95.00000%` with `1 line` in your changes missing coverage. Please review.
> Project coverage is 73.79%. Comparing base [(`5ab6356`)](https://app.codecov.io/gh/TheAlgorithms/Java/commit/5ab6356090c17cddd953c801eac4abb6ef48c9f1?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms) to head [(`1ab83ac`)](https://app.codecov.io/gh/TheAlgorithms/Java/commit/1ab83acf24d4b7bcc094d868e17d8e9c53cb9f1b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms).

| [Files with missing lines](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6120?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms) | Patch % | Lines |
|---|---|---|
| [...healgorithms/matrix/PrintAMatrixInSpiralOrder.java](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6120?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Fcom%2Fthealgorithms%2Fmatrix%2FPrintAMatrixInSpiralOrder.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms#diff-c3JjL21haW4vamF2YS9jb20vdGhlYWxnb3JpdGhtcy9tYXRyaXgvUHJpbnRBTWF0cml4SW5TcGlyYWxPcmRlci5qYXZh) | 95.00% | [0 Missing and 1 partial :warning: ](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6120?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms) |

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff            @@
##             master    #6120   +/-   ##
=========================================
  Coverage     73.79%   73.79%           
- Complexity     5118     5119    +1     
=========================================
  Files           658      658           
  Lines         17632    17632           
  Branches       3391     3391           
=========================================
+ Hits          13011    13012    +1     
  Misses         4117     4117           
+ Partials        504      503    -1     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/TheAlgorithms/Java/pull/6120?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=TheAlgorithms).

siriak: Please check why build and linter fail, you probably need to fix formatting to fix them
siriak: Or try updating with the base branch
varada610: > Please check why build and linter fail, you probably need to fix formatting to fix them

Im not sure what fails in the build. locally is fine. It says some PMD check failed not sure how to resolve 

siriak: Update your branch first, it may be already resolved in main
![image](https://github.com/user-attachments/assets/ef857e65-c493-45b8-bf1a-ab2bf36c8e3a)

vil02: > > Please check why build and linter fail, you probably need to fix formatting to fix them
> 
> Im not sure what fails in the build. locally is fine. It says some PMD check failed not sure how to resolve

Regarding PMD (cf. [logs](https://github.com/TheAlgorithms/Java/actions/runs/12678906866/job/35337499855?pr=6120)):
```
Warning:  PMD Failure: com.thealgorithms.matrix.matrixexponentiation.Fibonacci:58 Rule:UnnecessaryFullyQualifiedName Priority:4 Unnecessary qualifier 'Fibonacci': 'IDENTITY_MATRIX' is already in scope because it is declared in an enclosing type.
Warning:  PMD Failure: com.thealgorithms.matrix.matrixexponentiation.Fibonacci:65 Rule:UnnecessaryFullyQualifiedName Priority:4 Unnecessary qualifier 'Fibonacci': 'FIB_MATRIX' is already in scope because it is declared in an enclosing type.
```
So it should be enough to remove the `Fibonacci` from the lines 58 and 65.

Regarding clang-format (cf. [logs](https://github.com/TheAlgorithms/Java/actions/runs/12678906862/job/35337500048?pr=6120)):
```
--- ./src/test/java/com/thealgorithms/matrix/InverseOfMatrixTest.java	(original)
+++ ./src/test/java/com/thealgorithms/matrix/InverseOfMatrixTest.java	(reformatted)
@@ -1,8 +1,8 @@
 package com.thealgorithms.matrix;
 
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+
 import java.util.stream.Stream;
-
-import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.Arguments;
 import org.junit.jupiter.params.provider.MethodSource;
```
i.e. move the `static` import to the very top.
vil02: @varada610: as an addition to:
https://github.com/TheAlgorithms/Java/pull/6120#issuecomment-2583943851

After you will fix the PMD issues, please remove this line:
https://github.com/TheAlgorithms/Java/blob/a9633c00007f3e2037d74f358ec917b142e3c630/pmd-exclude.properties#L58
varada610: thanks @vil02 and @siriak for the help . i see build is green
varada610: @siriak @vil02  Require a review to complete the merge

Patch:
diff --git a/pmd-exclude.properties b/pmd-exclude.properties
index f6ee8819..5bf31455 100644
--- a/pmd-exclude.properties
+++ b/pmd-exclude.properties
@@ -55,7 +55,6 @@ com.thealgorithms.maths.SumOfArithmeticSeries=UselessParentheses
 com.thealgorithms.maths.TrinomialTriangle=UselessParentheses
 com.thealgorithms.maths.VampireNumber=CollapsibleIfStatements
 com.thealgorithms.maths.Volume=UselessParentheses
-com.thealgorithms.matrixexponentiation.Fibonacci=UnnecessaryFullyQualifiedName
 com.thealgorithms.misc.Sparsity=UselessParentheses
 com.thealgorithms.misc.ThreeSumProblem=UselessParentheses
 com.thealgorithms.misc.WordBoggle=UselessParentheses
diff --git a/src/main/java/com/thealgorithms/misc/InverseOfMatrix.java b/src/main/java/com/thealgorithms/matrix/InverseOfMatrix.java
similarity index 98%
rename from src/main/java/com/thealgorithms/misc/InverseOfMatrix.java
rename to src/main/java/com/thealgorithms/matrix/InverseOfMatrix.java
index 706feab0..13e795a9 100644
--- a/src/main/java/com/thealgorithms/misc/InverseOfMatrix.java
+++ b/src/main/java/com/thealgorithms/matrix/InverseOfMatrix.java
@@ -1,4 +1,4 @@
-package com.thealgorithms.misc;
+package com.thealgorithms.matrix;
 
 /**
  * This class provides methods to compute the inverse of a square matrix
diff --git a/src/main/java/com/thealgorithms/misc/MatrixTranspose.java b/src/main/java/com/thealgorithms/matrix/MatrixTranspose.java
similarity index 97%
rename from src/main/java/com/thealgorithms/misc/MatrixTranspose.java
rename to src/main/java/com/thealgorithms/matrix/MatrixTranspose.java
index 74368278..f91ebc10 100644
--- a/src/main/java/com/thealgorithms/misc/MatrixTranspose.java
+++ b/src/main/java/com/thealgorithms/matrix/MatrixTranspose.java
@@ -1,4 +1,4 @@
-package com.thealgorithms.misc;
+package com.thealgorithms.matrix;
 
 /**
  *
diff --git a/src/main/java/com/thealgorithms/misc/MedianOfMatrix.java b/src/main/java/com/thealgorithms/matrix/MedianOfMatrix.java
similarity index 95%
rename from src/main/java/com/thealgorithms/misc/MedianOfMatrix.java
rename to src/main/java/com/thealgorithms/matrix/MedianOfMatrix.java
index edeedbbe..c710c60a 100644
--- a/src/main/java/com/thealgorithms/misc/MedianOfMatrix.java
+++ b/src/main/java/com/thealgorithms/matrix/MedianOfMatrix.java
@@ -1,4 +1,4 @@
-package com.thealgorithms.misc;
+package com.thealgorithms.matrix;
 
 import java.util.ArrayList;
 import java.util.Collections;
diff --git a/src/main/java/com/thealgorithms/misc/MirrorOfMatrix.java b/src/main/java/com/thealgorithms/matrix/MirrorOfMatrix.java
similarity index 98%
rename from src/main/java/com/thealgorithms/misc/MirrorOfMatrix.java
rename to src/main/java/com/thealgorithms/matrix/MirrorOfMatrix.java
index 89dfce3f..b24fcba7 100644
--- a/src/main/java/com/thealgorithms/misc/MirrorOfMatrix.java
+++ b/src/main/java/com/thealgorithms/matrix/MirrorOfMatrix.java
@@ -1,4 +1,4 @@
-package com.thealgorithms.misc;
+package com.thealgorithms.matrix;
 
 // Problem Statement
 /*
diff --git a/src/main/java/com/thealgorithms/others/PrintAMatrixInSpiralOrder.java b/src/main/java/com/thealgorithms/matrix/PrintAMatrixInSpiralOrder.java
similarity index 94%
rename from src/main/java/com/thealgorithms/others/PrintAMatrixInSpiralOrder.java
rename to src/main/java/com/thealgorithms/matrix/PrintAMatrixInSpiralOrder.java
index ddc37a91..2e735222 100644
--- a/src/main/java/com/thealgorithms/others/PrintAMatrixInSpiralOrder.java
+++ b/src/main/java/com/thealgorithms/matrix/PrintAMatrixInSpiralOrder.java
@@ -1,62 +1,62 @@
-package com.thealgorithms.others;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class PrintAMatrixInSpiralOrder {
-    /**
-     * Search a key in row and column wise sorted matrix
-     *
-     * @param matrix matrix to be searched
-     * @param row    number of rows matrix has
-     * @param col    number of columns matrix has
-     * @author Sadiul Hakim : https://github.com/sadiul-hakim
-     */
-
-    public List<Integer> print(int[][] matrix, int row, int col) {
-
-        // r traverses matrix row wise from first
-        int r = 0;
-        // c traverses matrix column wise from first
-        int c = 0;
-        int i;
-
-        List<Integer> result = new ArrayList<>();
-
-        while (r < row && c < col) {
-            // print first row of matrix
-            for (i = c; i < col; i++) {
-                result.add(matrix[r][i]);
-            }
-
-            // increase r by one because first row printed
-            r++;
-
-            // print last column
-            for (i = r; i < row; i++) {
-                result.add(matrix[i][col - 1]);
-            }
-
-            // decrease col by one because last column has been printed
-            col--;
-
-            // print rows from last except printed elements
-            if (r < row) {
-                for (i = col - 1; i >= c; i--) {
-                    result.add(matrix[row - 1][i]);
-                }
-
-                row--;
-            }
-
-            // print columns from first except printed elements
-            if (c < col) {
-                for (i = row - 1; i >= r; i--) {
-                    result.add(matrix[i][c]);
-                }
-                c++;
-            }
-        }
-        return result;
-    }
-}
+package com.thealgorithms.matrix;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class PrintAMatrixInSpiralOrder {
+    /**
+     * Search a key in row and column wise sorted matrix
+     *
+     * @param matrix matrix to be searched
+     * @param row    number of rows matrix has
+     * @param col    number of columns matrix has
+     * @author Sadiul Hakim : https://github.com/sadiul-hakim
+     */
+
+    public List<Integer> print(int[][] matrix, int row, int col) {
+
+        // r traverses matrix row wise from first
+        int r = 0;
+        // c traverses matrix column wise from first
+        int c = 0;
+        int i;
+
+        List<Integer> result = new ArrayList<>();
+
+        while (r < row && c < col) {
+            // print first row of matrix
+            for (i = c; i < col; i++) {
+                result.add(matrix[r][i]);
+            }
+
+            // increase r by one because first row printed
+            r++;
+
+            // print last column
+            for (i = r; i < row; i++) {
+                result.add(matrix[i][col - 1]);
+            }
+
+            // decrease col by one because last column has been printed
+            col--;
+
+            // print rows from last except printed elements
+            if (r < row) {
+                for (i = col - 1; i >= c; i--) {
+                    result.add(matrix[row - 1][i]);
+                }
+
+                row--;
+            }
+
+            // print columns from first except printed elements
+            if (c < col) {
+                for (i = row - 1; i >= r; i--) {
+                    result.add(matrix[i][c]);
+                }
+                c++;
+            }
+        }
+        return result;
+    }
+}
diff --git a/src/main/java/com/thealgorithms/others/RotateMatrixBy90Degrees.java b/src/main/java/com/thealgorithms/matrix/RotateMatrixBy90Degrees.java
similarity index 98%
rename from src/main/java/com/thealgorithms/others/RotateMatrixBy90Degrees.java
rename to src/main/java/com/thealgorithms/matrix/RotateMatrixBy90Degrees.java
index 6ad0ef02..9a7f2552 100644
--- a/src/main/java/com/thealgorithms/others/RotateMatrixBy90Degrees.java
+++ b/src/main/java/com/thealgorithms/matrix/RotateMatrixBy90Degrees.java
@@ -1,4 +1,4 @@
-package com.thealgorithms.others;
+package com.thealgorithms.matrix;
 
 import java.util.Scanner;
 /**
diff --git a/src/main/java/com/thealgorithms/matrixexponentiation/Fibonacci.java b/src/main/java/com/thealgorithms/matrix/matrixexponentiation/Fibonacci.java
similarity index 93%
rename from src/main/java/com/thealgorithms/matrixexponentiation/Fibonacci.java
rename to src/main/java/com/thealgorithms/matrix/matrixexponentiation/Fibonacci.java
index afd34933..9c9f97b9 100644
--- a/src/main/java/com/thealgorithms/matrixexponentiation/Fibonacci.java
+++ b/src/main/java/com/thealgorithms/matrix/matrixexponentiation/Fibonacci.java
@@ -1,4 +1,4 @@
-package com.thealgorithms.matrixexponentiation;
+package com.thealgorithms.matrix.matrixexponentiation;
 
 import java.util.Scanner;
 
@@ -55,14 +55,14 @@ public final class Fibonacci {
      */
     public static int[][] fib(int n) {
         if (n == 0) {
-            return Fibonacci.IDENTITY_MATRIX;
+            return IDENTITY_MATRIX;
         } else {
             int[][] cachedResult = fib(n / 2);
             int[][] matrixExpResult = matrixMultiplication(cachedResult, cachedResult);
             if (n % 2 == 0) {
                 return matrixExpResult;
             } else {
-                return matrixMultiplication(Fibonacci.FIB_MATRIX, matrixExpResult);
+                return matrixMultiplication(FIB_MATRIX, matrixExpResult);
             }
         }
     }


Test patch:
diff --git a/src/test/java/com/thealgorithms/misc/InverseOfMatrixTest.java b/src/test/java/com/thealgorithms/matrix/InverseOfMatrixTest.java
similarity index 96%
rename from src/test/java/com/thealgorithms/misc/InverseOfMatrixTest.java
rename to src/test/java/com/thealgorithms/matrix/InverseOfMatrixTest.java
index 2f20de44..930fb377 100644
--- a/src/test/java/com/thealgorithms/misc/InverseOfMatrixTest.java
+++ b/src/test/java/com/thealgorithms/matrix/InverseOfMatrixTest.java
@@ -1,5 +1,4 @@
-package com.thealgorithms.misc;
-
+package com.thealgorithms.matrix;
 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 
 import java.util.stream.Stream;
diff --git a/src/test/java/com/thealgorithms/misc/MatrixTransposeTest.java b/src/test/java/com/thealgorithms/matrix/MatrixTransposeTest.java
similarity index 98%
rename from src/test/java/com/thealgorithms/misc/MatrixTransposeTest.java
rename to src/test/java/com/thealgorithms/matrix/MatrixTransposeTest.java
index cf668807..0457f314 100644
--- a/src/test/java/com/thealgorithms/misc/MatrixTransposeTest.java
+++ b/src/test/java/com/thealgorithms/matrix/MatrixTransposeTest.java
@@ -1,4 +1,4 @@
-package com.thealgorithms.misc;
+package com.thealgorithms.matrix;
 
 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
diff --git a/src/test/java/com/thealgorithms/misc/MedianOfMatrixTest.java b/src/test/java/com/thealgorithms/matrix/MedianOfMatrixTest.java
similarity index 96%
rename from src/test/java/com/thealgorithms/misc/MedianOfMatrixTest.java
rename to src/test/java/com/thealgorithms/matrix/MedianOfMatrixTest.java
index 19bc6685..db66bb2d 100644
--- a/src/test/java/com/thealgorithms/misc/MedianOfMatrixTest.java
+++ b/src/test/java/com/thealgorithms/matrix/MedianOfMatrixTest.java
@@ -1,4 +1,4 @@
-package com.thealgorithms.misc;
+package com.thealgorithms.matrix;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
diff --git a/src/test/java/com/thealgorithms/misc/MirrorOfMatrixTest.java b/src/test/java/com/thealgorithms/matrix/MirrorOfMatrixTest.java
similarity index 98%
rename from src/test/java/com/thealgorithms/misc/MirrorOfMatrixTest.java
rename to src/test/java/com/thealgorithms/matrix/MirrorOfMatrixTest.java
index 0da0cf0f..2d68e1fa 100644
--- a/src/test/java/com/thealgorithms/misc/MirrorOfMatrixTest.java
+++ b/src/test/java/com/thealgorithms/matrix/MirrorOfMatrixTest.java
@@ -1,4 +1,4 @@
-package com.thealgorithms.misc;
+package com.thealgorithms.matrix;
 
 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
diff --git a/src/test/java/com/thealgorithms/others/TestPrintMatrixInSpiralOrder.java b/src/test/java/com/thealgorithms/matrix/TestPrintMatrixInSpiralOrder.java
similarity index 96%
rename from src/test/java/com/thealgorithms/others/TestPrintMatrixInSpiralOrder.java
rename to src/test/java/com/thealgorithms/matrix/TestPrintMatrixInSpiralOrder.java
index 986e72ea..bb415a58 100644
--- a/src/test/java/com/thealgorithms/others/TestPrintMatrixInSpiralOrder.java
+++ b/src/test/java/com/thealgorithms/matrix/TestPrintMatrixInSpiralOrder.java
@@ -1,4 +1,4 @@
-package com.thealgorithms.others;
+package com.thealgorithms.matrix;
 
 import static org.junit.jupiter.api.Assertions.assertIterableEquals;