public Map<String,List<File>> findFilesGroupedByBaseName(){
  Map<String,List<File>> baseLogFiles=new HashMap<String,List<File>>();
  String fileName;
  List<File> logFiles=getAllFilesMatchingGlobPattern();
  List<File> sameBaseFiles;
  for (  File file : logFiles) {
    String baseName;
    fileName=file.getName();
    int dashIndex=fileName.indexOf("-");
    int dotIndex=fileName.indexOf(".");
    int subIndex;
    if (dotIndex > 0 && dashIndex > 0) {
      subIndex=(dotIndex < dashIndex) ? dotIndex : dashIndex;
    }
 else {
      subIndex=dotIndex > 0 ? dotIndex : dashIndex;
    }
    if (subIndex > 0) {
      baseName=fileName.substring(0,subIndex);
    }
 else {
      baseName=fileName;
    }
    logger.debug("fileName: {}. baseName: {}",fileName,baseName);
    if ((sameBaseFiles=baseLogFiles.get(baseName)) == null) {
      sameBaseFiles=new ArrayList<File>();
    }
    sameBaseFiles.add(file);
    baseLogFiles.put(baseName,sameBaseFiles);
  }
  return baseLogFiles;
}

public Map < String , List < File > > findFilesGroupedByBaseName ( ) { Map < String , List < File > > baseLogFiles = new HashMap < String , List < File > > ( ) ; String fileName ; List < File > logFiles = getAllFilesMatchingGlobPattern ( ) ; List < File > sameBaseFiles ; for ( File file : logFiles ) { String baseName ; fileName = file . getName ( ) ; int dashIndex = fileName . indexOf ( "-" ) ; int dotIndex = fileName . indexOf ( "." ) ; int subIndex ; if ( dotIndex > 0 && dashIndex > 0 ) { subIndex = ( dotIndex < dashIndex ) ? dotIndex : dashIndex ; } else { subIndex = dotIndex > 0 ? dotIndex : dashIndex ; } if ( subIndex > 0 ) { baseName = fileName . substring ( 0 , subIndex ) ; } else { baseName = fileName ; } logger . debug ( "fileName: {}. baseName: {}" , fileName , baseName ) ; if ( ( sameBaseFiles = baseLogFiles . get ( baseName ) ) == null ) { sameBaseFiles = new ArrayList < File > ( ) ; } sameBaseFiles . add ( file ) ; baseLogFiles . put ( baseName , sameBaseFiles ) ; } return baseLogFiles ; }
groups files by their base name as key and rolled files as values .
