// product feature and add it to the id code and product feature applications
// of the next variant. just a matter of whether we're starting with an
// existing list of features and id code or from scratch.
if (combinations.size()==0) {
for (Iterator cFi = currentFeatures.iterator(); cFi.hasNext(); ) {
GenericEntity currentFeature = (GenericEntity) cFi.next();
if (currentFeature.getString("productFeatureApplTypeId").equals("SELECTABLE_FEATURE")) {
Map newCombination = new HashMap();
List newFeatures = new LinkedList();
List newFeatureIds = new LinkedList();
if (currentFeature.getString("idCode") != null) {
newCombination.put("defaultVariantProductId", productId + currentFeature.getString("idCode"));
} else {
newCombination.put("defaultVariantProductId", productId);
}
newFeatures.add(currentFeature);
newFeatureIds.add(currentFeature.getString("productFeatureId"));
newCombination.put("curProductFeatureAndAppls", newFeatures);
newCombination.put("curProductFeatureIds", newFeatureIds);
newCombinations.add(newCombination);
}
}
} else {
for (Iterator comboIt = combinations.iterator(); comboIt.hasNext(); ) {
Map combination = (Map) comboIt.next();
for (Iterator cFi = currentFeatures.iterator(); cFi.hasNext(); ) {
GenericEntity currentFeature = (GenericEntity) cFi.next();
if (currentFeature.getString("productFeatureApplTypeId").equals("SELECTABLE_FEATURE")) {
Map newCombination = new HashMap();
// .clone() is important, or you'll keep adding to the same List for all the variants
// have to cast twice: once from get() and once from clone()
List newFeatures = ((List) ((LinkedList) combination.get("curProductFeatureAndAppls")).clone());
List newFeatureIds = ((List) ((LinkedList) combination.get("curProductFeatureIds")).clone());
if (currentFeature.getString("idCode") != null) {
newCombination.put("defaultVariantProductId", combination.get("defaultVariantProductId") + currentFeature.getString("idCode"));
} else {
newCombination.put("defaultVariantProductId", combination.get("defaultVariantProductId"));
}
newFeatures.add(currentFeature);
newFeatureIds.add(currentFeature.getString("productFeatureId"));
newCombination.put("curProductFeatureAndAppls", newFeatures);
newCombination.put("curProductFeatureIds", newFeatureIds);
newCombinations.add(newCombination);
}
}