propertylist/IPropertylist: removed obsolete loadTextDB_sub()
[metux-java.git] / util / StrUtil.java
blob0c0c26aeee7ae16b9d978f5e3aa1ef392fc18ae1
2 package org.de.metux.util;
4 public class StrUtil
6 public static boolean isEmpty(String str[])
8 if ((str==null)||(str.length==0))
9 return true;
11 for (int x=0; x<str.length; x++)
12 if (!isEmpty(str[x]))
13 return false;
15 return true;
18 public static boolean isEmpty(String str)
20 if ((str==null)||(str.length()==0))
21 return true;
23 str = str.trim();
24 if (str.length()==0)
25 return true;
27 return false;
30 public static String fix_notnull(String str)
32 if (str==null)
33 return "";
34 else
35 return str;
38 public static String fold(String[] str)
40 if (str==null)
41 return "";
43 String res = "";
44 for (int x=0; x<str.length; x++)
45 if (str[x]!=null)
46 res += ((res.length()==0) ? "" : " ")+str[x];
48 return res;
51 public static boolean toBool(String str, boolean def)
53 try
55 return toBool(str);
57 catch (NumberFormatException e)
59 return def;
63 public static boolean toBool(String str)
64 throws NumberFormatException
66 str = str.toLowerCase();
68 if (str.equals("yes") ||
69 str.equals("on") ||
70 str.equals("enabled") ||
71 str.equals("1") ||
72 str.equals("true"))
73 return true;
75 if (str.equals("no") ||
76 str.equals("off") ||
77 str.equals("disabled") ||
78 str.equals("0") ||
79 str.equals("false"))
80 return false;
82 throw new NumberFormatException(str);
85 public String[] trim(String s[])
87 if (s==null)
88 return null;
89 if (s.length==0)
90 return s;
92 int sz = 0;
93 for (int x=0; x<s.length; x++)
95 s[x] = s[x].trim();
96 if (!isEmpty(s[x]))
97 sz++;
100 String n[] = new String[sz];
101 int y = 0;
102 for (int x=0; x<s.length; x++)
103 if (!isEmpty(s[x]))
104 n[y++] = s[x];
106 return n;