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

automated.process.strings.StringProcess Maven / Gradle / Ivy

The newest version!
package automated.process.strings;

import org.apache.commons.validator.routines.UrlValidator;

/**
 * Created by Ismail on 12/25/2017.
 * This class contains all related methods for processing strings
 * and do some operations to The provided strings
 */
public class StringProcess {

    /*************** Class Methods Section ***************/
    // This method split String of white spaces and return asList
    public static String[] getStringAsArray(String string) {
        return getStringAsArray(string, "\\s+");
    }

    // This method split String of provided expression and return asList
    public static String[] getStringAsArray(String string, String expressions) {
        return string.split(expressions) != null ? string.split(expressions) : null;
    }

    // This method validate Provided String as URL and return true or false
    public static boolean validateURL(String url) {
        // Validate if URL contains multiple //
        // and replace all duplicated slashes with one slash
        while (url.contains("//"))
            url = url.replace("//", "/");
        // Fix http:// issue cause in previous while it is removed
        // to be as one slash so we need to return that double slashes
        url = url.replaceFirst(":/", "://");
        // Check if URL contains localhost then will return true
        if (!url.contains("localhost"))// Else will validate the URL
            return UrlValidator.getInstance().isValid(url);
        else if (url.contains("localhost"))// If contains localhost return true
            return true;
        else// If URL is invalid and doesn't contains localhost then return false
            return false;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy