1717 */
1818package com .github .jknack .handlebars ;
1919
20- import static org .apache .commons .lang3 .Validate .isTrue ;
21- import static org .apache .commons .lang3 .Validate .notNull ;
2220import humanize .Humanize ;
2321
2422import java .io .IOException ;
2523import java .util .Date ;
2624import java .util .Locale ;
2725
2826import com .github .jknack .handlebars .internal .Locales ;
27+ import static java .util .Objects .requireNonNull ;
2928
3029/**
3130 * Handlebars helper for the Humanize library.
@@ -51,7 +50,6 @@ public enum HumanizeHelper implements Helper<Object> {
5150 @ Override
5251 public Object apply (final Object value , final Options options )
5352 throws IOException {
54- isTrue (value instanceof Number , "found '%s', expected: 'number'" , value );
5553 return Humanize .binaryPrefix ((Number ) value , resolveLocale (options ));
5654 }
5755 },
@@ -71,7 +69,6 @@ public Object apply(final Object value, final Options options)
7169 @ Override
7270 public Object apply (final Object value , final Options options )
7371 throws IOException {
74- isTrue (value instanceof String , "found '%s', expected: 'string'" , value );
7572 Boolean capFirst = options .hash ("capFirst" , true );
7673 return Humanize .camelize ((String ) value , capFirst );
7774 }
@@ -92,7 +89,6 @@ public Object apply(final Object value, final Options options)
9289 @ Override
9390 public Object apply (final Object value , final Options options )
9491 throws IOException {
95- isTrue (value instanceof String , "found '%s', expected: 'string'" , value );
9692 return Humanize .capitalize ((String ) value );
9793 }
9894 },
@@ -112,7 +108,6 @@ public Object apply(final Object value, final Options options)
112108 @ Override
113109 public Object apply (final Object value , final Options options )
114110 throws IOException {
115- isTrue (value instanceof String , "found '%s', expected: 'string'" , value );
116111 String replacement = options .hash ("replacement" , " " );
117112 return Humanize .decamelize ((String ) value , replacement );
118113 }
@@ -133,7 +128,6 @@ public Object apply(final Object value, final Options options)
133128 @ Override
134129 public Object apply (final Object value , final Options options )
135130 throws IOException {
136- isTrue (value instanceof Number , "found '%s', expected: 'number'" , value );
137131 return Humanize .formatCurrency ((Number ) value , resolveLocale (options ));
138132 }
139133 },
@@ -153,7 +147,6 @@ public Object apply(final Object value, final Options options)
153147 @ Override
154148 public Object apply (final Object value , final Options options )
155149 throws IOException {
156- isTrue (value instanceof Number , "found '%s', expected: 'number'" , value );
157150 return Humanize .formatPercent ((Number ) value , resolveLocale (options ));
158151 }
159152 },
@@ -174,7 +167,6 @@ public Object apply(final Object value, final Options options)
174167 @ Override
175168 public Object apply (final Object value , final Options options )
176169 throws IOException {
177- isTrue (value instanceof Number , "found '%s', expected: 'number'" , value );
178170 return Humanize .metricPrefix ((Number ) value , resolveLocale (options ));
179171 }
180172 },
@@ -194,7 +186,6 @@ public Object apply(final Object value, final Options options)
194186 @ Override
195187 public Object apply (final Object value , final Options options )
196188 throws IOException {
197- isTrue (value instanceof Date , "found '%s', expected: 'date'" , value );
198189 return Humanize .naturalDay ((Date ) value );
199190 }
200191 },
@@ -216,7 +207,6 @@ public Object apply(final Object value, final Options options)
216207 @ Override
217208 public Object apply (final Object value , final Options options )
218209 throws IOException {
219- isTrue (value instanceof Date , "found '%s', expected: 'date'" , value );
220210 return Humanize .naturalTime ((Date ) value , resolveLocale (options ));
221211 }
222212 },
@@ -237,7 +227,6 @@ public Object apply(final Object value, final Options options)
237227 @ Override
238228 public Object apply (final Object value , final Options options )
239229 throws IOException {
240- isTrue (value instanceof Number , "found '%s', expected: 'number'" , value );
241230 return Humanize .ordinal ((Number ) value , resolveLocale (options ));
242231 }
243232 },
@@ -291,7 +280,6 @@ public Object apply(final Object value, final Options options)
291280 @ Override
292281 public Object apply (final Object value , final Options options )
293282 throws IOException {
294- isTrue (value instanceof String , "found '%s', expected: 'string'" , value );
295283 return Humanize .pluralizeFormat ((String ) value , resolveLocale (options ))
296284 .render (options .params );
297285 }
@@ -326,7 +314,6 @@ public Object apply(final Object value, final Options options)
326314 @ Override
327315 public Object apply (final Object value , final Options options )
328316 throws IOException {
329- isTrue (value instanceof String , "found '%s', expected: 'string'" , value );
330317 return Humanize .slugify ((String ) value );
331318 }
332319 },
@@ -347,7 +334,6 @@ public Object apply(final Object value, final Options options)
347334 @ Override
348335 public Object apply (final Object value , final Options options )
349336 throws IOException {
350- isTrue (value instanceof Number , "found '%s', expected: 'number'" , value );
351337 return Humanize .spellBigNumber ((Number ) value , resolveLocale (options ));
352338 }
353339 },
@@ -368,7 +354,6 @@ public Object apply(final Object value, final Options options)
368354 @ Override
369355 public Object apply (final Object value , final Options options )
370356 throws IOException {
371- isTrue (value instanceof Number , "found '%s', expected: 'number'" , value );
372357 return Humanize .spellDigit ((Number ) value , resolveLocale (options ));
373358 }
374359 },
@@ -389,7 +374,6 @@ public Object apply(final Object value, final Options options)
389374 @ Override
390375 public Object apply (final Object value , final Options options )
391376 throws IOException {
392- isTrue (value instanceof String , "found '%s', expected: 'string'" , value );
393377 return Humanize .titleize ((String ) value );
394378 }
395379 },
@@ -409,7 +393,6 @@ public Object apply(final Object value, final Options options)
409393 @ Override
410394 public Object apply (final Object value , final Options options )
411395 throws IOException {
412- isTrue (value instanceof String , "found '%s', expected: 'string'" , value );
413396 return Humanize .transliterate ((String ) value );
414397 }
415398 },
@@ -429,7 +412,6 @@ public Object apply(final Object value, final Options options)
429412 @ Override
430413 public Object apply (final Object value , final Options options )
431414 throws IOException {
432- isTrue (value instanceof String , "found '%s', expected: 'string'" , value );
433415 return Humanize .underscore ((String ) value );
434416 }
435417 },
@@ -450,11 +432,8 @@ public Object apply(final Object value, final Options options)
450432 @ Override
451433 public Object apply (final Object value , final Options options )
452434 throws IOException {
453- isTrue (value instanceof String , "found '%s', expected: 'string'" , value );
454435 Number length = options .param (0 , null );
455- notNull (length , "found 'null', expected 'word wrap length'" );
456- isTrue (length .intValue () > 0 , "found '%s', expected 'a positive number'" ,
457- length );
436+ requireNonNull (length , "found 'null', expected 'word wrap length'" );
458437 return Humanize .wordWrap ((String ) value , length .intValue ());
459438 }
460439 };
@@ -476,7 +455,6 @@ protected static Locale resolveLocale(final Options options) {
476455 * @param handlebars The helper's owner.
477456 */
478457 public static void register (final Handlebars handlebars ) {
479- notNull (handlebars , "A handlebars object is required." );
480458 for (HumanizeHelper helper : values ()) {
481459 handlebars .registerHelper (helper .name (), helper );
482460 }
0 commit comments