001
002package com.commercetools.ml.models.image_search;
003
004import java.util.*;
005import java.util.function.Function;
006
007import io.vrap.rmf.base.client.Builder;
008import io.vrap.rmf.base.client.utils.Generated;
009
010/**
011 * ResultItemBuilder
012 * <hr>
013 * Example to create an instance using the builder pattern
014 * <div class=code-example>
015 * <pre><code class='java'>
016 *     ResultItem resultItem = ResultItem.builder()
017 *             .imageUrl("{imageUrl}")
018 *             .plusProductVariants(productVariantsBuilder -> productVariantsBuilder)
019 *             .build()
020 * </code></pre>
021 * </div>
022 */
023@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen")
024public class ResultItemBuilder implements Builder<ResultItem> {
025
026    private String imageUrl;
027
028    private java.util.List<com.commercetools.ml.models.common.ProductVariant> productVariants;
029
030    /**
031     *  <p>The URL of the image.</p>
032     * @param imageUrl value to be set
033     * @return Builder
034     */
035
036    public ResultItemBuilder imageUrl(final String imageUrl) {
037        this.imageUrl = imageUrl;
038        return this;
039    }
040
041    /**
042     *  <p>An array of product variants containing the image URL.</p>
043     * @param productVariants value to be set
044     * @return Builder
045     */
046
047    public ResultItemBuilder productVariants(
048            final com.commercetools.ml.models.common.ProductVariant... productVariants) {
049        this.productVariants = new ArrayList<>(Arrays.asList(productVariants));
050        return this;
051    }
052
053    /**
054     *  <p>An array of product variants containing the image URL.</p>
055     * @param productVariants value to be set
056     * @return Builder
057     */
058
059    public ResultItemBuilder productVariants(
060            final java.util.List<com.commercetools.ml.models.common.ProductVariant> productVariants) {
061        this.productVariants = productVariants;
062        return this;
063    }
064
065    /**
066     *  <p>An array of product variants containing the image URL.</p>
067     * @param productVariants value to be set
068     * @return Builder
069     */
070
071    public ResultItemBuilder plusProductVariants(
072            final com.commercetools.ml.models.common.ProductVariant... productVariants) {
073        if (this.productVariants == null) {
074            this.productVariants = new ArrayList<>();
075        }
076        this.productVariants.addAll(Arrays.asList(productVariants));
077        return this;
078    }
079
080    /**
081     *  <p>An array of product variants containing the image URL.</p>
082     * @param builder function to build the productVariants value
083     * @return Builder
084     */
085
086    public ResultItemBuilder plusProductVariants(
087            Function<com.commercetools.ml.models.common.ProductVariantBuilder, com.commercetools.ml.models.common.ProductVariantBuilder> builder) {
088        if (this.productVariants == null) {
089            this.productVariants = new ArrayList<>();
090        }
091        this.productVariants.add(builder.apply(com.commercetools.ml.models.common.ProductVariantBuilder.of()).build());
092        return this;
093    }
094
095    /**
096     *  <p>An array of product variants containing the image URL.</p>
097     * @param builder function to build the productVariants value
098     * @return Builder
099     */
100
101    public ResultItemBuilder withProductVariants(
102            Function<com.commercetools.ml.models.common.ProductVariantBuilder, com.commercetools.ml.models.common.ProductVariantBuilder> builder) {
103        this.productVariants = new ArrayList<>();
104        this.productVariants.add(builder.apply(com.commercetools.ml.models.common.ProductVariantBuilder.of()).build());
105        return this;
106    }
107
108    /**
109     *  <p>An array of product variants containing the image URL.</p>
110     * @param builder function to build the productVariants value
111     * @return Builder
112     */
113
114    public ResultItemBuilder addProductVariants(
115            Function<com.commercetools.ml.models.common.ProductVariantBuilder, com.commercetools.ml.models.common.ProductVariant> builder) {
116        return plusProductVariants(builder.apply(com.commercetools.ml.models.common.ProductVariantBuilder.of()));
117    }
118
119    /**
120     *  <p>An array of product variants containing the image URL.</p>
121     * @param builder function to build the productVariants value
122     * @return Builder
123     */
124
125    public ResultItemBuilder setProductVariants(
126            Function<com.commercetools.ml.models.common.ProductVariantBuilder, com.commercetools.ml.models.common.ProductVariant> builder) {
127        return productVariants(builder.apply(com.commercetools.ml.models.common.ProductVariantBuilder.of()));
128    }
129
130    /**
131     *  <p>The URL of the image.</p>
132     * @return imageUrl
133     */
134
135    public String getImageUrl() {
136        return this.imageUrl;
137    }
138
139    /**
140     *  <p>An array of product variants containing the image URL.</p>
141     * @return productVariants
142     */
143
144    public java.util.List<com.commercetools.ml.models.common.ProductVariant> getProductVariants() {
145        return this.productVariants;
146    }
147
148    /**
149     * builds ResultItem with checking for non-null required values
150     * @return ResultItem
151     */
152    public ResultItem build() {
153        Objects.requireNonNull(imageUrl, ResultItem.class + ": imageUrl is missing");
154        Objects.requireNonNull(productVariants, ResultItem.class + ": productVariants is missing");
155        return new ResultItemImpl(imageUrl, productVariants);
156    }
157
158    /**
159     * builds ResultItem without checking for non-null required values
160     * @return ResultItem
161     */
162    public ResultItem buildUnchecked() {
163        return new ResultItemImpl(imageUrl, productVariants);
164    }
165
166    /**
167     * factory method for an instance of ResultItemBuilder
168     * @return builder
169     */
170    public static ResultItemBuilder of() {
171        return new ResultItemBuilder();
172    }
173
174    /**
175     * create builder for ResultItem instance
176     * @param template instance with prefilled values for the builder
177     * @return builder
178     */
179    public static ResultItemBuilder of(final ResultItem template) {
180        ResultItemBuilder builder = new ResultItemBuilder();
181        builder.imageUrl = template.getImageUrl();
182        builder.productVariants = template.getProductVariants();
183        return builder;
184    }
185
186}