johanmoritz / freecol

FreeCol: FreeCol is a turn-based strategy game based on the old game Colonization, and similar to Civilization. The objective of the game is to create an independent nation.
GNU General Public License v2.0
0 stars 1 forks source link

Refactor ModelMessage::getDefaultDisplay to reduce CCN #47

Open rbratfors opened 4 years ago

rbratfors commented 4 years ago

This function has a switch statement with a lot of "fall through" cases, i.e. cases without breaks. There's as many as 8 of these that fall through to the default which is a very interesting design choice.

The code complexity of the function can be reduced some by just deleting all of those cases and letting them default to default instead.

rbratfors commented 4 years ago
case DEFAULT:
            CodeCoverage.run("getDefaultDisplay");
            doIf = true;
            break;
case WARNING:
            CodeCoverage.run("getDefaultDisplay");
            doIf = true;
            break;
case WAREHOUSE_CAPACITY:
            CodeCoverage.run("getDefaultDisplay");
            doIf = true;
            break;
case FOREIGN_DIPLOMACY:
            CodeCoverage.run("getDefaultDisplay");
            doIf = true;
            break;
case MARKET_PRICES:
            CodeCoverage.run("getDefaultDisplay");
            doIf = true;
            break;
case MISSING_GOODS:
            CodeCoverage.run("getDefaultDisplay");
            doIf = true;
            break;
case TUTORIAL:
            CodeCoverage.run("getDefaultDisplay");
            doIf = true;
            break;
case GIFT_GOODS:
            CodeCoverage.run("getDefaultDisplay");
            doIf = true;
            break;
default:
            CodeCoverage.run("getDefaultDisplay");
            doIf = true;
            break;

Here's the code in question. Every one of these cases can be removed since they do the same thing as default.