?? tochinese.java
字號:
package sun.com.tool;
import java.util.Iterator;
import java.util.List;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.Set;
import sun.com.domain.Box;
import sun.com.domain.Ship;
public class ToChinese {
//此方法用于閱讀配置文件,通過將閱讀的內容放置到一個鍵值對的set集合中
public Set<String> trans(String filePath){
ResourceBundle rb = ResourceBundle.getBundle(filePath);
Set<String> pro = rb.keySet();
return pro;
}
public List<Ship> transitionFile(List<Ship> shiplist)throws MissingResourceException{
//遍歷船
Iterator<Ship> it = shiplist.iterator();
while(it.hasNext()){
//遍歷船得到箱子的集合
Iterator<Box> itb = it.next().getBox().iterator();
//遍歷箱子
while(itb.hasNext()){
Box box = itb.next();
Set<String> sizeList = trans("sun.com.config.Cntsize");
ResourceBundle rb = ResourceBundle.getBundle("sun.com.config.Cntsize");
//遍歷存放key的set值,跟箱子的尺寸比較 得到翻譯后的尺寸
Iterator<String> its = sizeList.iterator();
while(its.hasNext()){
String s = its.next();
if(box.getCntsize().equals(s))
{
box.setCntsize((rb.getString(s)));
break;
}
}
//箱子的類型
Set<String> typeList = trans("sun.com.config.Cnttype");
ResourceBundle rb1 = ResourceBundle.getBundle("sun.com.config.Cnttype");
//遍歷存放key的set值,跟箱子的類型比較 得到翻譯后的類型
Iterator<String> itt = typeList.iterator();
while(itt.hasNext()){
//得到key的值,通過比較key值如果相等就設置箱子的類型
String s = itt.next();
if(box.getCnttype().equals(s))
{
box.setCnttype((rb1.getString(s)));
break;
}
}
//箱子的經營人
//遍歷存放key的set值,跟箱子的經營人比較 得到翻譯后的類型
Set<String> perList =trans("sun.com.config.Cntoperator");
ResourceBundle rb2 = ResourceBundle.getBundle("sun.com.config.Cntoperator");
Iterator<String> itp = perList.iterator();
while(itp.hasNext()){
String s =itp.next();
if(box.getCntoperator().equals(s))
{
box.setCntoperator((rb2.getString(s)));
break;
}
}
}
}
return shiplist;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -