Subversion Repository Public Repository

litesoft

Diff Revisions 947 vs 948 for /trunk/GWT_Sandbox/FormEngine/src/com/temp/shared/utils/Assert.java

Diff revisions: vs.
  @@ -10,31 +10,27 @@
10 10 /**
11 11 * Assert that "value" is not null.
12 12 *
13 - * @param what
14 - * "field" was the problem on
15 - * @param value
16 - * to check
17 - */
18 - public static void notNull(String what, Object value) {
19 - if (value == null) {
20 - throw nullValue(what);
13 + * @param what "field" was the problem on
14 + * @param value to check
15 + */
16 + public static void notNull( String what, Object value ) {
17 + if ( value == null ) {
18 + throw nullValue( what );
21 19 }
22 20 }
23 21
24 22 /**
25 23 * Assert that "value" is not null or empty and return "value" trimmed.
26 24 *
27 - * @param what
28 - * "field" was the problem on
29 - * @param value
30 - * to check
25 + * @param what "field" was the problem on
26 + * @param value to check
31 27 *
32 28 * @return value minus any leading and trailing spaces
33 29 */
34 - public static String noEmpty(String what, String value) {
35 - value = StringUtils.noEmpty(value);
36 - if (value == null) {
37 - throw nullOrEmpty(what);
30 + public static String noEmpty( String what, String value ) {
31 + value = StringUtils.noEmpty( value );
32 + if ( value == null ) {
33 + throw nullOrEmpty( what );
38 34 }
39 35 return value;
40 36 }
  @@ -43,17 +39,15 @@
43 39 * Assert that "value" is not null or when converted to a String is not
44 40 * empty and then return resulting "value" trimmed.
45 41 *
46 - * @param what
47 - * "field" was the problem on
48 - * @param value
49 - * to check
42 + * @param what "field" was the problem on
43 + * @param value to check
50 44 *
51 45 * @return value converted to a String minus any leading and trailing spaces
52 46 */
53 - public static String noEmptyToString(String what, Object value) {
54 - String strValue = StringUtils.noEmptyToString(value);
55 - if (strValue == null) {
56 - throw nullOrEmpty(what);
47 + public static String noEmptyToString( String what, Object value ) {
48 + String strValue = StringUtils.noEmptyToString( value );
49 + if ( strValue == null ) {
50 + throw nullOrEmpty( what );
57 51 }
58 52 return strValue;
59 53 }
  @@ -62,58 +56,54 @@
62 56 * Assert that "value" is not null or empty (if it is a String) and return
63 57 * "value" trimmed (if it is a String).
64 58 *
65 - * @param what
66 - * "field" was the problem on
67 - * @param value
68 - * to check
59 + * @param what "field" was the problem on
60 + * @param value to check
69 61 *
70 62 * @return value minus any leading and trailing spaces
71 63 */
72 - public static <T> T notNullOrEmpty(String what, T value) {
73 - if (value == null) {
74 - throw nullOrEmpty(what);
64 + public static <T> T notNullOrEmpty( String what, T value ) {
65 + if ( value == null ) {
66 + throw nullOrEmpty( what );
75 67 }
76 - if (value instanceof String) {
77 - value = ObjectUtils.cast(noEmpty(what, value.toString()));
68 + if ( value instanceof String ) {
69 + value = ObjectUtils.cast( noEmpty( what, value.toString() ) );
78 70 }
79 71 return value;
80 72 }
81 73
82 - public static IllegalArgumentException nullValue(String what) {
83 - return new IllegalArgumentException(what + " not allowed to be null");
74 + public static IllegalArgumentException nullValue( String what ) {
75 + return new IllegalArgumentException( what + " not allowed to be null" );
84 76 }
85 77
86 - private static IllegalArgumentException nullOrEmpty(String what) {
87 - return new IllegalArgumentException(what + " not allowed to be null or empty");
78 + private static IllegalArgumentException nullOrEmpty( String what ) {
79 + return new IllegalArgumentException( what + " not allowed to be null or empty" );
88 80 }
89 81
90 82 /**
91 83 * Assert that "value" is not null or empty and is acceptable as a filename.
92 - *
84 + * <p/>
93 85 * While control characters are NOT allowed, all other characters are,
94 86 * however certain characters (see
95 87 * CharacterUtils.UNACCEPTABLE_NON_CONTROL_FILENAME_CHARACTERS) will be
96 88 * replaced with an underscore ('_').
97 89 *
98 - * @param what
99 - * "field" was the problem on
100 - * @param value
101 - * to check - null or empty unacceptable
90 + * @param what "field" was the problem on
91 + * @param value to check - null or empty unacceptable
102 92 *
103 93 * @return value minus any leading and trailing spaces and any illegal
104 - * characters converted to an underscore.
94 + * characters converted to an underscore.
105 95 */
106 - public static String simpleFilenameRequired(String what, String value) {
107 - StringBuilder sb = new StringBuilder(noEmpty(what, value));
108 - for (int i = 0; i < sb.length(); i++) {
109 - char c = sb.charAt(i);
110 - if (CharacterUtils.isControlChar(c)) {
111 - throw new IllegalArgumentException(what + " contained control character at index " + i + " : '" + value + "'");
96 + public static String simpleFilenameRequired( String what, String value ) {
97 + StringBuilder sb = new StringBuilder( noEmpty( what, value ) );
98 + for ( int i = 0; i < sb.length(); i++ ) {
99 + char c = sb.charAt( i );
100 + if ( CharacterUtils.isControlChar( c ) ) {
101 + throw new IllegalArgumentException( what + " contained control character at index " + i + " : '" + value + "'" );
112 102 }
113 - if (CharacterUtils.isUnacceptableNonControlFilenameChar(c)) {
114 - sb.setCharAt(i, '_');
115 - } else if (c == CharacterUtils.HIBIT_SPACE) {
116 - sb.setCharAt(i, ' ');
103 + if ( CharacterUtils.isUnacceptableNonControlFilenameChar( c ) ) {
104 + sb.setCharAt( i, '_' );
105 + } else if ( c == CharacterUtils.HIBIT_SPACE ) {
106 + sb.setCharAt( i, ' ' );
117 107 }
118 108 }
119 109 return sb.toString();
  @@ -122,23 +112,21 @@
122 112 /**
123 113 * Assert that "value" is either null or made up of only the acceptable
124 114 * characters.
125 - *
115 + * <p/>
126 116 * The "acceptable" characters are Ascii values (33-126 inclusive), with the
127 117 * spaces and newlines tolerated.
128 118 *
129 - * @param what
130 - * "field" was the problem on
131 - * @param value
132 - * to check - null unacceptable
119 + * @param what "field" was the problem on
120 + * @param value to check - null unacceptable
133 121 *
134 122 * @return value deNulled for in-lining this method.
135 123 */
136 - public static String displayable7BitAsciiAllowingSpacesAndNewlines(String what, String value) {
137 - value = StringUtils.deNull(value);
138 - for (int i = 0; i < value.length(); i++) {
139 - char c = value.charAt(i);
140 - if (!CharacterUtils.isDisplayable7BitAsciiAllowingSpaceAndNewline(c)) {
141 - throw new IllegalArgumentException(what + " contained unacceptable character at index " + i + " : '" + value + "'");
124 + public static String displayable7BitAsciiAllowingSpacesAndNewlines( String what, String value ) {
125 + value = StringUtils.deNull( value );
126 + for ( int i = 0; i < value.length(); i++ ) {
127 + char c = value.charAt( i );
128 + if ( !CharacterUtils.isDisplayable7BitAsciiAllowingSpaceAndNewline( c ) ) {
129 + throw new IllegalArgumentException( what + " contained unacceptable character at index " + i + " : '" + value + "'" );
142 130 }
143 131 }
144 132 return value;