001 002package com.commercetools.api.models.product; 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 * ProductUpdateBuilder 012 * <hr> 013 * Example to create an instance using the builder pattern 014 * <div class=code-example> 015 * <pre><code class='java'> 016 * ProductUpdate productUpdate = ProductUpdate.builder() 017 * .version(0.3) 018 * .plusActions(actionsBuilder -> actionsBuilder) 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 ProductUpdateBuilder implements Builder<ProductUpdate> { 025 026 private Long version; 027 028 private java.util.List<com.commercetools.api.models.product.ProductUpdateAction> actions; 029 030 /** 031 * <p>Expected version of the Product on which the changes should be applied. If the expected version does not match the actual version, a 409 Conflict will be returned.</p> 032 * @param version value to be set 033 * @return Builder 034 */ 035 036 public ProductUpdateBuilder version(final Long version) { 037 this.version = version; 038 return this; 039 } 040 041 /** 042 * <p>Update actions to be performed on the Product.</p> 043 * @param actions value to be set 044 * @return Builder 045 */ 046 047 public ProductUpdateBuilder actions(final com.commercetools.api.models.product.ProductUpdateAction... actions) { 048 this.actions = new ArrayList<>(Arrays.asList(actions)); 049 return this; 050 } 051 052 /** 053 * <p>Update actions to be performed on the Product.</p> 054 * @param actions value to be set 055 * @return Builder 056 */ 057 058 public ProductUpdateBuilder actions( 059 final java.util.List<com.commercetools.api.models.product.ProductUpdateAction> actions) { 060 this.actions = actions; 061 return this; 062 } 063 064 /** 065 * <p>Update actions to be performed on the Product.</p> 066 * @param actions value to be set 067 * @return Builder 068 */ 069 070 public ProductUpdateBuilder plusActions(final com.commercetools.api.models.product.ProductUpdateAction... actions) { 071 if (this.actions == null) { 072 this.actions = new ArrayList<>(); 073 } 074 this.actions.addAll(Arrays.asList(actions)); 075 return this; 076 } 077 078 /** 079 * <p>Update actions to be performed on the Product.</p> 080 * @param builder function to build the actions value 081 * @return Builder 082 */ 083 084 public ProductUpdateBuilder plusActions( 085 Function<com.commercetools.api.models.product.ProductUpdateActionBuilder, Builder<? extends com.commercetools.api.models.product.ProductUpdateAction>> builder) { 086 if (this.actions == null) { 087 this.actions = new ArrayList<>(); 088 } 089 this.actions.add(builder.apply(com.commercetools.api.models.product.ProductUpdateActionBuilder.of()).build()); 090 return this; 091 } 092 093 /** 094 * <p>Update actions to be performed on the Product.</p> 095 * @param builder function to build the actions value 096 * @return Builder 097 */ 098 099 public ProductUpdateBuilder withActions( 100 Function<com.commercetools.api.models.product.ProductUpdateActionBuilder, Builder<? extends com.commercetools.api.models.product.ProductUpdateAction>> builder) { 101 this.actions = new ArrayList<>(); 102 this.actions.add(builder.apply(com.commercetools.api.models.product.ProductUpdateActionBuilder.of()).build()); 103 return this; 104 } 105 106 /** 107 * <p>Expected version of the Product on which the changes should be applied. If the expected version does not match the actual version, a 409 Conflict will be returned.</p> 108 * @return version 109 */ 110 111 public Long getVersion() { 112 return this.version; 113 } 114 115 /** 116 * <p>Update actions to be performed on the Product.</p> 117 * @return actions 118 */ 119 120 public java.util.List<com.commercetools.api.models.product.ProductUpdateAction> getActions() { 121 return this.actions; 122 } 123 124 /** 125 * builds ProductUpdate with checking for non-null required values 126 * @return ProductUpdate 127 */ 128 public ProductUpdate build() { 129 Objects.requireNonNull(version, ProductUpdate.class + ": version is missing"); 130 Objects.requireNonNull(actions, ProductUpdate.class + ": actions is missing"); 131 return new ProductUpdateImpl(version, actions); 132 } 133 134 /** 135 * builds ProductUpdate without checking for non-null required values 136 * @return ProductUpdate 137 */ 138 public ProductUpdate buildUnchecked() { 139 return new ProductUpdateImpl(version, actions); 140 } 141 142 /** 143 * factory method for an instance of ProductUpdateBuilder 144 * @return builder 145 */ 146 public static ProductUpdateBuilder of() { 147 return new ProductUpdateBuilder(); 148 } 149 150 /** 151 * create builder for ProductUpdate instance 152 * @param template instance with prefilled values for the builder 153 * @return builder 154 */ 155 public static ProductUpdateBuilder of(final ProductUpdate template) { 156 ProductUpdateBuilder builder = new ProductUpdateBuilder(); 157 builder.version = template.getVersion(); 158 builder.actions = template.getActions(); 159 return builder; 160 } 161 162}