コード例 #1
0
 /**
  * Considers variant1 greater then other if, for the same variant category level, the value of the
  * {@link VariantValueCategoryModel} belonging to variant1 has a bigger sequence then the {@link
  * VariantValueCategoryModel} belonging to variant2.
  */
 @Override
 public int compare(
     final GenericVariantProductModel variant1, final GenericVariantProductModel variant2) {
   if ((variant1 != null) && (variant2 != null)) {
     // get sorted list of VariantValueCategories
     final List<VariantValueCategoryModel> variantValueCategories1 =
         getVariantValuesCategories(variant1);
     final List<VariantValueCategoryModel> variantValueCategories2 =
         getVariantValuesCategories(variant2);
     if (variantValueCategories1.size() == variantValueCategories2.size()) {
       int compare = 0;
       for (int i = 0; i < variantValueCategories1.size(); i++) {
         final VariantValueCategoryModel valueCategory1 = variantValueCategories1.get(i);
         final VariantValueCategoryModel valueCategory2 = variantValueCategories2.get(i);
         compare = Integer.compare(valueCategory1.getSequence(), valueCategory2.getSequence());
         if (compare != 0) {
           break;
         }
       }
       return compare;
     } else {
       throw new IllegalArgumentException(
           "Variants should have the same number of category levels to be compared!");
     }
   } else {
     throw new IllegalArgumentException("Cannot compare null variants!");
   }
 }
  @Override
  public void populate(
      final VariantValueCategoryModel variantValueCategory,
      final VariantMatrixElementData variantMatrixElementData)
      throws ConversionException {
    final VariantCategoryData parent = new VariantCategoryData();

    final VariantCategoryModel variantCategoryModel =
        (VariantCategoryModel) variantValueCategory.getSupercategories().get(0);
    parent.setName(variantCategoryModel.getName());
    parent.setHasImage(variantCategoryModel.getHasImage());

    final VariantValueCategoryData data = new VariantValueCategoryData();
    data.setName(variantValueCategory.getName());
    data.setSequence(variantValueCategory.getSequence());

    variantMatrixElementData.setVariantValueCategory(data);
    variantMatrixElementData.setParentVariantCategory(parent);

    final VariantOptionData variantOptionData = new VariantOptionData();
    final VariantOptionQualifierData variantOptionQualifierData = new VariantOptionQualifierData();
    variantOptionQualifierData.setImage(new ImageData());
    variantOptionData.setVariantOptionQualifiers(
        Arrays.asList(new VariantOptionQualifierData[] {variantOptionQualifierData}));

    variantMatrixElementData.setVariantOption(variantOptionData);
  }