@@ -427,190 +427,315 @@ private static Conversion<?> getTypeConversion(
427
427
/**
428
428
* Return the value converted to a byte
429
429
*
430
+ * @param value
431
+ * The value to be converted
432
+ * @throws IllegalArgumentException
433
+ * If the value cannot be converted
430
434
*/
431
435
public static byte asByte (Object value ) {
432
436
return asByte (value ,(byte )0 );
433
437
}
434
438
435
439
/**
436
- * Return the value converted to a byte or the default value
440
+ * Return the value converted to a byte
441
+ * or the specified alternate value if the original value is null. Note,
442
+ * this method still throws {@link IllegalArgumentException} if the value
443
+ * is not null and could not be converted.
437
444
*
438
- */
439
- public static byte asByte (Object value , byte defaultValue ) {
445
+ * @param value
446
+ * The value to be converted
447
+ * @param nullValue
448
+ * The value to be returned if {@link value} is null. Note, this
449
+ * value will not be returned if the conversion fails otherwise.
450
+ * @throws IllegalArgumentException
451
+ * If the value cannot be converted
452
+ */
453
+ public static byte asByte (Object value , byte nullValue ) {
440
454
value =convert (Byte .class ,value );
441
455
if (value !=null ) {
442
456
return ((Byte )value ).byteValue ();
443
457
}
444
458
else {
445
- return defaultValue ;
459
+ return nullValue ;
446
460
}
447
461
}
448
462
449
463
/**
450
464
* Return the value converted to a short
451
465
*
466
+ * @param value
467
+ * The value to be converted
468
+ * @throws IllegalArgumentException
469
+ * If the value cannot be converted
452
470
*/
453
471
public static short asShort (Object value ) {
454
472
return asShort (value ,(short )0 );
455
473
}
456
474
457
475
/**
458
- * Return the value converted to a short or the default value
476
+ * Return the value converted to a short
477
+ * or the specified alternate value if the original value is null. Note,
478
+ * this method still throws {@link IllegalArgumentException} if the value
479
+ * is not null and could not be converted.
459
480
*
460
- */
461
- public static short asShort (Object value , short defaultValue ) {
481
+ * @param value
482
+ * The value to be converted
483
+ * @param nullValue
484
+ * The value to be returned if {@link value} is null. Note, this
485
+ * value will not be returned if the conversion fails otherwise.
486
+ * @throws IllegalArgumentException
487
+ * If the value cannot be converted
488
+ */
489
+ public static short asShort (Object value , short nullValue ) {
462
490
value =convert (Short .class ,value );
463
491
if (value !=null ) {
464
492
return ((Short )value ).shortValue ();
465
493
}
466
494
else {
467
- return defaultValue ;
495
+ return nullValue ;
468
496
}
469
497
}
470
498
471
499
/**
472
500
* Return the value converted to an int
473
501
*
502
+ * @param value
503
+ * The value to be converted
504
+ * @throws IllegalArgumentException
505
+ * If the value cannot be converted
474
506
*/
475
507
public static int asInt (Object value ) {
476
508
return asInt (value ,0 );
477
509
}
478
510
479
511
/**
480
- * Return the value converted to an int or the default value
512
+ * Return the value converted to an int
513
+ * or the specified alternate value if the original value is null. Note,
514
+ * this method still throws {@link IllegalArgumentException} if the value
515
+ * is not null and could not be converted.
481
516
*
482
- */
483
- public static int asInt (Object value , int defaultValue ) {
517
+ * @param value
518
+ * The value to be converted
519
+ * @param nullValue
520
+ * The value to be returned if {@link value} is null. Note, this
521
+ * value will not be returned if the conversion fails otherwise.
522
+ * @throws IllegalArgumentException
523
+ * If the value cannot be converted
524
+ */
525
+ public static int asInt (Object value , int nullValue ) {
484
526
value =convert (Integer .class ,value );
485
527
if (value !=null ) {
486
528
return ((Integer )value ).intValue ();
487
529
}
488
530
else {
489
- return defaultValue ;
531
+ return nullValue ;
490
532
}
491
533
}
492
534
493
535
/**
494
536
* Return the value converted to a long
495
537
*
538
+ * @param value
539
+ * The value to be converted
540
+ * @throws IllegalArgumentException
541
+ * If the value cannot be converted
496
542
*/
497
543
public static long asLong (Object value ) {
498
544
return asLong (value ,0L );
499
545
}
500
546
501
547
/**
502
- * Return the value converted to a long or the default value
548
+ * Return the value converted to a long
549
+ * or the specified alternate value if the original value is null. Note,
550
+ * this method still throws {@link IllegalArgumentException} if the value
551
+ * is not null and could not be converted.
503
552
*
504
- */
505
- public static long asLong (Object value , long defaultValue ) {
553
+ * @param value
554
+ * The value to be converted
555
+ * @param nullValue
556
+ * The value to be returned if {@link value} is null. Note, this
557
+ * value will not be returned if the conversion fails otherwise.
558
+ * @throws IllegalArgumentException
559
+ * If the value cannot be converted
560
+ */
561
+ public static long asLong (Object value , long nullValue ) {
506
562
value =convert (Long .class ,value );
507
563
if (value !=null ) {
508
564
return ((Long )value ).longValue ();
509
565
}
510
566
else {
511
- return defaultValue ;
567
+ return nullValue ;
512
568
}
513
569
}
514
570
515
571
/**
516
572
* Return the value converted to a float
517
573
*
574
+ * @param value
575
+ * The value to be converted
576
+ * @throws IllegalArgumentException
577
+ * If the value cannot be converted
518
578
*/
519
579
public static float asFloat (Object value ) {
520
580
return asFloat (value ,0F );
521
581
}
522
582
523
583
/**
524
- * Return the value converted to a float or the default value
584
+ * Return the value converted to a float
585
+ * or the specified alternate value if the original value is null. Note,
586
+ * this method still throws {@link IllegalArgumentException} if the value
587
+ * is not null and could not be converted.
525
588
*
526
- */
527
- public static float asFloat (Object value , float defaultValue ) {
589
+ * @param value
590
+ * The value to be converted
591
+ * @param nullValue
592
+ * The value to be returned if {@link value} is null. Note, this
593
+ * value will not be returned if the conversion fails otherwise.
594
+ * @throws IllegalArgumentException
595
+ * If the value cannot be converted
596
+ */
597
+ public static float asFloat (Object value , float nullValue ) {
528
598
value =convert (Float .class ,value );
529
599
if (value !=null ) {
530
600
return ((Float )value ).floatValue ();
531
601
}
532
602
else {
533
- return defaultValue ;
603
+ return nullValue ;
534
604
}
535
605
}
536
606
537
607
/**
538
608
* Return the value converted to a double
539
609
*
610
+ * @param value
611
+ * The value to be converted
612
+ * @throws IllegalArgumentException
613
+ * If the value cannot be converted
540
614
*/
541
- public static double asDouble (Object value )
542
- {
615
+ public static double asDouble (Object value ) {
543
616
return asDouble (value ,0D );
544
617
}
545
618
546
619
/**
547
- * Return the value converted to a double or the default value
620
+ * Return the value converted to a double
621
+ * or the specified alternate value if the original value is null. Note,
622
+ * this method still throws {@link IllegalArgumentException} if the value
623
+ * is not null and could not be converted.
548
624
*
549
- */
550
- public static double asDouble (Object value , double defaultValue ) {
625
+ * @param value
626
+ * The value to be converted
627
+ * @param nullValue
628
+ * The value to be returned if {@link value} is null. Note, this
629
+ * value will not be returned if the conversion fails otherwise.
630
+ * @throws IllegalArgumentException
631
+ * If the value cannot be converted
632
+ */
633
+ public static double asDouble (Object value , double nullValue ) {
551
634
value =convert (Double .class ,value );
552
635
return (value !=null )
553
636
? ((Double )value ).doubleValue ()
554
- : defaultValue ;
637
+ : nullValue ;
555
638
}
556
639
557
640
558
641
/**
559
642
* Return the value converted to a char
560
643
*
644
+ * @param value
645
+ * The value to be converted
646
+ * @throws IllegalArgumentException
647
+ * If the value cannot be converted
561
648
*/
562
649
public static char asChar (Object value ) {
563
650
return asChar (value ,(char )0 );
564
651
}
565
652
566
653
567
654
/**
568
- * Return the value converted to a char or the default value
655
+ * Return the value converted to a char
656
+ * or the specified alternate value if the original value is null. Note,
657
+ * this method still throws {@link IllegalArgumentException} if the value
658
+ * is not null and could not be converted.
569
659
*
570
- */
571
- public static char asChar (Object value , char defaultValue ) {
660
+ * @param value
661
+ * The value to be converted
662
+ * @param nullValue
663
+ * The value to be returned if {@link value} is null. Note, this
664
+ * value will not be returned if the conversion fails otherwise.
665
+ * @throws IllegalArgumentException
666
+ * If the value cannot be converted
667
+ */
668
+ public static char asChar (Object value , char nullValue ) {
572
669
value =convert (Character .class ,value );
573
670
return (value !=null )
574
671
? ((Character )value ).charValue ()
575
- : defaultValue ;
672
+ : nullValue ;
576
673
}
577
674
578
675
/**
579
676
* Return the value converted to a boolean
580
677
*
678
+ * @param value
679
+ * The value to be converted
680
+ * @throws IllegalArgumentException
681
+ * If the value cannot be converted
581
682
*/
582
683
public static boolean asBoolean (Object value ) {
583
684
return asBoolean (value ,false );
584
685
}
585
686
586
687
/**
587
- * Return the value converted to a boolean or the default value
688
+ * Return the value converted to a boolean
689
+ * or the specified alternate value if the original value is null. Note,
690
+ * this method still throws {@link IllegalArgumentException} if the value
691
+ * is not null and could not be converted.
588
692
*
589
- */
590
- public static boolean asBoolean (Object value , boolean defaultValue ) {
693
+ * @param value
694
+ * The value to be converted
695
+ * @param nullValue
696
+ * The value to be returned if {@link value} is null. Note, this
697
+ * value will not be returned if the conversion fails otherwise.
698
+ * @throws IllegalArgumentException
699
+ * If the value cannot be converted
700
+ */
701
+ public static boolean asBoolean (Object value , boolean nullValue ) {
591
702
value =convert (Boolean .class ,value );
592
703
return (value !=null )
593
704
? ((Boolean )value ).booleanValue ()
594
- : defaultValue ;
705
+ : nullValue ;
595
706
}
596
707
597
708
/**
598
709
* Return the value converted to a string
599
710
*
711
+ * @param value
712
+ * The value to be converted
713
+ * @throws IllegalArgumentException
714
+ * If the value cannot be converted
600
715
*/
601
716
public static String asString (Object value ) {
602
717
return (String )convert (String .class ,value );
603
718
}
604
719
605
720
/**
606
- * Return the value converted to a string or the default value
721
+ * Return the value converted to a string
722
+ * or the specified alternate value if the original value is null. Note,
723
+ * this method still throws {@link IllegalArgumentException} if the value
724
+ * is not null and could not be converted.
607
725
*
608
- */
609
- public static String asString (Object value , String defaultValue ) {
726
+ * @param value
727
+ * The value to be converted
728
+ * @param nullValue
729
+ * The value to be returned if {@link value} is null. Note, this
730
+ * value will not be returned if the conversion fails otherwise.
731
+ * @throws IllegalArgumentException
732
+ * If the value cannot be converted
733
+ */
734
+ public static String asString (Object value , String nullValue ) {
610
735
value =convert (String .class ,value );
611
736
return (value !=null )
612
737
? (String )value
613
- : defaultValue ;
738
+ : nullValue ;
614
739
}
615
740
616
741
/**
0 commit comments