/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.umbc.combio.erilllab.jfitom.Util;

import java.io.File;
import java.io.FileFilter;
import java.io.FilenameFilter;
import java.util.List;

/**
 *
 * @author Shehab
 */
public class JFitomWUtil {

    /**
        This method takes the absolute directory path and the file name extension (e.g. .OPT)
     * as input and returns a list of files under that directory with the extension. If there is
     * no file it returns null.
     */
    public static File[] getFilesWithExtUnderDirectory(String directoryPath, String extension){

        File dir = new File(directoryPath);
        if (dir.exists())
        {
            return dir.listFiles(getFilenameFilter(extension));
        }
        return null;

    }

    public static FilenameFilter getFilenameFilter(final String extension){

        FilenameFilter fileNameFilter = new FilenameFilter()
        {
            @Override
            public boolean accept(File dir, String name)
            {
                if (name.toUpperCase().endsWith(extension.trim()))
                {
                    return true;
                }

                return false;
            }
        };

        return fileNameFilter;
    }

    public static FileFilter getFileFilter(final String extension){

      FileFilter fileFilter = new FileFilter()
        {
            @Override
            public boolean accept(File name)
            {
                if (name.getName().toUpperCase().endsWith(extension.trim()))
                {
                    return true;
                }

                return false;
            }
        };

        return fileFilter;
    }

}
