Subversion Repository Public Repository

litesoft

Diff Revisions 599 vs 600 for /trunk/GWT_Sandbox/FormEngine/src/com/temp/shared/utils/Validate.java

Diff revisions: vs.
  @@ -1,17 +1,58 @@
1 1 package com.temp.shared.utils;
2 2
3 - public class Validate {
4 - public static void notNull(String what, Object toCheck) {
5 - if (toCheck == null) {
6 - throw new IllegalArgumentException(what + " Not Allowed to be Null");
3 + public class Validate
4 + {
5 + public static void notNull( String what, Object toCheck )
6 + {
7 + if ( toCheck == null )
8 + {
9 + throw new IllegalArgumentException( what + " Not Allowed to be Null" );
7 10 }
8 11 }
9 12
10 - public static String noEmpty(String what, String toCheck) {
11 - toCheck = StringUtils.noEmpty(toCheck);
12 - if (toCheck == null) {
13 - throw new IllegalArgumentException(what + " Not Allowed to be Null or Empty");
13 + public static String noEmpty( String what, String toCheck )
14 + {
15 + toCheck = StringUtils.noEmpty( toCheck );
16 + if ( toCheck == null )
17 + {
18 + throw new IllegalArgumentException( what + " Not Allowed to be Null or Empty" );
14 19 }
15 20 return toCheck;
16 21 }
22 +
23 + public static String noEmptyIdentifier( String what, String toCheck )
24 + {
25 + toCheck = noEmpty( what, toCheck );
26 + if ( toCheck != null )
27 + {
28 + int errorIndex = StringUtils.checkIdentifier( toCheck );
29 + if ( errorIndex == 0 )
30 + {
31 + throw new IllegalArgumentException( "First Character Unacceptable for an Identifier: '" + toCheck + "'" );
32 + }
33 + if ( errorIndex != -1 )
34 + {
35 + throw new IllegalArgumentException( "Character (" + (errorIndex + 1) + ":'" + toCheck.charAt( errorIndex ) + "') Unacceptable for an Identifier: '" + toCheck + "'" );
36 + }
37 + }
38 + return toCheck;
39 + }
40 +
41 + public static Integer optionalLength( String what, Integer length )
42 + {
43 + if ( length != null )
44 + {
45 + length( what, length );
46 + }
47 + return length;
48 + }
49 +
50 + public static int length( String what, int length )
51 + {
52 + if ( length < 1 )
53 + {
54 + throw new IllegalArgumentException( what + " Must be at least 1" );
55 + }
56 + return length;
57 + }
17 58 }