All Downloads are FREE. Search and download functionalities are using the official Maven repository.

model.MARK_II.util.BigClassUtil Maven / Gradle / Ivy

The newest version!
package model.MARK_II.util;

import java.io.File;

/**
 * @author Q Liu ([email protected])
 * @version  6/11/2015.
 */
public class BigClassUtil {

    public static String extractFolderName(String pathAndFolderName) {
        // example: String pathAndFolderName = "
        // ./src/test/java/model/experiments/vision/MARK_II/FolderName";
        String[] parts = pathAndFolderName.split("/");
        String folderName = parts[parts.length - 1];
        return folderName;
    }

    public static String extractPath(String pathAndFolderName) {
        int lengthOfFolderName = extractFolderName(pathAndFolderName).length();
        return pathAndFolderName.substring(0, pathAndFolderName.length() -
                lengthOfFolderName);
    }

    public static boolean isFolderInList(String folderName, File[] listOfFilesAndFolders) {
        for (int i = 0; i < listOfFilesAndFolders.length; i++) {

            if (listOfFilesAndFolders[i].isDirectory() &&
                    folderName.equals(listOfFilesAndFolders[i].getName())) {
                return true;
            }
        }
        return false;
    }

    public static boolean isFileInList(String fileName, File[] listOfFilesAndFolders) {
        for (int i = 0; i < listOfFilesAndFolders.length; i++) {

            if (listOfFilesAndFolders[i].isFile() &&
                    fileName.equals(listOfFilesAndFolders[i].getName())) {
                return true;
            }
        }
        return false;
    }

    public static void deleteFolder(File file){
        File[] contents = file.listFiles();
        if (contents != null) {
            for (File f : contents) {
                deleteFolder(f);
            }
        }
        file.delete();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy