⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tochinese.java

📁 一个java开发的海运系统
💻 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 + -