1 /* 2 * Copyright 2022 Google LLC 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.cloud.retail.v2; 18 19 import com.google.api.pathtemplate.PathTemplate; 20 import com.google.api.resourcenames.ResourceName; 21 import com.google.common.base.Preconditions; 22 import com.google.common.collect.ImmutableMap; 23 import java.util.ArrayList; 24 import java.util.List; 25 import java.util.Map; 26 import java.util.Objects; 27 import javax.annotation.Generated; 28 29 // AUTO-GENERATED DOCUMENTATION AND CLASS. 30 @Generated("by gapic-generator-java") 31 public class ProductName implements ResourceName { 32 private static final PathTemplate PROJECT_LOCATION_CATALOG_BRANCH_PRODUCT = 33 PathTemplate.createWithoutUrlEncoding( 34 "projects/{project}/locations/{location}/catalogs/{catalog}/branches/{branch}/products/{product}"); 35 private volatile Map<String, String> fieldValuesMap; 36 private final String project; 37 private final String location; 38 private final String catalog; 39 private final String branch; 40 private final String product; 41 42 @Deprecated ProductName()43 protected ProductName() { 44 project = null; 45 location = null; 46 catalog = null; 47 branch = null; 48 product = null; 49 } 50 ProductName(Builder builder)51 private ProductName(Builder builder) { 52 project = Preconditions.checkNotNull(builder.getProject()); 53 location = Preconditions.checkNotNull(builder.getLocation()); 54 catalog = Preconditions.checkNotNull(builder.getCatalog()); 55 branch = Preconditions.checkNotNull(builder.getBranch()); 56 product = Preconditions.checkNotNull(builder.getProduct()); 57 } 58 getProject()59 public String getProject() { 60 return project; 61 } 62 getLocation()63 public String getLocation() { 64 return location; 65 } 66 getCatalog()67 public String getCatalog() { 68 return catalog; 69 } 70 getBranch()71 public String getBranch() { 72 return branch; 73 } 74 getProduct()75 public String getProduct() { 76 return product; 77 } 78 newBuilder()79 public static Builder newBuilder() { 80 return new Builder(); 81 } 82 toBuilder()83 public Builder toBuilder() { 84 return new Builder(this); 85 } 86 of( String project, String location, String catalog, String branch, String product)87 public static ProductName of( 88 String project, String location, String catalog, String branch, String product) { 89 return newBuilder() 90 .setProject(project) 91 .setLocation(location) 92 .setCatalog(catalog) 93 .setBranch(branch) 94 .setProduct(product) 95 .build(); 96 } 97 format( String project, String location, String catalog, String branch, String product)98 public static String format( 99 String project, String location, String catalog, String branch, String product) { 100 return newBuilder() 101 .setProject(project) 102 .setLocation(location) 103 .setCatalog(catalog) 104 .setBranch(branch) 105 .setProduct(product) 106 .build() 107 .toString(); 108 } 109 parse(String formattedString)110 public static ProductName parse(String formattedString) { 111 if (formattedString.isEmpty()) { 112 return null; 113 } 114 Map<String, String> matchMap = 115 PROJECT_LOCATION_CATALOG_BRANCH_PRODUCT.validatedMatch( 116 formattedString, "ProductName.parse: formattedString not in valid format"); 117 return of( 118 matchMap.get("project"), 119 matchMap.get("location"), 120 matchMap.get("catalog"), 121 matchMap.get("branch"), 122 matchMap.get("product")); 123 } 124 parseList(List<String> formattedStrings)125 public static List<ProductName> parseList(List<String> formattedStrings) { 126 List<ProductName> list = new ArrayList<>(formattedStrings.size()); 127 for (String formattedString : formattedStrings) { 128 list.add(parse(formattedString)); 129 } 130 return list; 131 } 132 toStringList(List<ProductName> values)133 public static List<String> toStringList(List<ProductName> values) { 134 List<String> list = new ArrayList<>(values.size()); 135 for (ProductName value : values) { 136 if (value == null) { 137 list.add(""); 138 } else { 139 list.add(value.toString()); 140 } 141 } 142 return list; 143 } 144 isParsableFrom(String formattedString)145 public static boolean isParsableFrom(String formattedString) { 146 return PROJECT_LOCATION_CATALOG_BRANCH_PRODUCT.matches(formattedString); 147 } 148 149 @Override getFieldValuesMap()150 public Map<String, String> getFieldValuesMap() { 151 if (fieldValuesMap == null) { 152 synchronized (this) { 153 if (fieldValuesMap == null) { 154 ImmutableMap.Builder<String, String> fieldMapBuilder = ImmutableMap.builder(); 155 if (project != null) { 156 fieldMapBuilder.put("project", project); 157 } 158 if (location != null) { 159 fieldMapBuilder.put("location", location); 160 } 161 if (catalog != null) { 162 fieldMapBuilder.put("catalog", catalog); 163 } 164 if (branch != null) { 165 fieldMapBuilder.put("branch", branch); 166 } 167 if (product != null) { 168 fieldMapBuilder.put("product", product); 169 } 170 fieldValuesMap = fieldMapBuilder.build(); 171 } 172 } 173 } 174 return fieldValuesMap; 175 } 176 getFieldValue(String fieldName)177 public String getFieldValue(String fieldName) { 178 return getFieldValuesMap().get(fieldName); 179 } 180 181 @Override toString()182 public String toString() { 183 return PROJECT_LOCATION_CATALOG_BRANCH_PRODUCT.instantiate( 184 "project", 185 project, 186 "location", 187 location, 188 "catalog", 189 catalog, 190 "branch", 191 branch, 192 "product", 193 product); 194 } 195 196 @Override equals(Object o)197 public boolean equals(Object o) { 198 if (o == this) { 199 return true; 200 } 201 if (o != null || getClass() == o.getClass()) { 202 ProductName that = ((ProductName) o); 203 return Objects.equals(this.project, that.project) 204 && Objects.equals(this.location, that.location) 205 && Objects.equals(this.catalog, that.catalog) 206 && Objects.equals(this.branch, that.branch) 207 && Objects.equals(this.product, that.product); 208 } 209 return false; 210 } 211 212 @Override hashCode()213 public int hashCode() { 214 int h = 1; 215 h *= 1000003; 216 h ^= Objects.hashCode(project); 217 h *= 1000003; 218 h ^= Objects.hashCode(location); 219 h *= 1000003; 220 h ^= Objects.hashCode(catalog); 221 h *= 1000003; 222 h ^= Objects.hashCode(branch); 223 h *= 1000003; 224 h ^= Objects.hashCode(product); 225 return h; 226 } 227 228 /** 229 * Builder for 230 * projects/{project}/locations/{location}/catalogs/{catalog}/branches/{branch}/products/{product}. 231 */ 232 public static class Builder { 233 private String project; 234 private String location; 235 private String catalog; 236 private String branch; 237 private String product; 238 Builder()239 protected Builder() {} 240 getProject()241 public String getProject() { 242 return project; 243 } 244 getLocation()245 public String getLocation() { 246 return location; 247 } 248 getCatalog()249 public String getCatalog() { 250 return catalog; 251 } 252 getBranch()253 public String getBranch() { 254 return branch; 255 } 256 getProduct()257 public String getProduct() { 258 return product; 259 } 260 setProject(String project)261 public Builder setProject(String project) { 262 this.project = project; 263 return this; 264 } 265 setLocation(String location)266 public Builder setLocation(String location) { 267 this.location = location; 268 return this; 269 } 270 setCatalog(String catalog)271 public Builder setCatalog(String catalog) { 272 this.catalog = catalog; 273 return this; 274 } 275 setBranch(String branch)276 public Builder setBranch(String branch) { 277 this.branch = branch; 278 return this; 279 } 280 setProduct(String product)281 public Builder setProduct(String product) { 282 this.product = product; 283 return this; 284 } 285 Builder(ProductName productName)286 private Builder(ProductName productName) { 287 this.project = productName.project; 288 this.location = productName.location; 289 this.catalog = productName.catalog; 290 this.branch = productName.branch; 291 this.product = productName.product; 292 } 293 build()294 public ProductName build() { 295 return new ProductName(this); 296 } 297 } 298 } 299