001 002package com.commercetools.api.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 * PriceTierBuilder 012 * <hr> 013 * Example to create an instance using the builder pattern 014 * <div class=code-example> 015 * <pre><code class='java'> 016 * PriceTier priceTier = PriceTier.builder() 017 * .minimumQuantity(0.3) 018 * .value(valueBuilder -> valueBuilder) 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 PriceTierBuilder implements Builder<PriceTier> { 025 026 private Long minimumQuantity; 027 028 private com.commercetools.api.models.common.TypedMoney value; 029 030 /** 031 * <p>Minimum quantity this Price tier is valid for.</p> 032 * <p>The minimum quantity is always greater than or equal to 2. The base Price is interpreted as valid for a minimum quantity equal to 1. A Price or StandalonePrice cannot contain more than one tier with the same <code>minimumQuantity</code>.</p> 033 * @param minimumQuantity value to be set 034 * @return Builder 035 */ 036 037 public PriceTierBuilder minimumQuantity(final Long minimumQuantity) { 038 this.minimumQuantity = minimumQuantity; 039 return this; 040 } 041 042 /** 043 * <p>Money value that applies when the <code>minimumQuantity</code> is greater than or equal to the LineItem <code>quantity</code>.</p> 044 * <p>The <code>currencyCode</code> of a Price tier is always the same as the <code>currencyCode</code> in the <code>value</code> of the related Price.</p> 045 * @param value value to be set 046 * @return Builder 047 */ 048 049 public PriceTierBuilder value(final com.commercetools.api.models.common.TypedMoney value) { 050 this.value = value; 051 return this; 052 } 053 054 /** 055 * <p>Money value that applies when the <code>minimumQuantity</code> is greater than or equal to the LineItem <code>quantity</code>.</p> 056 * <p>The <code>currencyCode</code> of a Price tier is always the same as the <code>currencyCode</code> in the <code>value</code> of the related Price.</p> 057 * @param builder function to build the value value 058 * @return Builder 059 */ 060 061 public PriceTierBuilder value( 062 Function<com.commercetools.api.models.common.TypedMoneyBuilder, Builder<? extends com.commercetools.api.models.common.TypedMoney>> builder) { 063 this.value = builder.apply(com.commercetools.api.models.common.TypedMoneyBuilder.of()).build(); 064 return this; 065 } 066 067 /** 068 * <p>Minimum quantity this Price tier is valid for.</p> 069 * <p>The minimum quantity is always greater than or equal to 2. The base Price is interpreted as valid for a minimum quantity equal to 1. A Price or StandalonePrice cannot contain more than one tier with the same <code>minimumQuantity</code>.</p> 070 * @return minimumQuantity 071 */ 072 073 public Long getMinimumQuantity() { 074 return this.minimumQuantity; 075 } 076 077 /** 078 * <p>Money value that applies when the <code>minimumQuantity</code> is greater than or equal to the LineItem <code>quantity</code>.</p> 079 * <p>The <code>currencyCode</code> of a Price tier is always the same as the <code>currencyCode</code> in the <code>value</code> of the related Price.</p> 080 * @return value 081 */ 082 083 public com.commercetools.api.models.common.TypedMoney getValue() { 084 return this.value; 085 } 086 087 /** 088 * builds PriceTier with checking for non-null required values 089 * @return PriceTier 090 */ 091 public PriceTier build() { 092 Objects.requireNonNull(minimumQuantity, PriceTier.class + ": minimumQuantity is missing"); 093 Objects.requireNonNull(value, PriceTier.class + ": value is missing"); 094 return new PriceTierImpl(minimumQuantity, value); 095 } 096 097 /** 098 * builds PriceTier without checking for non-null required values 099 * @return PriceTier 100 */ 101 public PriceTier buildUnchecked() { 102 return new PriceTierImpl(minimumQuantity, value); 103 } 104 105 /** 106 * factory method for an instance of PriceTierBuilder 107 * @return builder 108 */ 109 public static PriceTierBuilder of() { 110 return new PriceTierBuilder(); 111 } 112 113 /** 114 * create builder for PriceTier instance 115 * @param template instance with prefilled values for the builder 116 * @return builder 117 */ 118 public static PriceTierBuilder of(final PriceTier template) { 119 PriceTierBuilder builder = new PriceTierBuilder(); 120 builder.minimumQuantity = template.getMinimumQuantity(); 121 builder.value = template.getValue(); 122 return builder; 123 } 124 125}