Please help me restructure this Java code to allow for sometime have 4 items in packagePriceList.
public static HTMLSelectOptionsElement listPremiumPackageTermsWithPrice(String[] packagePriceList, int cyberSourceBillingMode) {
HTMLSelectOptionsElement optionsElement = new HTMLSelectOptionsElement();
// Testing only. Allows for a shorter recurring term for QA testing.
if (cyberSourceBillingMode == DiceUtilConstants.CYBERSOURCE_BILLING_MODE_ICS_WEEKLY_OVERRIDE) {
optionsElement.addOption("1 Week", String.valueOf(UserPackage.PREMIUM_PACKAGE_TERM_7_DAYS));
}
optionsElement.addOption("1 Month - " + packagePriceList[0], String.valueOf(UserPackage.PREMIUM_PACKAGE_TERM_30_DAYS));
optionsElement.addOption("3 Months - " + packagePriceList[1], String.valueOf(UserPackage.PREMIUM_PACKAGE_TERM_90_DAYS));
optionsElement.addOption("6 Months - " + packagePriceList[2], String.valueOf(UserPackage.PREMIUM_PACKAGE_TERM_180_DAYS));
optionsElement.addOption("12 Months - " + packagePriceList[3], String.valueOf(UserPackage.PREMIUM_PACKAGE_TERM_365_DAYS));
return optionsElement;
}
I thought about just catching the IndexOutOfBoundsException but would that be a bit of a hack?
packagePriceList
of length 4, or sometimes less, sometimes more? \$\endgroup\$