Skip to content

Commit c54b8cd

Browse files
authored
Fix formatting of FloodFill (TheAlgorithms#4361)
1 parent a88abb7 commit c54b8cd

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/main/java/com/thealgorithms/backtracking/FloodFill.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
* Java program for Flood fill algorithm.
55
* @author Akshay Dubey (<a href="https://github.com/itsAkshayDubey">Git-Akshay Dubey</a>)
66
*/
7-
public class FloodFill {
7+
public final class FloodFill {
8+
private FloodFill() {
9+
}
810

911
/**
1012
* Get the color at the given coordinates of a 2D image
@@ -14,7 +16,7 @@ public class FloodFill {
1416
* @param y The y co-ordinate of which color is to be obtained
1517
*/
1618

17-
public static int getPixel(int[][] image, int x, int y) {
19+
public static int getPixel(final int[][] image, final int x, final int y) {
1820
return image[x][y];
1921
}
2022

@@ -25,7 +27,7 @@ public static int getPixel(int[][] image, int x, int y) {
2527
* @param x The x co-ordinate at which color is to be filled
2628
* @param y The y co-ordinate at which color is to be filled
2729
*/
28-
public static void putPixel(int[][] image, int x, int y, int newColor) {
30+
public static void putPixel(final int[][] image, final int x, final int y, final int newColor) {
2931
image[x][y] = newColor;
3032
}
3133

@@ -38,11 +40,10 @@ public static void putPixel(int[][] image, int x, int y, int newColor) {
3840
* @param newColor The new color which to be filled in the image
3941
* @param oldColor The old color which is to be replaced in the image
4042
*/
41-
public static void floodFill(int[][] image, int x, int y, int newColor, int oldColor) {
42-
if (newColor == oldColor) return;
43-
if (x < 0 || x >= image.length) return;
44-
if (y < 0 || y >= image[x].length) return;
45-
if (getPixel(image, x, y) != oldColor) return;
43+
public static void floodFill(final int[][] image, final int x, final int y, final int newColor, final int oldColor) {
44+
if (newColor == oldColor || x < 0 || x >= image.length || y < 0 || y >= image[x].length || getPixel(image, x, y) != oldColor) {
45+
return;
46+
}
4647

4748
putPixel(image, x, y, newColor);
4849

0 commit comments

Comments
 (0)