-3

このコードを改善する必要があり、非常に重く、別の作成方法が見つかりませんでした

すべての条件を検証する必要がありますが、条件が真の場合は重要ではなく、他の条件を探し続ける必要があります。

私の英語の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...
}

何か助けてくれませんか?ありがとう!!

4

2 に答える 2

2

これを最適化するためにいくつかのことを行うことができます。

  1. 次のコード ブロックを削除します。これらは不要です。

    else 
    {
        // Nothing..
    }
    
  2. 次に、関数からの戻り値をローカル変数に保存して、同じ関数を何度も呼び出すオーバーヘッドを節約します。

    int activeClassId = getActiveClassId(), skillId = skill.getId();
    
  3. a を使用しListて可能な値を格納し、 を使用しますList.contains()。たとえば、次のように変換できます。

    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)
    

    これに:

    List<Integer> validClassIds = Arrays.asList( 36, 9, 37, 23, 24, 8, 48, 108, 92, 109, 101, 102, 93, 114, 55, 46, 2, 3, 57, 117, 113, 88, 89, 118, 16, 30, 17, 43, 97, 105, 98, 112, 28, 41, 14, 104, 111, 96);
    
    if( skillId == 252 && validClassIds.contains( activeClassId))
    

O(n)で検索したくない場合List.contains()は、List の代わりに HashSet を使用できます。詳細はこちら

于 2013-02-16T04:29:55.233 に答える
1

I have advice from algorithm perspective.

Use Huffman coding to minimize the compare times by adjust if-else conditions sequence.if you have statistic of possibility of data.

于 2013-02-16T04:39:54.263 に答える