public List<File> sampleFiles(int number,FilenameFilter filter){
  log.info("Sampling " + number + " files from "+ fromFolder.toString());
  if (toFolder != null) {
    log.info("Copying sampled files to " + toFolder.toString());
  }
  List<File> result=null;
  File[] fileList=fromFolder.listFiles(filter);
  if (fileList.length > 0) {
    result=new ArrayList<File>();
    if (fileList.length < number) {
      log.warn("Although " + number + " files were requested, only "+ fileList.length+ " are available");
    }
    MyPermutator mp=new MyPermutator();
    ArrayList<Integer> permutation=mp.permutate(fileList.length);
    for (int i=0; i < Math.min(number,fileList.length); i++) {
      File theFile=fileList[permutation.get(i) - 1];
      if (toFolder != null) {
        boolean checkMove=copyFile(toFolder,theFile);
        if (!checkMove) {
          log.warn("Could not successfully relocate " + theFile.toString());
        }
      }
      result.add(theFile);
    }
  }
 else {
    log.warn("The folder contains no relevant files. A null list is returned!");
  }
  log.info("File sampling complete.");
  return result;
}

public List < File > sampleFiles ( int number , FilenameFilter filter ) { log . info ( "Sampling " + number + " files from " + fromFolder . toString ( ) ) ; if ( toFolder != null ) { log . info ( "Copying sampled files to " + toFolder . toString ( ) ) ; } List < File > result = null ; File [ ] fileList = fromFolder . listFiles ( filter ) ; if ( fileList . length > 0 ) { result = new ArrayList < File > ( ) ; if ( fileList . length < number ) { log . warn ( "Although " + number + " files were requested, only " + fileList . length + " are available" ) ; } MyPermutator mp = new MyPermutator ( ) ; ArrayList < Integer > permutation = mp . permutate ( fileList . length ) ; for ( int i = 0 ; i < Math . min ( number , fileList . length ) ; i ++ ) { File theFile = fileList [ permutation . get ( i ) - 1 ] ; if ( toFolder != null ) { boolean checkMove = copyFile ( toFolder , theFile ) ; if ( ! checkMove ) { log . warn ( "Could not successfully relocate " + theFile . toString ( ) ) ; } } result . add ( theFile ) ; } } else { log . warn ( "The folder contains no relevant files. A null list is returned!" ) ; } log . info ( "File sampling complete." ) ; return result ; }
the method samples from a filtered file list .
