001
002package com.commercetools.history.models.common;
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 * TaxRateBuilder
012 * <hr>
013 * Example to create an instance using the builder pattern
014 * <div class=code-example>
015 * <pre><code class='java'>
016 *     TaxRate taxRate = TaxRate.builder()
017 *             .id("{id}")
018 *             .name("{name}")
019 *             .amount(1)
020 *             .includedInPrice(true)
021 *             .country("{country}")
022 *             .state("{state}")
023 *             .plusSubRates(subRatesBuilder -> subRatesBuilder)
024 *             .build()
025 * </code></pre>
026 * </div>
027 */
028@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen")
029public class TaxRateBuilder implements Builder<TaxRate> {
030
031    private String id;
032
033    private String name;
034
035    private Integer amount;
036
037    private Boolean includedInPrice;
038
039    private String country;
040
041    private String state;
042
043    private java.util.List<com.commercetools.history.models.common.SubRate> subRates;
044
045    /**
046     *  <p>The ID is always set if the tax rate is part of a TaxCategory. The external tax rates in a Cart do not contain an <code>id</code>.</p>
047     * @param id value to be set
048     * @return Builder
049     */
050
051    public TaxRateBuilder id(final String id) {
052        this.id = id;
053        return this;
054    }
055
056    /**
057     * set the value to the name
058     * @param name value to be set
059     * @return Builder
060     */
061
062    public TaxRateBuilder name(final String name) {
063        this.name = name;
064        return this;
065    }
066
067    /**
068     *  <p>Percentage in the range of [0..1]. The sum of the amounts of all <code>subRates</code>, if there are any.</p>
069     * @param amount value to be set
070     * @return Builder
071     */
072
073    public TaxRateBuilder amount(final Integer amount) {
074        this.amount = amount;
075        return this;
076    }
077
078    /**
079     * set the value to the includedInPrice
080     * @param includedInPrice value to be set
081     * @return Builder
082     */
083
084    public TaxRateBuilder includedInPrice(final Boolean includedInPrice) {
085        this.includedInPrice = includedInPrice;
086        return this;
087    }
088
089    /**
090     *  <p>Two-digit country code as per ISO 3166-1 alpha-2.</p>
091     * @param country value to be set
092     * @return Builder
093     */
094
095    public TaxRateBuilder country(final String country) {
096        this.country = country;
097        return this;
098    }
099
100    /**
101     *  <p>The state in the country</p>
102     * @param state value to be set
103     * @return Builder
104     */
105
106    public TaxRateBuilder state(final String state) {
107        this.state = state;
108        return this;
109    }
110
111    /**
112     * set values to the subRates
113     * @param subRates value to be set
114     * @return Builder
115     */
116
117    public TaxRateBuilder subRates(final com.commercetools.history.models.common.SubRate... subRates) {
118        this.subRates = new ArrayList<>(Arrays.asList(subRates));
119        return this;
120    }
121
122    /**
123     * set value to the subRates
124     * @param subRates value to be set
125     * @return Builder
126     */
127
128    public TaxRateBuilder subRates(final java.util.List<com.commercetools.history.models.common.SubRate> subRates) {
129        this.subRates = subRates;
130        return this;
131    }
132
133    /**
134     * add values to the subRates
135     * @param subRates value to be set
136     * @return Builder
137     */
138
139    public TaxRateBuilder plusSubRates(final com.commercetools.history.models.common.SubRate... subRates) {
140        if (this.subRates == null) {
141            this.subRates = new ArrayList<>();
142        }
143        this.subRates.addAll(Arrays.asList(subRates));
144        return this;
145    }
146
147    /**
148     * add the value to the subRates using the builder function
149     * @param builder function to build the subRates value
150     * @return Builder
151     */
152
153    public TaxRateBuilder plusSubRates(
154            Function<com.commercetools.history.models.common.SubRateBuilder, com.commercetools.history.models.common.SubRateBuilder> builder) {
155        if (this.subRates == null) {
156            this.subRates = new ArrayList<>();
157        }
158        this.subRates.add(builder.apply(com.commercetools.history.models.common.SubRateBuilder.of()).build());
159        return this;
160    }
161
162    /**
163     * set the value to the subRates using the builder function
164     * @param builder function to build the subRates value
165     * @return Builder
166     */
167
168    public TaxRateBuilder withSubRates(
169            Function<com.commercetools.history.models.common.SubRateBuilder, com.commercetools.history.models.common.SubRateBuilder> builder) {
170        this.subRates = new ArrayList<>();
171        this.subRates.add(builder.apply(com.commercetools.history.models.common.SubRateBuilder.of()).build());
172        return this;
173    }
174
175    /**
176     * add the value to the subRates using the builder function
177     * @param builder function to build the subRates value
178     * @return Builder
179     */
180
181    public TaxRateBuilder addSubRates(
182            Function<com.commercetools.history.models.common.SubRateBuilder, com.commercetools.history.models.common.SubRate> builder) {
183        return plusSubRates(builder.apply(com.commercetools.history.models.common.SubRateBuilder.of()));
184    }
185
186    /**
187     * set the value to the subRates using the builder function
188     * @param builder function to build the subRates value
189     * @return Builder
190     */
191
192    public TaxRateBuilder setSubRates(
193            Function<com.commercetools.history.models.common.SubRateBuilder, com.commercetools.history.models.common.SubRate> builder) {
194        return subRates(builder.apply(com.commercetools.history.models.common.SubRateBuilder.of()));
195    }
196
197    /**
198     *  <p>The ID is always set if the tax rate is part of a TaxCategory. The external tax rates in a Cart do not contain an <code>id</code>.</p>
199     * @return id
200     */
201
202    public String getId() {
203        return this.id;
204    }
205
206    /**
207     * value of name}
208     * @return name
209     */
210
211    public String getName() {
212        return this.name;
213    }
214
215    /**
216     *  <p>Percentage in the range of [0..1]. The sum of the amounts of all <code>subRates</code>, if there are any.</p>
217     * @return amount
218     */
219
220    public Integer getAmount() {
221        return this.amount;
222    }
223
224    /**
225     * value of includedInPrice}
226     * @return includedInPrice
227     */
228
229    public Boolean getIncludedInPrice() {
230        return this.includedInPrice;
231    }
232
233    /**
234     *  <p>Two-digit country code as per ISO 3166-1 alpha-2.</p>
235     * @return country
236     */
237
238    public String getCountry() {
239        return this.country;
240    }
241
242    /**
243     *  <p>The state in the country</p>
244     * @return state
245     */
246
247    public String getState() {
248        return this.state;
249    }
250
251    /**
252     * value of subRates}
253     * @return subRates
254     */
255
256    public java.util.List<com.commercetools.history.models.common.SubRate> getSubRates() {
257        return this.subRates;
258    }
259
260    /**
261     * builds TaxRate with checking for non-null required values
262     * @return TaxRate
263     */
264    public TaxRate build() {
265        Objects.requireNonNull(id, TaxRate.class + ": id is missing");
266        Objects.requireNonNull(name, TaxRate.class + ": name is missing");
267        Objects.requireNonNull(amount, TaxRate.class + ": amount is missing");
268        Objects.requireNonNull(includedInPrice, TaxRate.class + ": includedInPrice is missing");
269        Objects.requireNonNull(country, TaxRate.class + ": country is missing");
270        Objects.requireNonNull(state, TaxRate.class + ": state is missing");
271        Objects.requireNonNull(subRates, TaxRate.class + ": subRates is missing");
272        return new TaxRateImpl(id, name, amount, includedInPrice, country, state, subRates);
273    }
274
275    /**
276     * builds TaxRate without checking for non-null required values
277     * @return TaxRate
278     */
279    public TaxRate buildUnchecked() {
280        return new TaxRateImpl(id, name, amount, includedInPrice, country, state, subRates);
281    }
282
283    /**
284     * factory method for an instance of TaxRateBuilder
285     * @return builder
286     */
287    public static TaxRateBuilder of() {
288        return new TaxRateBuilder();
289    }
290
291    /**
292     * create builder for TaxRate instance
293     * @param template instance with prefilled values for the builder
294     * @return builder
295     */
296    public static TaxRateBuilder of(final TaxRate template) {
297        TaxRateBuilder builder = new TaxRateBuilder();
298        builder.id = template.getId();
299        builder.name = template.getName();
300        builder.amount = template.getAmount();
301        builder.includedInPrice = template.getIncludedInPrice();
302        builder.country = template.getCountry();
303        builder.state = template.getState();
304        builder.subRates = template.getSubRates();
305        return builder;
306    }
307
308}