public static @ CheckForNull String hashify ( String spec ) { if ( spec . contains ( "H" ) ) { // if someone is already using H, presumably he knows what it is, so a warning is likely false positive return null ; } else if ( spec . startsWith ( "*/" ) ) { // "*/15 ...." (every N minutes) to hash return "H" + spec . substring ( 1 ) ; } else if ( spec . matches ( "\\d+ .+" ) ) { // "0 ..." (certain minute) to hash return "H " + spec . substring ( spec . indexOf ( ' ' ) + 1 ) ; } else { Matcher m = Pattern . compile ( "0(,(\\d+)(,\\d+)*)( .+)" ) . matcher ( spec ) ; if ( m . matches ( ) ) { // 0,15,30,45 to H/15 int period = Integer . parseInt ( m . group ( 2 ) ) ; if ( period > 0 ) { StringBuilder b = new StringBuilder ( ) ; for ( int i = period ; i < 60 ; i += period ) { b . append ( ' ' ) . append ( i ) ; } if ( b . toString ( ) . equals ( m . group ( 1 ) ) ) { return "H/" + period + m . group ( 4 ) ; } } } return null ; } }
Checks a prospective crontab specification to see if it could benefit from balanced hashes .