@@ -11,51 +11,51 @@ public class IntegerRule implements ValidationRule {
1111 private final int max ;
1212 private final int step ;
1313
14- public IntegerRule (int min , int max , int step ){
14+ public IntegerRule (int min , int max , int step ) {
1515 this .min = min ;
1616 this .max = max ;
1717 this .step = step ;
1818 }
1919
20- public IntegerRule (int min , int max ){
20+ public IntegerRule (int min , int max ) {
2121 this (min , max , 1 );
2222 }
2323
24- public IntegerRule (String [] params ){
24+ public IntegerRule (String [] params ) {
2525 int min = Integer .MIN_VALUE ;
2626 int max = Integer .MAX_VALUE ;
2727 int step = 1 ;
28- if (params .length > 0 )
28+ if (params .length > 0 )
2929 min = Integer .parseInt (params [0 ]);
30- if (params .length > 1 )
30+ if (params .length > 1 )
3131 max = Integer .parseInt (params [1 ]);
32- if (params .length > 2 )
32+ if (params .length > 2 )
3333 step = Integer .parseInt (params [2 ]);
3434 this .min = min ;
3535 this .max = max ;
3636 this .step = step ;
3737 }
3838
3939 public String validate (ValidationContext context , Field field , AbstractElement value ) {
40- if (value == null )
40+ if (value == null )
4141 return null ;
4242 int v ;
43- if (value .isNumber ()) {
43+ if (value .isNumber ()) {
4444 v = value .number ().intValue ();
45- }else if (value .isString ()){
45+ } else if (value .isString ()) {
4646 try {
4747 v = Integer .parseInt (value .string ());
48- }catch (NumberFormatException ex ){
48+ } catch (NumberFormatException ex ) {
4949 return "Not an integer value" ;
5050 }
51- }else {
51+ } else {
5252 return "Not an integer value" ;
5353 }
54- if (v < min )
54+ if (v < min )
5555 return String .format ("Smaller than the minimum value (%d < %d)" , v , min );
56- if (v > max )
56+ if (v > max )
5757 return String .format ("Greater than the maximum value (%d > %d)" , v , max );
58- if (step > 1 && (v - min ) % step != 0 )
58+ if (step > 1 && (v - min ) % step != 0 )
5959 return String .format ("Not in steps of %d" , step );
6060 return null ;
6161 }
0 commit comments