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.discoveryengine.v1beta; 18 19 import com.google.api.core.BetaApi; 20 import com.google.api.pathtemplate.PathTemplate; 21 import com.google.api.pathtemplate.ValidationException; 22 import com.google.api.resourcenames.ResourceName; 23 import com.google.common.base.Preconditions; 24 import com.google.common.collect.ImmutableMap; 25 import java.util.ArrayList; 26 import java.util.List; 27 import java.util.Map; 28 import java.util.Objects; 29 import javax.annotation.Generated; 30 31 // AUTO-GENERATED DOCUMENTATION AND CLASS. 32 @Generated("by gapic-generator-java") 33 public class BranchName implements ResourceName { 34 private static final PathTemplate PROJECT_LOCATION_DATA_STORE_BRANCH = 35 PathTemplate.createWithoutUrlEncoding( 36 "projects/{project}/locations/{location}/dataStores/{data_store}/branches/{branch}"); 37 private static final PathTemplate PROJECT_LOCATION_COLLECTION_DATA_STORE_BRANCH = 38 PathTemplate.createWithoutUrlEncoding( 39 "projects/{project}/locations/{location}/collections/{collection}/dataStores/{data_store}/branches/{branch}"); 40 private volatile Map<String, String> fieldValuesMap; 41 private PathTemplate pathTemplate; 42 private String fixedValue; 43 private final String project; 44 private final String location; 45 private final String dataStore; 46 private final String branch; 47 private final String collection; 48 49 @Deprecated BranchName()50 protected BranchName() { 51 project = null; 52 location = null; 53 dataStore = null; 54 branch = null; 55 collection = null; 56 } 57 BranchName(Builder builder)58 private BranchName(Builder builder) { 59 project = Preconditions.checkNotNull(builder.getProject()); 60 location = Preconditions.checkNotNull(builder.getLocation()); 61 dataStore = Preconditions.checkNotNull(builder.getDataStore()); 62 branch = Preconditions.checkNotNull(builder.getBranch()); 63 collection = null; 64 pathTemplate = PROJECT_LOCATION_DATA_STORE_BRANCH; 65 } 66 BranchName(ProjectLocationCollectionDataStoreBranchBuilder builder)67 private BranchName(ProjectLocationCollectionDataStoreBranchBuilder builder) { 68 project = Preconditions.checkNotNull(builder.getProject()); 69 location = Preconditions.checkNotNull(builder.getLocation()); 70 collection = Preconditions.checkNotNull(builder.getCollection()); 71 dataStore = Preconditions.checkNotNull(builder.getDataStore()); 72 branch = Preconditions.checkNotNull(builder.getBranch()); 73 pathTemplate = PROJECT_LOCATION_COLLECTION_DATA_STORE_BRANCH; 74 } 75 getProject()76 public String getProject() { 77 return project; 78 } 79 getLocation()80 public String getLocation() { 81 return location; 82 } 83 getDataStore()84 public String getDataStore() { 85 return dataStore; 86 } 87 getBranch()88 public String getBranch() { 89 return branch; 90 } 91 getCollection()92 public String getCollection() { 93 return collection; 94 } 95 newBuilder()96 public static Builder newBuilder() { 97 return new Builder(); 98 } 99 100 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") newProjectLocationDataStoreBranchBuilder()101 public static Builder newProjectLocationDataStoreBranchBuilder() { 102 return new Builder(); 103 } 104 105 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") 106 public static ProjectLocationCollectionDataStoreBranchBuilder newProjectLocationCollectionDataStoreBranchBuilder()107 newProjectLocationCollectionDataStoreBranchBuilder() { 108 return new ProjectLocationCollectionDataStoreBranchBuilder(); 109 } 110 toBuilder()111 public Builder toBuilder() { 112 return new Builder(this); 113 } 114 of(String project, String location, String dataStore, String branch)115 public static BranchName of(String project, String location, String dataStore, String branch) { 116 return newBuilder() 117 .setProject(project) 118 .setLocation(location) 119 .setDataStore(dataStore) 120 .setBranch(branch) 121 .build(); 122 } 123 124 @BetaApi("The static create methods are not stable yet and may be changed in the future.") ofProjectLocationDataStoreBranchName( String project, String location, String dataStore, String branch)125 public static BranchName ofProjectLocationDataStoreBranchName( 126 String project, String location, String dataStore, String branch) { 127 return newBuilder() 128 .setProject(project) 129 .setLocation(location) 130 .setDataStore(dataStore) 131 .setBranch(branch) 132 .build(); 133 } 134 135 @BetaApi("The static create methods are not stable yet and may be changed in the future.") ofProjectLocationCollectionDataStoreBranchName( String project, String location, String collection, String dataStore, String branch)136 public static BranchName ofProjectLocationCollectionDataStoreBranchName( 137 String project, String location, String collection, String dataStore, String branch) { 138 return newProjectLocationCollectionDataStoreBranchBuilder() 139 .setProject(project) 140 .setLocation(location) 141 .setCollection(collection) 142 .setDataStore(dataStore) 143 .setBranch(branch) 144 .build(); 145 } 146 format(String project, String location, String dataStore, String branch)147 public static String format(String project, String location, String dataStore, String branch) { 148 return newBuilder() 149 .setProject(project) 150 .setLocation(location) 151 .setDataStore(dataStore) 152 .setBranch(branch) 153 .build() 154 .toString(); 155 } 156 157 @BetaApi("The static format methods are not stable yet and may be changed in the future.") formatProjectLocationDataStoreBranchName( String project, String location, String dataStore, String branch)158 public static String formatProjectLocationDataStoreBranchName( 159 String project, String location, String dataStore, String branch) { 160 return newBuilder() 161 .setProject(project) 162 .setLocation(location) 163 .setDataStore(dataStore) 164 .setBranch(branch) 165 .build() 166 .toString(); 167 } 168 169 @BetaApi("The static format methods are not stable yet and may be changed in the future.") formatProjectLocationCollectionDataStoreBranchName( String project, String location, String collection, String dataStore, String branch)170 public static String formatProjectLocationCollectionDataStoreBranchName( 171 String project, String location, String collection, String dataStore, String branch) { 172 return newProjectLocationCollectionDataStoreBranchBuilder() 173 .setProject(project) 174 .setLocation(location) 175 .setCollection(collection) 176 .setDataStore(dataStore) 177 .setBranch(branch) 178 .build() 179 .toString(); 180 } 181 parse(String formattedString)182 public static BranchName parse(String formattedString) { 183 if (formattedString.isEmpty()) { 184 return null; 185 } 186 if (PROJECT_LOCATION_DATA_STORE_BRANCH.matches(formattedString)) { 187 Map<String, String> matchMap = PROJECT_LOCATION_DATA_STORE_BRANCH.match(formattedString); 188 return ofProjectLocationDataStoreBranchName( 189 matchMap.get("project"), 190 matchMap.get("location"), 191 matchMap.get("data_store"), 192 matchMap.get("branch")); 193 } else if (PROJECT_LOCATION_COLLECTION_DATA_STORE_BRANCH.matches(formattedString)) { 194 Map<String, String> matchMap = 195 PROJECT_LOCATION_COLLECTION_DATA_STORE_BRANCH.match(formattedString); 196 return ofProjectLocationCollectionDataStoreBranchName( 197 matchMap.get("project"), 198 matchMap.get("location"), 199 matchMap.get("collection"), 200 matchMap.get("data_store"), 201 matchMap.get("branch")); 202 } 203 throw new ValidationException("BranchName.parse: formattedString not in valid format"); 204 } 205 parseList(List<String> formattedStrings)206 public static List<BranchName> parseList(List<String> formattedStrings) { 207 List<BranchName> list = new ArrayList<>(formattedStrings.size()); 208 for (String formattedString : formattedStrings) { 209 list.add(parse(formattedString)); 210 } 211 return list; 212 } 213 toStringList(List<BranchName> values)214 public static List<String> toStringList(List<BranchName> values) { 215 List<String> list = new ArrayList<>(values.size()); 216 for (BranchName value : values) { 217 if (value == null) { 218 list.add(""); 219 } else { 220 list.add(value.toString()); 221 } 222 } 223 return list; 224 } 225 isParsableFrom(String formattedString)226 public static boolean isParsableFrom(String formattedString) { 227 return PROJECT_LOCATION_DATA_STORE_BRANCH.matches(formattedString) 228 || PROJECT_LOCATION_COLLECTION_DATA_STORE_BRANCH.matches(formattedString); 229 } 230 231 @Override getFieldValuesMap()232 public Map<String, String> getFieldValuesMap() { 233 if (fieldValuesMap == null) { 234 synchronized (this) { 235 if (fieldValuesMap == null) { 236 ImmutableMap.Builder<String, String> fieldMapBuilder = ImmutableMap.builder(); 237 if (project != null) { 238 fieldMapBuilder.put("project", project); 239 } 240 if (location != null) { 241 fieldMapBuilder.put("location", location); 242 } 243 if (dataStore != null) { 244 fieldMapBuilder.put("data_store", dataStore); 245 } 246 if (branch != null) { 247 fieldMapBuilder.put("branch", branch); 248 } 249 if (collection != null) { 250 fieldMapBuilder.put("collection", collection); 251 } 252 fieldValuesMap = fieldMapBuilder.build(); 253 } 254 } 255 } 256 return fieldValuesMap; 257 } 258 getFieldValue(String fieldName)259 public String getFieldValue(String fieldName) { 260 return getFieldValuesMap().get(fieldName); 261 } 262 263 @Override toString()264 public String toString() { 265 return fixedValue != null ? fixedValue : pathTemplate.instantiate(getFieldValuesMap()); 266 } 267 268 @Override equals(Object o)269 public boolean equals(Object o) { 270 if (o == this) { 271 return true; 272 } 273 if (o != null || getClass() == o.getClass()) { 274 BranchName that = ((BranchName) o); 275 return Objects.equals(this.project, that.project) 276 && Objects.equals(this.location, that.location) 277 && Objects.equals(this.dataStore, that.dataStore) 278 && Objects.equals(this.branch, that.branch) 279 && Objects.equals(this.collection, that.collection); 280 } 281 return false; 282 } 283 284 @Override hashCode()285 public int hashCode() { 286 int h = 1; 287 h *= 1000003; 288 h ^= Objects.hashCode(fixedValue); 289 h *= 1000003; 290 h ^= Objects.hashCode(project); 291 h *= 1000003; 292 h ^= Objects.hashCode(location); 293 h *= 1000003; 294 h ^= Objects.hashCode(dataStore); 295 h *= 1000003; 296 h ^= Objects.hashCode(branch); 297 h *= 1000003; 298 h ^= Objects.hashCode(collection); 299 return h; 300 } 301 302 /** 303 * Builder for projects/{project}/locations/{location}/dataStores/{data_store}/branches/{branch}. 304 */ 305 public static class Builder { 306 private String project; 307 private String location; 308 private String dataStore; 309 private String branch; 310 Builder()311 protected Builder() {} 312 getProject()313 public String getProject() { 314 return project; 315 } 316 getLocation()317 public String getLocation() { 318 return location; 319 } 320 getDataStore()321 public String getDataStore() { 322 return dataStore; 323 } 324 getBranch()325 public String getBranch() { 326 return branch; 327 } 328 setProject(String project)329 public Builder setProject(String project) { 330 this.project = project; 331 return this; 332 } 333 setLocation(String location)334 public Builder setLocation(String location) { 335 this.location = location; 336 return this; 337 } 338 setDataStore(String dataStore)339 public Builder setDataStore(String dataStore) { 340 this.dataStore = dataStore; 341 return this; 342 } 343 setBranch(String branch)344 public Builder setBranch(String branch) { 345 this.branch = branch; 346 return this; 347 } 348 Builder(BranchName branchName)349 private Builder(BranchName branchName) { 350 Preconditions.checkArgument( 351 Objects.equals(branchName.pathTemplate, PROJECT_LOCATION_DATA_STORE_BRANCH), 352 "toBuilder is only supported when BranchName has the pattern of projects/{project}/locations/{location}/dataStores/{data_store}/branches/{branch}"); 353 this.project = branchName.project; 354 this.location = branchName.location; 355 this.dataStore = branchName.dataStore; 356 this.branch = branchName.branch; 357 } 358 build()359 public BranchName build() { 360 return new BranchName(this); 361 } 362 } 363 364 /** 365 * Builder for 366 * projects/{project}/locations/{location}/collections/{collection}/dataStores/{data_store}/branches/{branch}. 367 */ 368 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") 369 public static class ProjectLocationCollectionDataStoreBranchBuilder { 370 private String project; 371 private String location; 372 private String collection; 373 private String dataStore; 374 private String branch; 375 ProjectLocationCollectionDataStoreBranchBuilder()376 protected ProjectLocationCollectionDataStoreBranchBuilder() {} 377 getProject()378 public String getProject() { 379 return project; 380 } 381 getLocation()382 public String getLocation() { 383 return location; 384 } 385 getCollection()386 public String getCollection() { 387 return collection; 388 } 389 getDataStore()390 public String getDataStore() { 391 return dataStore; 392 } 393 getBranch()394 public String getBranch() { 395 return branch; 396 } 397 setProject(String project)398 public ProjectLocationCollectionDataStoreBranchBuilder setProject(String project) { 399 this.project = project; 400 return this; 401 } 402 setLocation(String location)403 public ProjectLocationCollectionDataStoreBranchBuilder setLocation(String location) { 404 this.location = location; 405 return this; 406 } 407 setCollection(String collection)408 public ProjectLocationCollectionDataStoreBranchBuilder setCollection(String collection) { 409 this.collection = collection; 410 return this; 411 } 412 setDataStore(String dataStore)413 public ProjectLocationCollectionDataStoreBranchBuilder setDataStore(String dataStore) { 414 this.dataStore = dataStore; 415 return this; 416 } 417 setBranch(String branch)418 public ProjectLocationCollectionDataStoreBranchBuilder setBranch(String branch) { 419 this.branch = branch; 420 return this; 421 } 422 build()423 public BranchName build() { 424 return new BranchName(this); 425 } 426 } 427 } 428