001 002package com.commercetools.api.models.product; 003 004import java.util.*; 005import java.util.function.Function; 006 007import javax.annotation.Nullable; 008 009import io.vrap.rmf.base.client.Builder; 010import io.vrap.rmf.base.client.utils.Generated; 011 012/** 013 * ProductPagedQueryResponseBuilder 014 * <hr> 015 * Example to create an instance using the builder pattern 016 * <div class=code-example> 017 * <pre><code class='java'> 018 * ProductPagedQueryResponse productPagedQueryResponse = ProductPagedQueryResponse.builder() 019 * .limit(0.3) 020 * .offset(0.3) 021 * .count(0.3) 022 * .plusResults(resultsBuilder -> resultsBuilder) 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 ProductPagedQueryResponseBuilder implements Builder<ProductPagedQueryResponse> { 029 030 private Long limit; 031 032 private Long offset; 033 034 private Long count; 035 036 @Nullable 037 private Long total; 038 039 private java.util.List<com.commercetools.api.models.product.Product> results; 040 041 /** 042 * <p>Number of results requested.</p> 043 * @param limit value to be set 044 * @return Builder 045 */ 046 047 public ProductPagedQueryResponseBuilder limit(final Long limit) { 048 this.limit = limit; 049 return this; 050 } 051 052 /** 053 * <p>Number of elements skipped.</p> 054 * @param offset value to be set 055 * @return Builder 056 */ 057 058 public ProductPagedQueryResponseBuilder offset(final Long offset) { 059 this.offset = offset; 060 return this; 061 } 062 063 /** 064 * <p>Actual number of results returned.</p> 065 * @param count value to be set 066 * @return Builder 067 */ 068 069 public ProductPagedQueryResponseBuilder count(final Long count) { 070 this.count = count; 071 return this; 072 } 073 074 /** 075 * <p>Total number of results matching the query. This number is an estimation that is not strongly consistent. This field is returned by default. For improved performance, calculating this field can be deactivated by using the query parameter <code>withTotal=false</code>. When the results are filtered with a Query Predicate, <code>total</code> is subject to a limit.</p> 076 * @param total value to be set 077 * @return Builder 078 */ 079 080 public ProductPagedQueryResponseBuilder total(@Nullable final Long total) { 081 this.total = total; 082 return this; 083 } 084 085 /** 086 * <p>Products matching the query.</p> 087 * @param results value to be set 088 * @return Builder 089 */ 090 091 public ProductPagedQueryResponseBuilder results(final com.commercetools.api.models.product.Product... results) { 092 this.results = new ArrayList<>(Arrays.asList(results)); 093 return this; 094 } 095 096 /** 097 * <p>Products matching the query.</p> 098 * @param results value to be set 099 * @return Builder 100 */ 101 102 public ProductPagedQueryResponseBuilder results( 103 final java.util.List<com.commercetools.api.models.product.Product> results) { 104 this.results = results; 105 return this; 106 } 107 108 /** 109 * <p>Products matching the query.</p> 110 * @param results value to be set 111 * @return Builder 112 */ 113 114 public ProductPagedQueryResponseBuilder plusResults(final com.commercetools.api.models.product.Product... results) { 115 if (this.results == null) { 116 this.results = new ArrayList<>(); 117 } 118 this.results.addAll(Arrays.asList(results)); 119 return this; 120 } 121 122 /** 123 * <p>Products matching the query.</p> 124 * @param builder function to build the results value 125 * @return Builder 126 */ 127 128 public ProductPagedQueryResponseBuilder plusResults( 129 Function<com.commercetools.api.models.product.ProductBuilder, com.commercetools.api.models.product.ProductBuilder> builder) { 130 if (this.results == null) { 131 this.results = new ArrayList<>(); 132 } 133 this.results.add(builder.apply(com.commercetools.api.models.product.ProductBuilder.of()).build()); 134 return this; 135 } 136 137 /** 138 * <p>Products matching the query.</p> 139 * @param builder function to build the results value 140 * @return Builder 141 */ 142 143 public ProductPagedQueryResponseBuilder withResults( 144 Function<com.commercetools.api.models.product.ProductBuilder, com.commercetools.api.models.product.ProductBuilder> builder) { 145 this.results = new ArrayList<>(); 146 this.results.add(builder.apply(com.commercetools.api.models.product.ProductBuilder.of()).build()); 147 return this; 148 } 149 150 /** 151 * <p>Products matching the query.</p> 152 * @param builder function to build the results value 153 * @return Builder 154 */ 155 156 public ProductPagedQueryResponseBuilder addResults( 157 Function<com.commercetools.api.models.product.ProductBuilder, com.commercetools.api.models.product.Product> builder) { 158 return plusResults(builder.apply(com.commercetools.api.models.product.ProductBuilder.of())); 159 } 160 161 /** 162 * <p>Products matching the query.</p> 163 * @param builder function to build the results value 164 * @return Builder 165 */ 166 167 public ProductPagedQueryResponseBuilder setResults( 168 Function<com.commercetools.api.models.product.ProductBuilder, com.commercetools.api.models.product.Product> builder) { 169 return results(builder.apply(com.commercetools.api.models.product.ProductBuilder.of())); 170 } 171 172 /** 173 * <p>Number of results requested.</p> 174 * @return limit 175 */ 176 177 public Long getLimit() { 178 return this.limit; 179 } 180 181 /** 182 * <p>Number of elements skipped.</p> 183 * @return offset 184 */ 185 186 public Long getOffset() { 187 return this.offset; 188 } 189 190 /** 191 * <p>Actual number of results returned.</p> 192 * @return count 193 */ 194 195 public Long getCount() { 196 return this.count; 197 } 198 199 /** 200 * <p>Total number of results matching the query. This number is an estimation that is not strongly consistent. This field is returned by default. For improved performance, calculating this field can be deactivated by using the query parameter <code>withTotal=false</code>. When the results are filtered with a Query Predicate, <code>total</code> is subject to a limit.</p> 201 * @return total 202 */ 203 204 @Nullable 205 public Long getTotal() { 206 return this.total; 207 } 208 209 /** 210 * <p>Products matching the query.</p> 211 * @return results 212 */ 213 214 public java.util.List<com.commercetools.api.models.product.Product> getResults() { 215 return this.results; 216 } 217 218 /** 219 * builds ProductPagedQueryResponse with checking for non-null required values 220 * @return ProductPagedQueryResponse 221 */ 222 public ProductPagedQueryResponse build() { 223 Objects.requireNonNull(limit, ProductPagedQueryResponse.class + ": limit is missing"); 224 Objects.requireNonNull(offset, ProductPagedQueryResponse.class + ": offset is missing"); 225 Objects.requireNonNull(count, ProductPagedQueryResponse.class + ": count is missing"); 226 Objects.requireNonNull(results, ProductPagedQueryResponse.class + ": results is missing"); 227 return new ProductPagedQueryResponseImpl(limit, offset, count, total, results); 228 } 229 230 /** 231 * builds ProductPagedQueryResponse without checking for non-null required values 232 * @return ProductPagedQueryResponse 233 */ 234 public ProductPagedQueryResponse buildUnchecked() { 235 return new ProductPagedQueryResponseImpl(limit, offset, count, total, results); 236 } 237 238 /** 239 * factory method for an instance of ProductPagedQueryResponseBuilder 240 * @return builder 241 */ 242 public static ProductPagedQueryResponseBuilder of() { 243 return new ProductPagedQueryResponseBuilder(); 244 } 245 246 /** 247 * create builder for ProductPagedQueryResponse instance 248 * @param template instance with prefilled values for the builder 249 * @return builder 250 */ 251 public static ProductPagedQueryResponseBuilder of(final ProductPagedQueryResponse template) { 252 ProductPagedQueryResponseBuilder builder = new ProductPagedQueryResponseBuilder(); 253 builder.limit = template.getLimit(); 254 builder.offset = template.getOffset(); 255 builder.count = template.getCount(); 256 builder.total = template.getTotal(); 257 builder.results = template.getResults(); 258 return builder; 259 } 260 261}