blob: 206bd6b7b1b4acef6836bb2fca275ba2fc269fce (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
package org.testng.internal.annotations;
import org.testng.collections.Lists;
import org.testng.internal.ClassHelper;
import org.testng.internal.Utils;
import java.util.List;
import java.util.StringTokenizer;
/**
* Convert a string values into primitive types.
*
* Created on Dec 20, 2005
* @author cbeust
*/
public class Converter {
public static boolean getBoolean(String tagValue, boolean def) {
boolean result = def;
if (tagValue != null) {
result = Boolean.valueOf(tagValue);
}
return result;
}
public static int getInt(String tagValue, int def) {
int result = def;
if (tagValue != null) {
result = Integer.parseInt(tagValue);
}
return result;
}
public static String getString(String tagValue, String def) {
String result = def;
if (tagValue != null) {
result = tagValue;
}
return result;
}
public static long getLong(String tagValue, long def) {
long result = def;
if (tagValue != null) {
result = Long.parseLong(tagValue);
}
return result;
}
public static String[] getStringArray(String tagValue, String[] def) {
String[] result = def;
if (tagValue != null) {
result = Utils.stringToArray(tagValue);
}
return result;
}
public static Class[] getClassArray(String tagValue, Class[] def) {
Class[] result = def;
List vResult = Lists.newArrayList();
if (tagValue != null) {
StringTokenizer st = new StringTokenizer(tagValue, " ,");
while (st.hasMoreElements()) {
String className = (String) st.nextElement();
try {
Class cls = Class.forName(className);
vResult.add(cls);
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
result = (Class[]) vResult.toArray(new Class[vResult.size()]);
}
return result;
}
public static Class getClass(String namedParameter) {
Class result = null;
if (namedParameter != null) {
result = ClassHelper.forName(namedParameter);
}
return result;
}
}
|