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 * ItemShippingDetailsBuilder 012 * <hr> 013 * Example to create an instance using the builder pattern 014 * <div class=code-example> 015 * <pre><code class='java'> 016 * ItemShippingDetails itemShippingDetails = ItemShippingDetails.builder() 017 * .plusTargets(targetsBuilder -> targetsBuilder) 018 * .valid(true) 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 ItemShippingDetailsBuilder implements Builder<ItemShippingDetails> { 025 026 private java.util.List<com.commercetools.history.models.common.ItemShippingTarget> targets; 027 028 private Boolean valid; 029 030 /** 031 * set values to the targets 032 * @param targets value to be set 033 * @return Builder 034 */ 035 036 public ItemShippingDetailsBuilder targets( 037 final com.commercetools.history.models.common.ItemShippingTarget... targets) { 038 this.targets = new ArrayList<>(Arrays.asList(targets)); 039 return this; 040 } 041 042 /** 043 * set value to the targets 044 * @param targets value to be set 045 * @return Builder 046 */ 047 048 public ItemShippingDetailsBuilder targets( 049 final java.util.List<com.commercetools.history.models.common.ItemShippingTarget> targets) { 050 this.targets = targets; 051 return this; 052 } 053 054 /** 055 * add values to the targets 056 * @param targets value to be set 057 * @return Builder 058 */ 059 060 public ItemShippingDetailsBuilder plusTargets( 061 final com.commercetools.history.models.common.ItemShippingTarget... targets) { 062 if (this.targets == null) { 063 this.targets = new ArrayList<>(); 064 } 065 this.targets.addAll(Arrays.asList(targets)); 066 return this; 067 } 068 069 /** 070 * add the value to the targets using the builder function 071 * @param builder function to build the targets value 072 * @return Builder 073 */ 074 075 public ItemShippingDetailsBuilder plusTargets( 076 Function<com.commercetools.history.models.common.ItemShippingTargetBuilder, com.commercetools.history.models.common.ItemShippingTargetBuilder> builder) { 077 if (this.targets == null) { 078 this.targets = new ArrayList<>(); 079 } 080 this.targets.add(builder.apply(com.commercetools.history.models.common.ItemShippingTargetBuilder.of()).build()); 081 return this; 082 } 083 084 /** 085 * set the value to the targets using the builder function 086 * @param builder function to build the targets value 087 * @return Builder 088 */ 089 090 public ItemShippingDetailsBuilder withTargets( 091 Function<com.commercetools.history.models.common.ItemShippingTargetBuilder, com.commercetools.history.models.common.ItemShippingTargetBuilder> builder) { 092 this.targets = new ArrayList<>(); 093 this.targets.add(builder.apply(com.commercetools.history.models.common.ItemShippingTargetBuilder.of()).build()); 094 return this; 095 } 096 097 /** 098 * add the value to the targets using the builder function 099 * @param builder function to build the targets value 100 * @return Builder 101 */ 102 103 public ItemShippingDetailsBuilder addTargets( 104 Function<com.commercetools.history.models.common.ItemShippingTargetBuilder, com.commercetools.history.models.common.ItemShippingTarget> builder) { 105 return plusTargets(builder.apply(com.commercetools.history.models.common.ItemShippingTargetBuilder.of())); 106 } 107 108 /** 109 * set the value to the targets using the builder function 110 * @param builder function to build the targets value 111 * @return Builder 112 */ 113 114 public ItemShippingDetailsBuilder setTargets( 115 Function<com.commercetools.history.models.common.ItemShippingTargetBuilder, com.commercetools.history.models.common.ItemShippingTarget> builder) { 116 return targets(builder.apply(com.commercetools.history.models.common.ItemShippingTargetBuilder.of())); 117 } 118 119 /** 120 * <p>true if the quantity of the (custom) line item is equal to the sum of the sub-quantities in <code>targets</code>, <code>false</code> otherwise. A cart cannot be ordered when the value is <code>false</code>. The error InvalidItemShippingDetails will be triggered.</p> 121 * @param valid value to be set 122 * @return Builder 123 */ 124 125 public ItemShippingDetailsBuilder valid(final Boolean valid) { 126 this.valid = valid; 127 return this; 128 } 129 130 /** 131 * value of targets} 132 * @return targets 133 */ 134 135 public java.util.List<com.commercetools.history.models.common.ItemShippingTarget> getTargets() { 136 return this.targets; 137 } 138 139 /** 140 * <p>true if the quantity of the (custom) line item is equal to the sum of the sub-quantities in <code>targets</code>, <code>false</code> otherwise. A cart cannot be ordered when the value is <code>false</code>. The error InvalidItemShippingDetails will be triggered.</p> 141 * @return valid 142 */ 143 144 public Boolean getValid() { 145 return this.valid; 146 } 147 148 /** 149 * builds ItemShippingDetails with checking for non-null required values 150 * @return ItemShippingDetails 151 */ 152 public ItemShippingDetails build() { 153 Objects.requireNonNull(targets, ItemShippingDetails.class + ": targets is missing"); 154 Objects.requireNonNull(valid, ItemShippingDetails.class + ": valid is missing"); 155 return new ItemShippingDetailsImpl(targets, valid); 156 } 157 158 /** 159 * builds ItemShippingDetails without checking for non-null required values 160 * @return ItemShippingDetails 161 */ 162 public ItemShippingDetails buildUnchecked() { 163 return new ItemShippingDetailsImpl(targets, valid); 164 } 165 166 /** 167 * factory method for an instance of ItemShippingDetailsBuilder 168 * @return builder 169 */ 170 public static ItemShippingDetailsBuilder of() { 171 return new ItemShippingDetailsBuilder(); 172 } 173 174 /** 175 * create builder for ItemShippingDetails instance 176 * @param template instance with prefilled values for the builder 177 * @return builder 178 */ 179 public static ItemShippingDetailsBuilder of(final ItemShippingDetails template) { 180 ItemShippingDetailsBuilder builder = new ItemShippingDetailsBuilder(); 181 builder.targets = template.getTargets(); 182 builder.valid = template.getValid(); 183 return builder; 184 } 185 186}