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

📄 wireconfig.java

📁 j2me实现的移动机器人代码(Java实现)
💻 JAVA
字号:
package name.lxm.robot.arch;

import java.util.*;
import org.jdom.*;

public class WireConfig
{
	public class WireTarget{
		public static final String WTT_DIRECT = "direct";
		public static final String WTT_SUPPRESS = "suppress";
		public static final String WTT_INHIBATED = "inhibated";
		
		private String t_module;
		private String t_port;
		private String type;
		private long duration;
		
		public WireTarget(String t_module, String t_port, String type, long duration)
		{
			this.t_module = t_module;
			this.t_port = t_port;
			this.type = type;
			this.duration = duration;
		}

		public String getTModule()
		{
			return t_module;
		}

		public String getTPort()
		{
			return t_port;
		}

		public String getType()
		{
			return type;
		}

		public long getDuration()
		{
			return duration;
		}

	}
	
	private String src_module;
	private String id;
	private String src_port;
	private ArrayList wire_targets = new ArrayList();

	public WireConfig()
	{
	}

	public WireConfig(Element e)
		throws IllegalXMLFormatException
	{
		loadFromXML(e);
	}

	public void loadFromXML(Element e) 
		throws IllegalXMLFormatException
	{
		if(e.getName().equals("wire"))
		{
			//right, let's go
			this.src_module = e.getAttributeValue("src_module");
			this.src_port = e.getAttributeValue("src_port");
			this.id = e.getAttributeValue("id");
			
			List l = e.getChildren("target");
			for(int i=0; i<l.size();i++)
			{
				Element e2 = (Element) l.get(i);
				String t_m = e2.getAttributeValue("target_module");
				String t_p = e2.getAttributeValue("target_port");
				String t = e2.getAttributeValue("type");
				long duration = 0;
				if(!t.equals(WireTarget.WTT_DIRECT))
				{
					String v = e2.getAttributeValue("duration");
					if(v == null) throw new IllegalXMLFormatException("Not direct type wire target should have duration value.");
					duration = Long.parseLong(v);
				}
				wire_targets.add(new WireTarget(t_m, t_p, t, duration));
			}
		}else
			throw new IllegalXMLFormatException("Wrong format, should have the tag named by ``wire''.");
	}

	public String getSourceModule()
	{
		return src_module;
	}

	public String getSourcePort()
	{
		return src_port;
	}

	public List getWireTargets()
	{
		return wire_targets;
	}

	public String getID()
	{
		return id;
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -