001 002package com.commercetools.importapi.models.common; 003 004import java.util.*; 005 006import javax.annotation.Nullable; 007 008import io.vrap.rmf.base.client.Builder; 009import io.vrap.rmf.base.client.utils.Generated; 010 011/** 012 * MoneyBuilder 013 * <hr> 014 * Example to create an instance using the builder pattern 015 * <div class=code-example> 016 * <pre><code class='java'> 017 * Money money = Money.builder() 018 * .centAmount(0.3) 019 * .currencyCode("{currencyCode}") 020 * .build() 021 * </code></pre> 022 * </div> 023 */ 024@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen") 025public class MoneyBuilder implements Builder<Money> { 026 027 @Nullable 028 private Integer fractionDigits; 029 030 private Long centAmount; 031 032 private String currencyCode; 033 034 /** 035 * set the value to the fractionDigits 036 * @param fractionDigits value to be set 037 * @return Builder 038 */ 039 040 public MoneyBuilder fractionDigits(@Nullable final Integer fractionDigits) { 041 this.fractionDigits = fractionDigits; 042 return this; 043 } 044 045 /** 046 * set the value to the centAmount 047 * @param centAmount value to be set 048 * @return Builder 049 */ 050 051 public MoneyBuilder centAmount(final Long centAmount) { 052 this.centAmount = centAmount; 053 return this; 054 } 055 056 /** 057 * <p>The currency code compliant to ISO 4217.</p> 058 * @param currencyCode value to be set 059 * @return Builder 060 */ 061 062 public MoneyBuilder currencyCode(final String currencyCode) { 063 this.currencyCode = currencyCode; 064 return this; 065 } 066 067 /** 068 * value of fractionDigits} 069 * @return fractionDigits 070 */ 071 072 @Nullable 073 public Integer getFractionDigits() { 074 return this.fractionDigits; 075 } 076 077 /** 078 * value of centAmount} 079 * @return centAmount 080 */ 081 082 public Long getCentAmount() { 083 return this.centAmount; 084 } 085 086 /** 087 * <p>The currency code compliant to ISO 4217.</p> 088 * @return currencyCode 089 */ 090 091 public String getCurrencyCode() { 092 return this.currencyCode; 093 } 094 095 /** 096 * builds Money with checking for non-null required values 097 * @return Money 098 */ 099 public Money build() { 100 Objects.requireNonNull(centAmount, Money.class + ": centAmount is missing"); 101 Objects.requireNonNull(currencyCode, Money.class + ": currencyCode is missing"); 102 return new MoneyImpl(fractionDigits, centAmount, currencyCode); 103 } 104 105 /** 106 * builds Money without checking for non-null required values 107 * @return Money 108 */ 109 public Money buildUnchecked() { 110 return new MoneyImpl(fractionDigits, centAmount, currencyCode); 111 } 112 113 /** 114 * factory method for an instance of MoneyBuilder 115 * @return builder 116 */ 117 public static MoneyBuilder of() { 118 return new MoneyBuilder(); 119 } 120 121 /** 122 * create builder for Money instance 123 * @param template instance with prefilled values for the builder 124 * @return builder 125 */ 126 public static MoneyBuilder of(final Money template) { 127 MoneyBuilder builder = new MoneyBuilder(); 128 builder.fractionDigits = template.getFractionDigits(); 129 builder.centAmount = template.getCentAmount(); 130 builder.currencyCode = template.getCurrencyCode(); 131 return builder; 132 } 133 134}