110,530
社区成员
发帖
与我相关
我的任务
分享
Protocol localProtocol = (Protocol)Class.forName("protocol." + (this.class_name == null ? this.name : this.class_name)).newInstance();
localProtocol.type = Integer.parseInt(this.type);
localProtocol.size_policy = (this.maxsize == null ? 0 : Integer.parseInt(this.maxsize));
localProtocol.prior_policy = (this.priority == null ? 0 : Integer.parseInt(this.priority));
if (this.map.put(this.name.toUpperCase(), localProtocol) != null)
System.err.println("Duplicate protocol name " + this.name);
if (this.map.put(this.type, localProtocol) != null)
System.err.println("Duplicate protocol type " + this.type);
protected override mars Client(OS os)
{
i = os.type();
switch (i)
{
case 3:
return new Class1();
case 4:
return new Class2();
case 5:
return new Class3();
case 6:
return new Class4(); ... ... // 还有很多
}
return null;
}
public static Protocol ParsePro(ref string s)
{
Protocol pro;
switch (s)
{
case "PublicChat":
pro = (Protocol)new PublicChat();
pro.type = 79;
pro.size_policy = 1024;
pro.prior_policy = 1;
return pro;
}
return null;
}
我重写了,但还是有很多重复工作,怎么样简化,用 Hashtable 保存键对值可以,属性呢??
Hashtable map = new Hashtable();
map.Add("PublicChat", new PublicChat());
Protocol pro;
if (map.Contains("PublicChat"))
{
pro = (Protocol)map["PublicChat"];
pro.type = 79;
pro.size_policy = 1024;
pro.prior_policy = 1;
return pro;
}
return null;