4
4
* Java program for Flood fill algorithm.
5
5
* @author Akshay Dubey (<a href="https://github.com/itsAkshayDubey">Git-Akshay Dubey</a>)
6
6
*/
7
- public class FloodFill {
7
+ public final class FloodFill {
8
+ private FloodFill () {
9
+ }
8
10
9
11
/**
10
12
* Get the color at the given coordinates of a 2D image
@@ -14,7 +16,7 @@ public class FloodFill {
14
16
* @param y The y co-ordinate of which color is to be obtained
15
17
*/
16
18
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 ) {
18
20
return image [x ][y ];
19
21
}
20
22
@@ -25,7 +27,7 @@ public static int getPixel(int[][] image, int x, int y) {
25
27
* @param x The x co-ordinate at which color is to be filled
26
28
* @param y The y co-ordinate at which color is to be filled
27
29
*/
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 ) {
29
31
image [x ][y ] = newColor ;
30
32
}
31
33
@@ -38,11 +40,10 @@ public static void putPixel(int[][] image, int x, int y, int newColor) {
38
40
* @param newColor The new color which to be filled in the image
39
41
* @param oldColor The old color which is to be replaced in the image
40
42
*/
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
+ }
46
47
47
48
putPixel (image , x , y , newColor );
48
49
0 commit comments