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