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