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 * TransactionBuilder 012 * <hr> 013 * Example to create an instance using the builder pattern 014 * <div class=code-example> 015 * <pre><code class='java'> 016 * Transaction transaction = Transaction.builder() 017 * .id("{id}") 018 * .timestamp("{timestamp}") 019 * .type(TransactionType.AUTHORIZATION) 020 * .amount(amountBuilder -> amountBuilder) 021 * .interactionId("{interactionId}") 022 * .state(TransactionState.INITIAL) 023 * .build() 024 * </code></pre> 025 * </div> 026 */ 027@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen") 028public class TransactionBuilder implements Builder<Transaction> { 029 030 private String id; 031 032 private String timestamp; 033 034 private com.commercetools.history.models.common.TransactionType type; 035 036 private com.commercetools.history.models.common.Money amount; 037 038 private String interactionId; 039 040 private com.commercetools.history.models.common.TransactionState state; 041 042 /** 043 * <p>Unique identifier of the Transaction.</p> 044 * @param id value to be set 045 * @return Builder 046 */ 047 048 public TransactionBuilder id(final String id) { 049 this.id = id; 050 return this; 051 } 052 053 /** 054 * <p>Time at which the transaction took place.</p> 055 * @param timestamp value to be set 056 * @return Builder 057 */ 058 059 public TransactionBuilder timestamp(final String timestamp) { 060 this.timestamp = timestamp; 061 return this; 062 } 063 064 /** 065 * set the value to the type 066 * @param type value to be set 067 * @return Builder 068 */ 069 070 public TransactionBuilder type(final com.commercetools.history.models.common.TransactionType type) { 071 this.type = type; 072 return this; 073 } 074 075 /** 076 * set the value to the amount using the builder function 077 * @param builder function to build the amount value 078 * @return Builder 079 */ 080 081 public TransactionBuilder amount( 082 Function<com.commercetools.history.models.common.MoneyBuilder, com.commercetools.history.models.common.MoneyBuilder> builder) { 083 this.amount = builder.apply(com.commercetools.history.models.common.MoneyBuilder.of()).build(); 084 return this; 085 } 086 087 /** 088 * set the value to the amount using the builder function 089 * @param builder function to build the amount value 090 * @return Builder 091 */ 092 093 public TransactionBuilder withAmount( 094 Function<com.commercetools.history.models.common.MoneyBuilder, com.commercetools.history.models.common.Money> builder) { 095 this.amount = builder.apply(com.commercetools.history.models.common.MoneyBuilder.of()); 096 return this; 097 } 098 099 /** 100 * set the value to the amount 101 * @param amount value to be set 102 * @return Builder 103 */ 104 105 public TransactionBuilder amount(final com.commercetools.history.models.common.Money amount) { 106 this.amount = amount; 107 return this; 108 } 109 110 /** 111 * <p>Identifier used by the interface that manages the transaction (usually the PSP). If a matching interaction was logged in the <code>interfaceInteractions</code> array, the corresponding interaction should be findable with this ID.</p> 112 * @param interactionId value to be set 113 * @return Builder 114 */ 115 116 public TransactionBuilder interactionId(final String interactionId) { 117 this.interactionId = interactionId; 118 return this; 119 } 120 121 /** 122 * set the value to the state 123 * @param state value to be set 124 * @return Builder 125 */ 126 127 public TransactionBuilder state(final com.commercetools.history.models.common.TransactionState state) { 128 this.state = state; 129 return this; 130 } 131 132 /** 133 * <p>Unique identifier of the Transaction.</p> 134 * @return id 135 */ 136 137 public String getId() { 138 return this.id; 139 } 140 141 /** 142 * <p>Time at which the transaction took place.</p> 143 * @return timestamp 144 */ 145 146 public String getTimestamp() { 147 return this.timestamp; 148 } 149 150 /** 151 * value of type} 152 * @return type 153 */ 154 155 public com.commercetools.history.models.common.TransactionType getType() { 156 return this.type; 157 } 158 159 /** 160 * value of amount} 161 * @return amount 162 */ 163 164 public com.commercetools.history.models.common.Money getAmount() { 165 return this.amount; 166 } 167 168 /** 169 * <p>Identifier used by the interface that manages the transaction (usually the PSP). If a matching interaction was logged in the <code>interfaceInteractions</code> array, the corresponding interaction should be findable with this ID.</p> 170 * @return interactionId 171 */ 172 173 public String getInteractionId() { 174 return this.interactionId; 175 } 176 177 /** 178 * value of state} 179 * @return state 180 */ 181 182 public com.commercetools.history.models.common.TransactionState getState() { 183 return this.state; 184 } 185 186 /** 187 * builds Transaction with checking for non-null required values 188 * @return Transaction 189 */ 190 public Transaction build() { 191 Objects.requireNonNull(id, Transaction.class + ": id is missing"); 192 Objects.requireNonNull(timestamp, Transaction.class + ": timestamp is missing"); 193 Objects.requireNonNull(type, Transaction.class + ": type is missing"); 194 Objects.requireNonNull(amount, Transaction.class + ": amount is missing"); 195 Objects.requireNonNull(interactionId, Transaction.class + ": interactionId is missing"); 196 Objects.requireNonNull(state, Transaction.class + ": state is missing"); 197 return new TransactionImpl(id, timestamp, type, amount, interactionId, state); 198 } 199 200 /** 201 * builds Transaction without checking for non-null required values 202 * @return Transaction 203 */ 204 public Transaction buildUnchecked() { 205 return new TransactionImpl(id, timestamp, type, amount, interactionId, state); 206 } 207 208 /** 209 * factory method for an instance of TransactionBuilder 210 * @return builder 211 */ 212 public static TransactionBuilder of() { 213 return new TransactionBuilder(); 214 } 215 216 /** 217 * create builder for Transaction instance 218 * @param template instance with prefilled values for the builder 219 * @return builder 220 */ 221 public static TransactionBuilder of(final Transaction template) { 222 TransactionBuilder builder = new TransactionBuilder(); 223 builder.id = template.getId(); 224 builder.timestamp = template.getTimestamp(); 225 builder.type = template.getType(); 226 builder.amount = template.getAmount(); 227 builder.interactionId = template.getInteractionId(); 228 builder.state = template.getState(); 229 return builder; 230 } 231 232}