印度人的代码
蝈蝈俊 2001-02-16 12:22:00 以前在论坛上听说印度人的代码拖塌冗长,这两天在看
美国印度人的代码,发现果真不错,看得我都快找不到北了 : )
这是一段处理文本的Java代码,先请看美国印度人的代码:
if(osname.startsWith("Windows"))
{
if(runcmd.stdout == null)
return null;
StringTokenizer stringtokenizer = new StringTokenizer(runcmd.stdout.toString());
Hashtable hashtable = null;
Object obj = null;
String s2 = null;
String s5 = null;
while(stringtokenizer.hasMoreTokens())
{
String s6 = stringtokenizer.nextToken();
if(s6.equals("Type"))
break;
}
while(stringtokenizer.hasMoreTokens())
{
String s1 = stringtokenizer.nextToken();
if(stringtokenizer.hasMoreTokens())
{
s2 = stringtokenizer.nextToken();
if(stringtokenizer.hasMoreTokens())
s5 = stringtokenizer.nextToken();
}
if(s5 == null || !s5.equals("invalid"))
{
if(hashtable == null)
hashtable = new Hashtable();
if(s1 != null && s2 != null && !s2.equals("00:00:00:00:00:00"))
hashtable.put(s1, s2);
}
}
return hashtable;
}
这是我对整个程序结构调整后的部分代码:
if(strOSName.startsWith("Windows"))
{
StringTokenizer stringtokenizer = new StringTokenizer(strCommandResult);
String[] strValue = new String[3];
while(stringtokenizer.hasMoreTokens() && (! stringtokenizer.nextToken().equals("Type")))
{//发现"Type"关键字后退出}
while(stringtokenizer.hasMoreTokens())
{
for(int i = 0; i < 3; i++)
if(stringtokenizer.hasMoreTokens())
strValue[i] = stringtokenizer.nextToken();
if(strValue[2] == null || !strValue[2].equals("invalid"))
if(strValue[0] != null && strValue[1] != null && !strValue[1].equals("00:00:00:00:00:00"))
hashtable.put(strValue[0], strValue[1]);
}
}
大家看了之后感觉如何?
转贴之http://seforum.yeah.net 论坛的邮件列表