多年未摸java,为了给hive写udf操刀写了一把,哈哈~
import java.util.*;
public class test {private static final String py2zhStr = "All,全部|BD,孟加拉|Unknown,Unknown";
private String result = "";
public static void main(String[] args) {
System.out.println("Hello, it's: ");
System.out.println(new Date());
test taotest=new test();
System.out.println(taotest.evaluate("USaa"));
}
public String evaluate( String text ) {
if ( null == text ) {
return null;
}
String str = text.toString();
HashMap hm=new HashMap();
String[] tmparray = new String[10];
String[] strarray=py2zhStr.split("|");
for (int i = 0; i < strarray.length; i++) {
tmparray = strarray[i].toString().split(",");
if(tmparray.length == 2) {
hm.put(tmparray[0],tmparray[1]);
}
}
if(hm.containsKey(str)) {
result= hm.get(str).toString();
} else {
result= "未知" ;
}
return result;
}
}