public static final int getDurationInterval ( final String duration ) { if ( duration == null || duration . isEmpty ( ) ) { throw new IllegalArgumentException ( "Duration cannot be null or empty" ) ; } if ( duration . contains ( "." ) ) { throw new IllegalArgumentException ( "Floating point intervals are not supported" ) ; } int unit = 0 ; while ( Character . isDigit ( duration . charAt ( unit ) ) ) { unit ++ ; } int interval ; try { interval = Integer . parseInt ( duration . substring ( 0 , unit ) ) ; } catch ( NumberFormatException e ) { throw new IllegalArgumentException ( "Invalid duration (number): " + duration ) ; } if ( interval <= 0 ) { throw new IllegalArgumentException ( "Zero or negative duration: " + duration ) ; } return interval ; }
Parses the prefix of the duration the interval and returns it as a number . E . g . if you supply 1d it will return 1 . If you supply 60m it will return 60 .