public static Duration parse ( String value ) { /* * Implementation note: Regular expressions are not used to improve * performance. */ if ( value . length ( ) == 0 ) { throw parseError ( value ) ; } int index = 0 ; char first = value . charAt ( index ) ; boolean prior = ( first == ' ' ) ; if ( first == ' ' || first == ' ' ) { index ++ ; } if ( value . charAt ( index ) != ' ' ) { throw parseError ( value ) ; } Builder builder = new Builder ( ) ; builder . prior ( prior ) ; StringBuilder buffer = new StringBuilder ( ) ; for ( int i = index + 1 ; i < value . length ( ) ; i ++ ) { char c = value . charAt ( i ) ; if ( c == ' ' ) { /* * A "T" character is supposed to immediately precede the time * component value(s). It is required by the syntax, but not * really necessary. Ignore it. */ continue ; } if ( c >= ' ' && c <= ' ' ) { buffer . append ( c ) ; continue ; } if ( buffer . length ( ) == 0 ) { throw parseError ( value ) ; } Integer num = Integer . valueOf ( buffer . toString ( ) ) ; buffer . setLength ( 0 ) ; switch ( c ) { case ' ' : builder . weeks ( num ) ; break ; case ' ' : builder . days ( num ) ; break ; case ' ' : builder . hours ( num ) ; break ; case ' ' : builder . minutes ( num ) ; break ; case ' ' : builder . seconds ( num ) ; break ; default : throw parseError ( value ) ; } } return builder . build ( ) ; }
Parses a duration string .