package com.capgemini.framework.common;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Class for folder management.
 **/
public final class FolderHelper {

  private FolderHelper() {
    // Constructor of helper classes must be private
  }


  /**
   * Get file list from a specific directory with a filtered extension.
   *
   * @param aDirectory  Directory path containing searched files
   * @param anExtension Extension of searched files (Set to null when all files should be returned)
   * @return List of files
   */
  public static List<String> dirList(final File aDirectory, final String anExtension) {
    List<String> filteredFileList = new ArrayList<>();
    for (String element : aDirectory.list()) {
      if (anExtension == null || (element.endsWith(anExtension))) {
        filteredFileList.add(element);
      }
    }

    return filteredFileList;
  }

}
