Is there a Java equivalent for PowerScript "CHOOSE CASE"? -


i find powerscript's choose case statement useful, make code more lot of ifs , else ifs.

here example of how works, above link:

choose case weight    case < 16         postage=weight*0.30         method="usps"    case 16 48         postage=4.50         method="ups"    case else         postage=25.00         method="fedex" end choose 

a case 5 11 same case 5, 6, 7, 8, 9, 10, 11

note choose case not equivalent java's switch

if objective cleaning decision point, encapsulate code decides case applies separately code uses decision, in:

enum weightclass { low, medium, high };  public weightclass determineweightclass(int weight) {     return (weight < 16)          ? weightclass.low          : (weight <= 48              ? weightclass.medium              : weightclass.high); } 

and @ decision point:

switch(determineweightclass(weight)) {     case low:         ...         break;     case medium:         ...         break;     case high:         ...         break; } 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -