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