我需要改進這個代碼,是非常重的,我沒有找到另一種方式來創建如果此代碼優化?
所有條件需要驗證,如果條件爲真並不重要,必須繼續尋找其他條件。
使用對不起,我的英語GOOGLETRANSLATE
if (skill.getId() == 233 && getActiveClassId() == 55 || getActiveClassId() == 46 || getActiveClassId() == 2 || getActiveClassId() == 3 || getActiveClassId() == 57 || getActiveClassId() == 117 || getActiveClassId() == 113 || getActiveClassId() == 88 || getActiveClassId() == 89 || getActiveClassId() == 118 || getActiveClassId() == 16 || getActiveClassId() == 30 || getActiveClassId() == 17 || getActiveClassId() == 43 || getActiveClassId() == 97 || getActiveClassId() == 105 || getActiveClassId() == 98 || getActiveClassId() == 112 || getActiveClassId() == 51 || getActiveClassId() == 52 || getActiveClassId() == 116 || getActiveClassId() == 116 || getActiveClassId() == 28 || getActiveClassId() == 41 || getActiveClassId() == 14 || getActiveClassId() == 104 || getActiveClassId() == 111 || getActiveClassId() == 96) {
removeSkillById(233); // Light Armor
} else {
// Nothing...
}
if (skill.getId() == 227 && getActiveClassId() == 36 || getActiveClassId() == 9 || getActiveClassId() == 37 || getActiveClassId() == 23 || getActiveClassId() == 24 || getActiveClassId() == 8 || getActiveClassId() == 48 || getActiveClassId() == 108 || getActiveClassId() == 92 || getActiveClassId() == 109 || getActiveClassId() == 101 || getActiveClassId() == 102 || getActiveClassId() == 93 || getActiveClassId() == 114 || getActiveClassId() == 16 || getActiveClassId() == 30 || getActiveClassId() == 17 || getActiveClassId() == 43 || getActiveClassId() == 97 || getActiveClassId() == 105 || getActiveClassId() == 98 || getActiveClassId() == 112 || getActiveClassId() == 51 || getActiveClassId() == 52 || getActiveClassId() == 115 || getActiveClassId() == 116 || getActiveClassId() == 28 || getActiveClassId() == 41 || getActiveClassId() == 14 || getActiveClassId() == 104 || getActiveClassId() == 111 || getActiveClassId() == 96) {
removeSkillById(227); // Light Armor
} else {
// Nothing...
}
if (skill.getId() == 236 && getActiveClassId() == 36 || getActiveClassId() == 9 || getActiveClassId() == 37 || getActiveClassId() == 23 || getActiveClassId() == 24 || getActiveClassId() == 8 || getActiveClassId() == 48 || getActiveClassId() == 108 || getActiveClassId() == 92 || getActiveClassId() == 109 || getActiveClassId() == 101 || getActiveClassId() == 102 || getActiveClassId() == 93 || getActiveClassId() == 114 || getActiveClassId() == 55 || getActiveClassId() == 46 || getActiveClassId() == 2 || getActiveClassId() == 3 || getActiveClassId() == 57 || getActiveClassId() == 117 || getActiveClassId() == 113 || getActiveClassId() == 88 || getActiveClassId() == 89 || getActiveClassId() == 118 || getActiveClassId() == 51 || getActiveClassId() == 52 || getActiveClassId() == 115 || getActiveClassId() == 116 || getActiveClassId() == 28 || getActiveClassId() == 41 || getActiveClassId() == 14 || getActiveClassId() == 104 || getActiveClassId() == 111 || getActiveClassId() == 96) {
removeSkillById(236); // Light Armor
} else {
// Nothing...
}
if (skill.getId() == 252 && getActiveClassId() == 36 || getActiveClassId() == 9 || getActiveClassId() == 37 || getActiveClassId() == 23 || getActiveClassId() == 24 || getActiveClassId() == 8 || getActiveClassId() == 48 || getActiveClassId() == 108 || getActiveClassId() == 92 || getActiveClassId() == 109 || getActiveClassId() == 101 || getActiveClassId() == 102 || getActiveClassId() == 93 || getActiveClassId() == 114 || getActiveClassId() == 55 || getActiveClassId() == 46 || getActiveClassId() == 2 || getActiveClassId() == 3 || getActiveClassId() == 57 || getActiveClassId() == 117 || getActiveClassId() == 113 || getActiveClassId() == 88 || getActiveClassId() == 89 || getActiveClassId() == 118 || getActiveClassId() == 16 || getActiveClassId() == 30 || getActiveClassId() == 17 || getActiveClassId() == 43 || getActiveClassId() == 97 || getActiveClassId() == 105 || getActiveClassId() == 98 || getActiveClassId() == 112 || getActiveClassId() == 28 || getActiveClassId() == 41 || getActiveClassId() == 14 || getActiveClassId() == 104 || getActiveClassId() == 111 || getActiveClassId() == 96) {
removeSkillById(252); // Light Armor
} else {
// Nothing...
}
if (skill.getId() == 258 && getActiveClassId() == 36 || getActiveClassId() == 9 || getActiveClassId() == 37 || getActiveClassId() == 23 || getActiveClassId() == 24 || getActiveClassId() == 8 || getActiveClassId() == 48 || getActiveClassId() == 108 || getActiveClassId() == 92 || getActiveClassId() == 109 || getActiveClassId() == 101 || getActiveClassId() == 102 || getActiveClassId() == 93 || getActiveClassId() == 114 || getActiveClassId() == 55 || getActiveClassId() == 46 || getActiveClassId() == 2 || getActiveClassId() == 3 || getActiveClassId() == 57 || getActiveClassId() == 117 || getActiveClassId() == 113 || getActiveClassId() == 88 || getActiveClassId() == 89 || getActiveClassId() == 118 || getActiveClassId() == 16 || getActiveClassId() == 30 || getActiveClassId() == 17 || getActiveClassId() == 43 || getActiveClassId() == 97 || getActiveClassId() == 105 || getActiveClassId() == 98 || getActiveClassId() == 112 || getActiveClassId() == 51 || getActiveClassId() == 52 || getActiveClassId() == 115 || getActiveClassId() == 116) {
removeSkillById(258); // Light Armor
} else {
// Nothing...
}
if (skill.getId() == 231 && getActiveClassId() == 6 || getActiveClassId() == 5 || getActiveClassId() == 33 || getActiveClassId() == 20 || getActiveClassId() == 91 || getActiveClassId() == 90 || getActiveClassId() == 106 || getActiveClassId() == 99 || getActiveClassId() == 51 || getActiveClassId() == 52 || getActiveClassId() == 115 || getActiveClassId() == 116 || getActiveClassId() == 17 || getActiveClassId() == 98) {
removeSkillById(231); // Heavy Armor
} else {
// Nothing...
}
if (skill.getId() == 232 && getActiveClassId() == 55 || getActiveClassId() == 46 || getActiveClassId() == 2 || getActiveClassId() == 3 || getActiveClassId() == 57 || getActiveClassId() == 117 || getActiveClassId() == 113 || getActiveClassId() == 88 || getActiveClassId() == 89 || getActiveClassId() == 118 || getActiveClassId() == 51 || getActiveClassId() == 52 || getActiveClassId() == 115 || getActiveClassId() == 116 || getActiveClassId() == 17 || getActiveClassId() == 98) {
removeSkillById(232); // Heavy Armor
} else {
// Nothing...
}
if (skill.getId() == 253 && getActiveClassId() == 55 || getActiveClassId() == 46 || getActiveClassId() == 2 || getActiveClassId() == 3 || getActiveClassId() == 57 || getActiveClassId() == 117 || getActiveClassId() == 113 || getActiveClassId() == 88 || getActiveClassId() == 89 || getActiveClassId() == 118 || getActiveClassId() == 6 || getActiveClassId() == 5 || getActiveClassId() == 33 || getActiveClassId() == 20 || getActiveClassId() == 91 || getActiveClassId() == 90 || getActiveClassId() == 106 || getActiveClassId() == 99 || getActiveClassId() == 17 || getActiveClassId() == 98) {
removeSkillById(253); // Heavy Armor
} else {
// Nothing...
}
if (skill.getId() == 259 && getActiveClassId() == 55 || getActiveClassId() == 46 || getActiveClassId() == 2 || getActiveClassId() == 3 || getActiveClassId() == 57 || getActiveClassId() == 117 || getActiveClassId() == 113 || getActiveClassId() == 88 || getActiveClassId() == 89 || getActiveClassId() == 118 || getActiveClassId() == 6 || getActiveClassId() == 5 || getActiveClassId() == 33 || getActiveClassId() == 20 || getActiveClassId() == 91 || getActiveClassId() == 90 || getActiveClassId() == 106 || getActiveClassId() == 99 || getActiveClassId() == 51 || getActiveClassId() == 52 || getActiveClassId() == 115 || getActiveClassId() == 116) {
removeSkillById(259); // Heavy Armor
} else {
// Nothing...
}
if (skill.getId() == 234 && getActiveClassId() == 16 || getActiveClassId() == 17 || getActiveClassId() == 30 || getActiveClassId() == 43 || getActiveClassId() == 97 || getActiveClassId() == 98 || getActiveClassId() == 105 || getActiveClassId() == 112 || getActiveClassId() == 51 || getActiveClassId() == 52 || getActiveClassId() == 115 || getActiveClassId() == 116) {
removeSkillById(234); // Robe Mastery
} else {
// Nothing...
}
if (skill.getId() == 235 && getActiveClassId() == 28 || getActiveClassId() == 13 || getActiveClassId() == 41 || getActiveClassId() == 12 || getActiveClassId() == 40 || getActiveClassId() == 27 || getActiveClassId() == 14 || getActiveClassId() == 104 || getActiveClassId() == 95 || getActiveClassId() == 111 || getActiveClassId() == 94 || getActiveClassId() == 110 || getActiveClassId() == 103 || getActiveClassId() == 96 || getActiveClassId() == 51 || getActiveClassId() == 52 || getActiveClassId() == 115 || getActiveClassId() == 116) {
removeSkillById(235); // Robe Mastery
} else {
// Nothing...
}
if (skill.getId() == 251 && getActiveClassId() == 28 || getActiveClassId() == 13 || getActiveClassId() == 41 || getActiveClassId() == 12 || getActiveClassId() == 40 || getActiveClassId() == 27 || getActiveClassId() == 14 || getActiveClassId() == 104 || getActiveClassId() == 95 || getActiveClassId() == 111 || getActiveClassId() == 94 || getActiveClassId() == 110 || getActiveClassId() == 103 || getActiveClassId() == 96 || getActiveClassId() == 16 || getActiveClassId() == 17 || getActiveClassId() == 30 || getActiveClassId() == 43 || getActiveClassId() == 97 || getActiveClassId() == 98 || getActiveClassId() == 105 || getActiveClassId() == 112) {
removeSkillById(251); // Robe Mastery
} else {
// Nothing...
}
任何幫助我嗎?謝謝!!
您可以刪除'else {}'語句 – 2013-02-16 04:18:10
您可能會在大'if'之前計算'skill.getId()'和'getActiveClassId()'等,以獲得一些性能(和清晰度)外。考慮在'skill.getId()'上使用'switch'而不是嵌套'if',並且只處理其餘的條件。或者按OO方式做:使每個對象都處理它的邏輯部分,不要在外面處理它(可能意味着對類層次結構的完全重新設計......)。 – vonbrand 2013-02-16 04:27:52
你應該仔細研究[enums](http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html)而不是所有這些神奇的數字。 – Kevin 2013-02-16 04:32:34