Project

General

Profile

1
package eu.dnetlib.util;
2

    
3
import java.net.MalformedURLException;
4
import java.net.URL;
5

    
6
public class UtilityFunctions {
7

    
8
	public static boolean isEmpty(String str) {
9
		return str == null || str.trim().length() == 0;
10
	}
11

    
12
	/**
13
	 * Filters a string. Returns the string of "" if the string is null
14
	 * 
15
	 * @param str
16
	 *            the string to be filter
17
	 * @return the actual string or "" if str is null
18
	 */
19
	public static String filterNull(String str) {
20
		return str == null ? "" : str;
21
	}
22

    
23
	public static boolean nonEmpty(String str) {
24
		return !isEmpty(str);
25
	}
26

    
27
	public static boolean isValidURL(String str) {
28
		if (isEmpty(str))
29
			return false;
30

    
31
		boolean valid = true;
32
		try {
33
			new URL(str.trim());
34
		} catch (MalformedURLException e) {
35
			valid = false;
36
		}
37
		return valid;
38
	}
39
}
(3-3/3)