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 * ShippingRateBuilder 012 * <hr> 013 * Example to create an instance using the builder pattern 014 * <div class=code-example> 015 * <pre><code class='java'> 016 * ShippingRate shippingRate = ShippingRate.builder() 017 * .price(priceBuilder -> priceBuilder) 018 * .freeAbove(freeAboveBuilder -> freeAboveBuilder) 019 * .isMatching(true) 020 * .plusTiers(tiersBuilder -> tiersBuilder) 021 * .build() 022 * </code></pre> 023 * </div> 024 */ 025@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen") 026public class ShippingRateBuilder implements Builder<ShippingRate> { 027 028 private com.commercetools.history.models.common.Money price; 029 030 private com.commercetools.history.models.common.Money freeAbove; 031 032 private Boolean isMatching; 033 034 private java.util.List<com.commercetools.history.models.common.ShippingRatePriceTier> tiers; 035 036 /** 037 * set the value to the price using the builder function 038 * @param builder function to build the price value 039 * @return Builder 040 */ 041 042 public ShippingRateBuilder price( 043 Function<com.commercetools.history.models.common.MoneyBuilder, com.commercetools.history.models.common.MoneyBuilder> builder) { 044 this.price = builder.apply(com.commercetools.history.models.common.MoneyBuilder.of()).build(); 045 return this; 046 } 047 048 /** 049 * set the value to the price using the builder function 050 * @param builder function to build the price value 051 * @return Builder 052 */ 053 054 public ShippingRateBuilder withPrice( 055 Function<com.commercetools.history.models.common.MoneyBuilder, com.commercetools.history.models.common.Money> builder) { 056 this.price = builder.apply(com.commercetools.history.models.common.MoneyBuilder.of()); 057 return this; 058 } 059 060 /** 061 * set the value to the price 062 * @param price value to be set 063 * @return Builder 064 */ 065 066 public ShippingRateBuilder price(final com.commercetools.history.models.common.Money price) { 067 this.price = price; 068 return this; 069 } 070 071 /** 072 * set the value to the freeAbove using the builder function 073 * @param builder function to build the freeAbove value 074 * @return Builder 075 */ 076 077 public ShippingRateBuilder freeAbove( 078 Function<com.commercetools.history.models.common.MoneyBuilder, com.commercetools.history.models.common.MoneyBuilder> builder) { 079 this.freeAbove = builder.apply(com.commercetools.history.models.common.MoneyBuilder.of()).build(); 080 return this; 081 } 082 083 /** 084 * set the value to the freeAbove using the builder function 085 * @param builder function to build the freeAbove value 086 * @return Builder 087 */ 088 089 public ShippingRateBuilder withFreeAbove( 090 Function<com.commercetools.history.models.common.MoneyBuilder, com.commercetools.history.models.common.Money> builder) { 091 this.freeAbove = builder.apply(com.commercetools.history.models.common.MoneyBuilder.of()); 092 return this; 093 } 094 095 /** 096 * set the value to the freeAbove 097 * @param freeAbove value to be set 098 * @return Builder 099 */ 100 101 public ShippingRateBuilder freeAbove(final com.commercetools.history.models.common.Money freeAbove) { 102 this.freeAbove = freeAbove; 103 return this; 104 } 105 106 /** 107 * <p>Only appears in response to requests for ShippingMethods by Cart or location to mark this shipping rate as one that matches the Cart or location.</p> 108 * @param isMatching value to be set 109 * @return Builder 110 */ 111 112 public ShippingRateBuilder isMatching(final Boolean isMatching) { 113 this.isMatching = isMatching; 114 return this; 115 } 116 117 /** 118 * set values to the tiers 119 * @param tiers value to be set 120 * @return Builder 121 */ 122 123 public ShippingRateBuilder tiers(final com.commercetools.history.models.common.ShippingRatePriceTier... tiers) { 124 this.tiers = new ArrayList<>(Arrays.asList(tiers)); 125 return this; 126 } 127 128 /** 129 * set value to the tiers 130 * @param tiers value to be set 131 * @return Builder 132 */ 133 134 public ShippingRateBuilder tiers( 135 final java.util.List<com.commercetools.history.models.common.ShippingRatePriceTier> tiers) { 136 this.tiers = tiers; 137 return this; 138 } 139 140 /** 141 * add values to the tiers 142 * @param tiers value to be set 143 * @return Builder 144 */ 145 146 public ShippingRateBuilder plusTiers(final com.commercetools.history.models.common.ShippingRatePriceTier... tiers) { 147 if (this.tiers == null) { 148 this.tiers = new ArrayList<>(); 149 } 150 this.tiers.addAll(Arrays.asList(tiers)); 151 return this; 152 } 153 154 /** 155 * add the value to the tiers using the builder function 156 * @param builder function to build the tiers value 157 * @return Builder 158 */ 159 160 public ShippingRateBuilder plusTiers( 161 Function<com.commercetools.history.models.common.ShippingRatePriceTierBuilder, com.commercetools.history.models.common.ShippingRatePriceTierBuilder> builder) { 162 if (this.tiers == null) { 163 this.tiers = new ArrayList<>(); 164 } 165 this.tiers 166 .add(builder.apply(com.commercetools.history.models.common.ShippingRatePriceTierBuilder.of()).build()); 167 return this; 168 } 169 170 /** 171 * set the value to the tiers using the builder function 172 * @param builder function to build the tiers value 173 * @return Builder 174 */ 175 176 public ShippingRateBuilder withTiers( 177 Function<com.commercetools.history.models.common.ShippingRatePriceTierBuilder, com.commercetools.history.models.common.ShippingRatePriceTierBuilder> builder) { 178 this.tiers = new ArrayList<>(); 179 this.tiers 180 .add(builder.apply(com.commercetools.history.models.common.ShippingRatePriceTierBuilder.of()).build()); 181 return this; 182 } 183 184 /** 185 * add the value to the tiers using the builder function 186 * @param builder function to build the tiers value 187 * @return Builder 188 */ 189 190 public ShippingRateBuilder addTiers( 191 Function<com.commercetools.history.models.common.ShippingRatePriceTierBuilder, com.commercetools.history.models.common.ShippingRatePriceTier> builder) { 192 return plusTiers(builder.apply(com.commercetools.history.models.common.ShippingRatePriceTierBuilder.of())); 193 } 194 195 /** 196 * set the value to the tiers using the builder function 197 * @param builder function to build the tiers value 198 * @return Builder 199 */ 200 201 public ShippingRateBuilder setTiers( 202 Function<com.commercetools.history.models.common.ShippingRatePriceTierBuilder, com.commercetools.history.models.common.ShippingRatePriceTier> builder) { 203 return tiers(builder.apply(com.commercetools.history.models.common.ShippingRatePriceTierBuilder.of())); 204 } 205 206 /** 207 * value of price} 208 * @return price 209 */ 210 211 public com.commercetools.history.models.common.Money getPrice() { 212 return this.price; 213 } 214 215 /** 216 * value of freeAbove} 217 * @return freeAbove 218 */ 219 220 public com.commercetools.history.models.common.Money getFreeAbove() { 221 return this.freeAbove; 222 } 223 224 /** 225 * <p>Only appears in response to requests for ShippingMethods by Cart or location to mark this shipping rate as one that matches the Cart or location.</p> 226 * @return isMatching 227 */ 228 229 public Boolean getIsMatching() { 230 return this.isMatching; 231 } 232 233 /** 234 * value of tiers} 235 * @return tiers 236 */ 237 238 public java.util.List<com.commercetools.history.models.common.ShippingRatePriceTier> getTiers() { 239 return this.tiers; 240 } 241 242 /** 243 * builds ShippingRate with checking for non-null required values 244 * @return ShippingRate 245 */ 246 public ShippingRate build() { 247 Objects.requireNonNull(price, ShippingRate.class + ": price is missing"); 248 Objects.requireNonNull(freeAbove, ShippingRate.class + ": freeAbove is missing"); 249 Objects.requireNonNull(isMatching, ShippingRate.class + ": isMatching is missing"); 250 Objects.requireNonNull(tiers, ShippingRate.class + ": tiers is missing"); 251 return new ShippingRateImpl(price, freeAbove, isMatching, tiers); 252 } 253 254 /** 255 * builds ShippingRate without checking for non-null required values 256 * @return ShippingRate 257 */ 258 public ShippingRate buildUnchecked() { 259 return new ShippingRateImpl(price, freeAbove, isMatching, tiers); 260 } 261 262 /** 263 * factory method for an instance of ShippingRateBuilder 264 * @return builder 265 */ 266 public static ShippingRateBuilder of() { 267 return new ShippingRateBuilder(); 268 } 269 270 /** 271 * create builder for ShippingRate instance 272 * @param template instance with prefilled values for the builder 273 * @return builder 274 */ 275 public static ShippingRateBuilder of(final ShippingRate template) { 276 ShippingRateBuilder builder = new ShippingRateBuilder(); 277 builder.price = template.getPrice(); 278 builder.freeAbove = template.getFreeAbove(); 279 builder.isMatching = template.getIsMatching(); 280 builder.tiers = template.getTiers(); 281 return builder; 282 } 283 284}