001 002package com.commercetools.ml.models.image_search; 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 * ImageSearchResponseBuilder 012 * <hr> 013 * Example to create an instance using the builder pattern 014 * <div class=code-example> 015 * <pre><code class='java'> 016 * ImageSearchResponse imageSearchResponse = ImageSearchResponse.builder() 017 * .count(0.3) 018 * .offset(0.3) 019 * .total(0.3) 020 * .plusResults(resultsBuilder -> resultsBuilder) 021 * .build() 022 * </code></pre> 023 * </div> 024 */ 025@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen") 026public class ImageSearchResponseBuilder implements Builder<ImageSearchResponse> { 027 028 private Integer count; 029 030 private Double offset; 031 032 private Integer total; 033 034 private java.util.List<com.commercetools.ml.models.image_search.ResultItem> results; 035 036 /** 037 * <p>The maximum number of results to return from a query.</p> 038 */ 039 040 public ImageSearchResponseBuilder count(final Integer count) { 041 this.count = count; 042 return this; 043 } 044 045 /** 046 * <p>Number of elements skipped.</p> 047 */ 048 049 public ImageSearchResponseBuilder offset(final Double offset) { 050 this.offset = offset; 051 return this; 052 } 053 054 /** 055 * <p>The total number of product images that were have been analyzed.</p> 056 */ 057 058 public ImageSearchResponseBuilder total(final Integer total) { 059 this.total = total; 060 return this; 061 } 062 063 /** 064 * <p>An array of image URLs of images that are similar to the query image. If no matching images are found, results is empty.</p> 065 */ 066 067 public ImageSearchResponseBuilder results(final com.commercetools.ml.models.image_search.ResultItem... results) { 068 this.results = new ArrayList<>(Arrays.asList(results)); 069 return this; 070 } 071 072 /** 073 * <p>An array of image URLs of images that are similar to the query image. If no matching images are found, results is empty.</p> 074 */ 075 076 public ImageSearchResponseBuilder results( 077 final java.util.List<com.commercetools.ml.models.image_search.ResultItem> results) { 078 this.results = results; 079 return this; 080 } 081 082 /** 083 * <p>An array of image URLs of images that are similar to the query image. If no matching images are found, results is empty.</p> 084 */ 085 086 public ImageSearchResponseBuilder plusResults( 087 final com.commercetools.ml.models.image_search.ResultItem... results) { 088 if (this.results == null) { 089 this.results = new ArrayList<>(); 090 } 091 this.results.addAll(Arrays.asList(results)); 092 return this; 093 } 094 095 /** 096 * <p>An array of image URLs of images that are similar to the query image. If no matching images are found, results is empty.</p> 097 */ 098 099 public ImageSearchResponseBuilder plusResults( 100 Function<com.commercetools.ml.models.image_search.ResultItemBuilder, com.commercetools.ml.models.image_search.ResultItemBuilder> builder) { 101 if (this.results == null) { 102 this.results = new ArrayList<>(); 103 } 104 this.results.add(builder.apply(com.commercetools.ml.models.image_search.ResultItemBuilder.of()).build()); 105 return this; 106 } 107 108 /** 109 * <p>An array of image URLs of images that are similar to the query image. If no matching images are found, results is empty.</p> 110 */ 111 112 public ImageSearchResponseBuilder withResults( 113 Function<com.commercetools.ml.models.image_search.ResultItemBuilder, com.commercetools.ml.models.image_search.ResultItemBuilder> builder) { 114 this.results = new ArrayList<>(); 115 this.results.add(builder.apply(com.commercetools.ml.models.image_search.ResultItemBuilder.of()).build()); 116 return this; 117 } 118 119 public Integer getCount() { 120 return this.count; 121 } 122 123 public Double getOffset() { 124 return this.offset; 125 } 126 127 public Integer getTotal() { 128 return this.total; 129 } 130 131 public java.util.List<com.commercetools.ml.models.image_search.ResultItem> getResults() { 132 return this.results; 133 } 134 135 public ImageSearchResponse build() { 136 Objects.requireNonNull(count, ImageSearchResponse.class + ": count is missing"); 137 Objects.requireNonNull(offset, ImageSearchResponse.class + ": offset is missing"); 138 Objects.requireNonNull(total, ImageSearchResponse.class + ": total is missing"); 139 Objects.requireNonNull(results, ImageSearchResponse.class + ": results is missing"); 140 return new ImageSearchResponseImpl(count, offset, total, results); 141 } 142 143 /** 144 * builds ImageSearchResponse without checking for non null required values 145 */ 146 public ImageSearchResponse buildUnchecked() { 147 return new ImageSearchResponseImpl(count, offset, total, results); 148 } 149 150 public static ImageSearchResponseBuilder of() { 151 return new ImageSearchResponseBuilder(); 152 } 153 154 public static ImageSearchResponseBuilder of(final ImageSearchResponse template) { 155 ImageSearchResponseBuilder builder = new ImageSearchResponseBuilder(); 156 builder.count = template.getCount(); 157 builder.offset = template.getOffset(); 158 builder.total = template.getTotal(); 159 builder.results = template.getResults(); 160 return builder; 161 } 162 163}