Refactoring useless Method away
Real-life challenge, convert a bunch of ifs to a switch statement
Start file
if (isTyp(YBD.Typ_GEBAEUDE, currentTyp)) { immobilienItem.setGebaeudeNr(currentItem.getGebaeudeNr()); } if (isTyp(YBD.Typ_OBJEKT, currentTyp)) { immobilienItem.setObjektNr(currentItem.getObjektNr()); } if (isTyp(YBD.Typ_ETAGE, currentTyp)) { immobilienItem.setEtageNr(currentItem.getEtageNr()); } if (isTyp(YBD.Typ_IMMOBILIE, currentTyp)) { immobilienItem.setImmobilieNr(currentItem.getImmobilieNr()); } if (isTyp(YBD.Typ_HAUS, currentTyp)) { immobilienItem.setHausNr(currentItem.getHausNr()); }
End file
switch (currentTyp) { case YBD.Typ_GEBAEUDE: immobilienItem.setGebaeudeNr(currentItem.getGebaeudeNr()); break; case YBD.Typ_OBJEKT: immobilienItem.setObjektNr(currentItem.getObjektNr()); break; case YBD.Typ_ETAGE: immobilienItem.setEtageNr(currentItem.getEtageNr()); break; case YBD.Typ_IMMOBILIE: immobilienItem.setImmobilieNr(currentItem.getImmobilieNr()); break; case YBD.Typ_HAUS: immobilienItem.setHausNr(currentItem.getHausNr()); break; }
View Diff
1,14c1,16 < if (isTyp(YBD.Typ_GEBAEUDE, currentTyp)) { < immobilienItem.setGebaeudeNr(currentItem.getGebaeudeNr()); < } < if (isTyp(YBD.Typ_OBJEKT, currentTyp)) { < immobilienItem.setObjektNr(currentItem.getObjektNr()); < } < if (isTyp(YBD.Typ_ETAGE, currentTyp)) { < immobilienItem.setEtageNr(currentItem.getEtageNr()); < } < if (isTyp(YBD.Typ_IMMOBILIE, currentTyp)) { < immobilienItem.setImmobilieNr(currentItem.getImmobilieNr()); < } < if (isTyp(YBD.Typ_HAUS, currentTyp)) { < immobilienItem.setHausNr(currentItem.getHausNr()); --- > switch (currentTyp) { > case YBD.Typ_GEBAEUDE: > immobilienItem.setGebaeudeNr(currentItem.getGebaeudeNr()); > break; > case YBD.Typ_OBJEKT: > immobilienItem.setObjektNr(currentItem.getObjektNr()); > break; > case YBD.Typ_ETAGE: > immobilienItem.setEtageNr(currentItem.getEtageNr()); > break; > case YBD.Typ_IMMOBILIE: > immobilienItem.setImmobilieNr(currentItem.getImmobilieNr()); > break; > case YBD.Typ_HAUS: > immobilienItem.setHausNr(currentItem.getHausNr()); > break;
Solutions by @xieyh11:
Unlock 1 remaining solutions by signing in and submitting your own entry