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 BranchName implements ResourceName { 32 private static final PathTemplate PROJECT_LOCATION_CATALOG_BRANCH = 33 PathTemplate.createWithoutUrlEncoding( 34 "projects/{project}/locations/{location}/catalogs/{catalog}/branches/{branch}"); 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 41 @Deprecated BranchName()42 protected BranchName() { 43 project = null; 44 location = null; 45 catalog = null; 46 branch = null; 47 } 48 BranchName(Builder builder)49 private BranchName(Builder builder) { 50 project = Preconditions.checkNotNull(builder.getProject()); 51 location = Preconditions.checkNotNull(builder.getLocation()); 52 catalog = Preconditions.checkNotNull(builder.getCatalog()); 53 branch = Preconditions.checkNotNull(builder.getBranch()); 54 } 55 getProject()56 public String getProject() { 57 return project; 58 } 59 getLocation()60 public String getLocation() { 61 return location; 62 } 63 getCatalog()64 public String getCatalog() { 65 return catalog; 66 } 67 getBranch()68 public String getBranch() { 69 return branch; 70 } 71 newBuilder()72 public static Builder newBuilder() { 73 return new Builder(); 74 } 75 toBuilder()76 public Builder toBuilder() { 77 return new Builder(this); 78 } 79 of(String project, String location, String catalog, String branch)80 public static BranchName of(String project, String location, String catalog, String branch) { 81 return newBuilder() 82 .setProject(project) 83 .setLocation(location) 84 .setCatalog(catalog) 85 .setBranch(branch) 86 .build(); 87 } 88 format(String project, String location, String catalog, String branch)89 public static String format(String project, String location, String catalog, String branch) { 90 return newBuilder() 91 .setProject(project) 92 .setLocation(location) 93 .setCatalog(catalog) 94 .setBranch(branch) 95 .build() 96 .toString(); 97 } 98 parse(String formattedString)99 public static BranchName parse(String formattedString) { 100 if (formattedString.isEmpty()) { 101 return null; 102 } 103 Map<String, String> matchMap = 104 PROJECT_LOCATION_CATALOG_BRANCH.validatedMatch( 105 formattedString, "BranchName.parse: formattedString not in valid format"); 106 return of( 107 matchMap.get("project"), 108 matchMap.get("location"), 109 matchMap.get("catalog"), 110 matchMap.get("branch")); 111 } 112 parseList(List<String> formattedStrings)113 public static List<BranchName> parseList(List<String> formattedStrings) { 114 List<BranchName> list = new ArrayList<>(formattedStrings.size()); 115 for (String formattedString : formattedStrings) { 116 list.add(parse(formattedString)); 117 } 118 return list; 119 } 120 toStringList(List<BranchName> values)121 public static List<String> toStringList(List<BranchName> values) { 122 List<String> list = new ArrayList<>(values.size()); 123 for (BranchName value : values) { 124 if (value == null) { 125 list.add(""); 126 } else { 127 list.add(value.toString()); 128 } 129 } 130 return list; 131 } 132 isParsableFrom(String formattedString)133 public static boolean isParsableFrom(String formattedString) { 134 return PROJECT_LOCATION_CATALOG_BRANCH.matches(formattedString); 135 } 136 137 @Override getFieldValuesMap()138 public Map<String, String> getFieldValuesMap() { 139 if (fieldValuesMap == null) { 140 synchronized (this) { 141 if (fieldValuesMap == null) { 142 ImmutableMap.Builder<String, String> fieldMapBuilder = ImmutableMap.builder(); 143 if (project != null) { 144 fieldMapBuilder.put("project", project); 145 } 146 if (location != null) { 147 fieldMapBuilder.put("location", location); 148 } 149 if (catalog != null) { 150 fieldMapBuilder.put("catalog", catalog); 151 } 152 if (branch != null) { 153 fieldMapBuilder.put("branch", branch); 154 } 155 fieldValuesMap = fieldMapBuilder.build(); 156 } 157 } 158 } 159 return fieldValuesMap; 160 } 161 getFieldValue(String fieldName)162 public String getFieldValue(String fieldName) { 163 return getFieldValuesMap().get(fieldName); 164 } 165 166 @Override toString()167 public String toString() { 168 return PROJECT_LOCATION_CATALOG_BRANCH.instantiate( 169 "project", project, "location", location, "catalog", catalog, "branch", branch); 170 } 171 172 @Override equals(Object o)173 public boolean equals(Object o) { 174 if (o == this) { 175 return true; 176 } 177 if (o != null || getClass() == o.getClass()) { 178 BranchName that = ((BranchName) o); 179 return Objects.equals(this.project, that.project) 180 && Objects.equals(this.location, that.location) 181 && Objects.equals(this.catalog, that.catalog) 182 && Objects.equals(this.branch, that.branch); 183 } 184 return false; 185 } 186 187 @Override hashCode()188 public int hashCode() { 189 int h = 1; 190 h *= 1000003; 191 h ^= Objects.hashCode(project); 192 h *= 1000003; 193 h ^= Objects.hashCode(location); 194 h *= 1000003; 195 h ^= Objects.hashCode(catalog); 196 h *= 1000003; 197 h ^= Objects.hashCode(branch); 198 return h; 199 } 200 201 /** Builder for projects/{project}/locations/{location}/catalogs/{catalog}/branches/{branch}. */ 202 public static class Builder { 203 private String project; 204 private String location; 205 private String catalog; 206 private String branch; 207 Builder()208 protected Builder() {} 209 getProject()210 public String getProject() { 211 return project; 212 } 213 getLocation()214 public String getLocation() { 215 return location; 216 } 217 getCatalog()218 public String getCatalog() { 219 return catalog; 220 } 221 getBranch()222 public String getBranch() { 223 return branch; 224 } 225 setProject(String project)226 public Builder setProject(String project) { 227 this.project = project; 228 return this; 229 } 230 setLocation(String location)231 public Builder setLocation(String location) { 232 this.location = location; 233 return this; 234 } 235 setCatalog(String catalog)236 public Builder setCatalog(String catalog) { 237 this.catalog = catalog; 238 return this; 239 } 240 setBranch(String branch)241 public Builder setBranch(String branch) { 242 this.branch = branch; 243 return this; 244 } 245 Builder(BranchName branchName)246 private Builder(BranchName branchName) { 247 this.project = branchName.project; 248 this.location = branchName.location; 249 this.catalog = branchName.catalog; 250 this.branch = branchName.branch; 251 } 252 build()253 public BranchName build() { 254 return new BranchName(this); 255 } 256 } 257 } 258