private StringBuilder formatNumeric ( Number [ ] hms , StringBuilder appendable ) { // find the start and end of non-nil values in hms array. We have to know if we // have hour-minute; minute-second; or hour-minute-second. int startIndex = - 1 ; int endIndex = - 1 ; for ( int i = 0 ; i < hms . length ; i ++ ) { if ( hms [ i ] != null ) { endIndex = i ; if ( startIndex == - 1 ) { startIndex = endIndex ; } } else { // Replace nil value with 0. hms [ i ] = Integer . valueOf ( 0 ) ; } } // convert hours, minutes, seconds into milliseconds. long millis = ( long ) ( ( ( Math . floor ( hms [ 0 ] . doubleValue ( ) ) * 60.0 + Math . floor ( hms [ 1 ] . doubleValue ( ) ) ) * 60.0 + Math . floor ( hms [ 2 ] . doubleValue ( ) ) ) * 1000.0 ) ; Date d = new Date ( millis ) ; // if hour-minute-second if ( startIndex == 0 && endIndex == 2 ) { return formatNumeric ( d , numericFormatters . getHourMinuteSecond ( ) , DateFormat . Field . SECOND , hms [ endIndex ] , appendable ) ; } // if minute-second if ( startIndex == 1 && endIndex == 2 ) { return formatNumeric ( d , numericFormatters . getMinuteSecond ( ) , DateFormat . Field . SECOND , hms [ endIndex ] , appendable ) ; } // if hour-minute if ( startIndex == 0 && endIndex == 1 ) { return formatNumeric ( d , numericFormatters . getHourMinute ( ) , DateFormat . Field . MINUTE , hms [ endIndex ] , appendable ) ; } throw new IllegalStateException ( ) ; }
values in hms with 0 .