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