private boolean relevant ( File currentLogFile , GregorianCalendar lastRelevantDate ) { String fileName = currentLogFile . getName ( ) ; Pattern p = Pattern . compile ( APPENER_DATE_DEFAULT_PATTERN ) ; Matcher m = p . matcher ( fileName ) ; if ( m . find ( ) ) { int year = Integer . parseInt ( m . group ( 1 ) ) ; int month = Integer . parseInt ( m . group ( 2 ) ) ; int dayOfMonth = Integer . parseInt ( m . group ( 3 ) ) ; GregorianCalendar fileDate = new GregorianCalendar ( year , month , dayOfMonth ) ; fileDate . add ( Calendar . MONTH , - 1 ) ; //Because of Calendar save the month such that January is 0 return fileDate . compareTo ( lastRelevantDate ) > 0 ; } else { return false ; } }
Get a log file and last relevant date and check if the log file is relevant