public static long parse ( String s , boolean clamp ) { if ( s == null || s . length ( ) == 0 || ! Character . isDigit ( s . charAt ( 0 ) ) ) throw new NumberFormatException ( ) ; long value = 0 ; long ttl = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char c = s . charAt ( i ) ; long oldvalue = value ; if ( Character . isDigit ( c ) ) { value = ( value * 10 ) + Character . getNumericValue ( c ) ; if ( value < oldvalue ) throw new NumberFormatException ( ) ; } else { switch ( Character . toUpperCase ( c ) ) { case ' ' : value *= 7 ; case ' ' : value *= 24 ; case ' ' : value *= 60 ; case ' ' : value *= 60 ; case ' ' : break ; default : throw new NumberFormatException ( ) ; } ttl += value ; value = 0 ; if ( ttl > 0xFFFFFFFF L ) throw new NumberFormatException ( ) ; } } if ( ttl == 0 ) ttl = value ; if ( ttl > 0xFFFFFFFF L ) throw new NumberFormatException ( ) ; else if ( ttl > MAX_VALUE && clamp ) ttl = MAX_VALUE ; return ttl ; }
Parses a TTL - like value which can either be expressed as a number or a BIND - style string with numbers and units .