Skip to content

Commit

Permalink
Fixed checkstyle errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sharara6 committed Dec 6, 2024
1 parent c507690 commit da4c5d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
12 changes: 8 additions & 4 deletions src/main/java/array/ArrayModeSnippet.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,23 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* ArrayModeSnippet.
*/

public class ArrayModeSnippet {

/** Returns the mode of the array and if multiple modes exists it returns them. */
/**
* Private constructor to prevent instantiation.
*/
private ArrayModeSnippet() {
throw new IllegalStateException("Utility class");
}
/** The function that calculates the mode. */

/**
* Returns the mode(s) of the array.
* If multiple modes exist, it returns them in a list.
*/
public static List<Integer> modeArray(int[] arr) {
int maxCount = 0;
HashMap<Integer, Integer> frequencyMap = new HashMap<>();
Expand All @@ -56,4 +61,3 @@ public static List<Integer> modeArray(int[] arr) {
return modes;
}
}

9 changes: 4 additions & 5 deletions src/test/java/array/ArrayModeSnippetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,16 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

import java.util.List;
import org.junit.jupiter.api.Test;

/**
* Tests for 30 Seconds of Java code library.
*/
class ArrayModeSnippetTest {
/**
* Test for {@link ArrayModeSnippet #ArrayModeSnippet(int[])}.
*/
* Test for {@link ArrayModeSnippet #ArrayModeSnippet(int[])}.
*/
@Test
void testModeArray() {
assertEquals(List.of(2), ArrayModeSnippet.modeArray(new int[]{1, 2, 2, 3}));
Expand All @@ -45,4 +44,4 @@ void testModeArray() {
assertEquals(List.of(), ArrayModeSnippet.modeArray(new int[]{}));
assertEquals(List.of(-1, -2), ArrayModeSnippet.modeArray(new int[]{-1, -1, -2, -2, -3}));
}
}
}

0 comments on commit da4c5d2

Please sign in to comment.