public static List<File> sampleFiles(File folder,int number,FileFilter filter){
  List<File> result=null;
  if (!folder.exists() || !folder.isDirectory() || !folder.canRead()) {
    LOG.error("Could not read from " + folder.getAbsolutePath());
    return null;
  }
  File[] fileList=folder.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");
    }
    int[] permutation=RandomPermutation.getRandomPermutation(fileList.length);
    int index=0;
    while (result.size() < number && index < permutation.length) {
      result.add(fileList[permutation[index++] - 1]);
    }
    LOG.info("File sampling complete, " + result.size() + " returned.");
    return result;
  }
 else {
    LOG.warn("The folder contains no relevant files. A null object is returned!");
    return null;
  }
}

public static List < File > sampleFiles ( File folder , int number , FileFilter filter ) { List < File > result = null ; if ( ! folder . exists ( ) || ! folder . isDirectory ( ) || ! folder . canRead ( ) ) { LOG . error ( "Could not read from " + folder . getAbsolutePath ( ) ) ; return null ; } File [ ] fileList = folder . 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" ) ; } int [ ] permutation = RandomPermutation . getRandomPermutation ( fileList . length ) ; int index = 0 ; while ( result . size ( ) < number && index < permutation . length ) { result . add ( fileList [ permutation [ index ++ ] - 1 ] ) ; } LOG . info ( "File sampling complete, " + result . size ( ) + " returned." ) ; return result ; } else { LOG . warn ( "The folder contains no relevant files. A null object is returned!" ) ; return null ; } }
the method samples from a filtered file list .
