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.privacy.dlp.v2; 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.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 InspectTemplateName implements ResourceName { 32 private static final PathTemplate ORGANIZATION_INSPECT_TEMPLATE = 33 PathTemplate.createWithoutUrlEncoding( 34 "organizations/{organization}/inspectTemplates/{inspect_template}"); 35 private static final PathTemplate PROJECT_INSPECT_TEMPLATE = 36 PathTemplate.createWithoutUrlEncoding( 37 "projects/{project}/inspectTemplates/{inspect_template}"); 38 private static final PathTemplate ORGANIZATION_LOCATION_INSPECT_TEMPLATE = 39 PathTemplate.createWithoutUrlEncoding( 40 "organizations/{organization}/locations/{location}/inspectTemplates/{inspect_template}"); 41 private static final PathTemplate PROJECT_LOCATION_INSPECT_TEMPLATE = 42 PathTemplate.createWithoutUrlEncoding( 43 "projects/{project}/locations/{location}/inspectTemplates/{inspect_template}"); 44 private volatile Map<String, String> fieldValuesMap; 45 private PathTemplate pathTemplate; 46 private String fixedValue; 47 private final String organization; 48 private final String inspectTemplate; 49 private final String project; 50 private final String location; 51 52 @Deprecated InspectTemplateName()53 protected InspectTemplateName() { 54 organization = null; 55 inspectTemplate = null; 56 project = null; 57 location = null; 58 } 59 InspectTemplateName(Builder builder)60 private InspectTemplateName(Builder builder) { 61 organization = Preconditions.checkNotNull(builder.getOrganization()); 62 inspectTemplate = Preconditions.checkNotNull(builder.getInspectTemplate()); 63 project = null; 64 location = null; 65 pathTemplate = ORGANIZATION_INSPECT_TEMPLATE; 66 } 67 InspectTemplateName(ProjectInspectTemplateBuilder builder)68 private InspectTemplateName(ProjectInspectTemplateBuilder builder) { 69 project = Preconditions.checkNotNull(builder.getProject()); 70 inspectTemplate = Preconditions.checkNotNull(builder.getInspectTemplate()); 71 organization = null; 72 location = null; 73 pathTemplate = PROJECT_INSPECT_TEMPLATE; 74 } 75 InspectTemplateName(OrganizationLocationInspectTemplateBuilder builder)76 private InspectTemplateName(OrganizationLocationInspectTemplateBuilder builder) { 77 organization = Preconditions.checkNotNull(builder.getOrganization()); 78 location = Preconditions.checkNotNull(builder.getLocation()); 79 inspectTemplate = Preconditions.checkNotNull(builder.getInspectTemplate()); 80 project = null; 81 pathTemplate = ORGANIZATION_LOCATION_INSPECT_TEMPLATE; 82 } 83 InspectTemplateName(ProjectLocationInspectTemplateBuilder builder)84 private InspectTemplateName(ProjectLocationInspectTemplateBuilder builder) { 85 project = Preconditions.checkNotNull(builder.getProject()); 86 location = Preconditions.checkNotNull(builder.getLocation()); 87 inspectTemplate = Preconditions.checkNotNull(builder.getInspectTemplate()); 88 organization = null; 89 pathTemplate = PROJECT_LOCATION_INSPECT_TEMPLATE; 90 } 91 getOrganization()92 public String getOrganization() { 93 return organization; 94 } 95 getInspectTemplate()96 public String getInspectTemplate() { 97 return inspectTemplate; 98 } 99 getProject()100 public String getProject() { 101 return project; 102 } 103 getLocation()104 public String getLocation() { 105 return location; 106 } 107 newBuilder()108 public static Builder newBuilder() { 109 return new Builder(); 110 } 111 112 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") newOrganizationInspectTemplateBuilder()113 public static Builder newOrganizationInspectTemplateBuilder() { 114 return new Builder(); 115 } 116 117 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") newProjectInspectTemplateBuilder()118 public static ProjectInspectTemplateBuilder newProjectInspectTemplateBuilder() { 119 return new ProjectInspectTemplateBuilder(); 120 } 121 122 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") 123 public static OrganizationLocationInspectTemplateBuilder newOrganizationLocationInspectTemplateBuilder()124 newOrganizationLocationInspectTemplateBuilder() { 125 return new OrganizationLocationInspectTemplateBuilder(); 126 } 127 128 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") newProjectLocationInspectTemplateBuilder()129 public static ProjectLocationInspectTemplateBuilder newProjectLocationInspectTemplateBuilder() { 130 return new ProjectLocationInspectTemplateBuilder(); 131 } 132 toBuilder()133 public Builder toBuilder() { 134 return new Builder(this); 135 } 136 of(String organization, String inspectTemplate)137 public static InspectTemplateName of(String organization, String inspectTemplate) { 138 return newBuilder().setOrganization(organization).setInspectTemplate(inspectTemplate).build(); 139 } 140 141 @BetaApi("The static create methods are not stable yet and may be changed in the future.") ofOrganizationInspectTemplateName( String organization, String inspectTemplate)142 public static InspectTemplateName ofOrganizationInspectTemplateName( 143 String organization, String inspectTemplate) { 144 return newBuilder().setOrganization(organization).setInspectTemplate(inspectTemplate).build(); 145 } 146 147 @BetaApi("The static create methods are not stable yet and may be changed in the future.") ofProjectInspectTemplateName( String project, String inspectTemplate)148 public static InspectTemplateName ofProjectInspectTemplateName( 149 String project, String inspectTemplate) { 150 return newProjectInspectTemplateBuilder() 151 .setProject(project) 152 .setInspectTemplate(inspectTemplate) 153 .build(); 154 } 155 156 @BetaApi("The static create methods are not stable yet and may be changed in the future.") ofOrganizationLocationInspectTemplateName( String organization, String location, String inspectTemplate)157 public static InspectTemplateName ofOrganizationLocationInspectTemplateName( 158 String organization, String location, String inspectTemplate) { 159 return newOrganizationLocationInspectTemplateBuilder() 160 .setOrganization(organization) 161 .setLocation(location) 162 .setInspectTemplate(inspectTemplate) 163 .build(); 164 } 165 166 @BetaApi("The static create methods are not stable yet and may be changed in the future.") ofProjectLocationInspectTemplateName( String project, String location, String inspectTemplate)167 public static InspectTemplateName ofProjectLocationInspectTemplateName( 168 String project, String location, String inspectTemplate) { 169 return newProjectLocationInspectTemplateBuilder() 170 .setProject(project) 171 .setLocation(location) 172 .setInspectTemplate(inspectTemplate) 173 .build(); 174 } 175 format(String organization, String inspectTemplate)176 public static String format(String organization, String inspectTemplate) { 177 return newBuilder() 178 .setOrganization(organization) 179 .setInspectTemplate(inspectTemplate) 180 .build() 181 .toString(); 182 } 183 184 @BetaApi("The static format methods are not stable yet and may be changed in the future.") formatOrganizationInspectTemplateName( String organization, String inspectTemplate)185 public static String formatOrganizationInspectTemplateName( 186 String organization, String inspectTemplate) { 187 return newBuilder() 188 .setOrganization(organization) 189 .setInspectTemplate(inspectTemplate) 190 .build() 191 .toString(); 192 } 193 194 @BetaApi("The static format methods are not stable yet and may be changed in the future.") formatProjectInspectTemplateName(String project, String inspectTemplate)195 public static String formatProjectInspectTemplateName(String project, String inspectTemplate) { 196 return newProjectInspectTemplateBuilder() 197 .setProject(project) 198 .setInspectTemplate(inspectTemplate) 199 .build() 200 .toString(); 201 } 202 203 @BetaApi("The static format methods are not stable yet and may be changed in the future.") formatOrganizationLocationInspectTemplateName( String organization, String location, String inspectTemplate)204 public static String formatOrganizationLocationInspectTemplateName( 205 String organization, String location, String inspectTemplate) { 206 return newOrganizationLocationInspectTemplateBuilder() 207 .setOrganization(organization) 208 .setLocation(location) 209 .setInspectTemplate(inspectTemplate) 210 .build() 211 .toString(); 212 } 213 214 @BetaApi("The static format methods are not stable yet and may be changed in the future.") formatProjectLocationInspectTemplateName( String project, String location, String inspectTemplate)215 public static String formatProjectLocationInspectTemplateName( 216 String project, String location, String inspectTemplate) { 217 return newProjectLocationInspectTemplateBuilder() 218 .setProject(project) 219 .setLocation(location) 220 .setInspectTemplate(inspectTemplate) 221 .build() 222 .toString(); 223 } 224 parse(String formattedString)225 public static InspectTemplateName parse(String formattedString) { 226 if (formattedString.isEmpty()) { 227 return null; 228 } 229 if (ORGANIZATION_INSPECT_TEMPLATE.matches(formattedString)) { 230 Map<String, String> matchMap = ORGANIZATION_INSPECT_TEMPLATE.match(formattedString); 231 return ofOrganizationInspectTemplateName( 232 matchMap.get("organization"), matchMap.get("inspect_template")); 233 } else if (PROJECT_INSPECT_TEMPLATE.matches(formattedString)) { 234 Map<String, String> matchMap = PROJECT_INSPECT_TEMPLATE.match(formattedString); 235 return ofProjectInspectTemplateName( 236 matchMap.get("project"), matchMap.get("inspect_template")); 237 } else if (ORGANIZATION_LOCATION_INSPECT_TEMPLATE.matches(formattedString)) { 238 Map<String, String> matchMap = ORGANIZATION_LOCATION_INSPECT_TEMPLATE.match(formattedString); 239 return ofOrganizationLocationInspectTemplateName( 240 matchMap.get("organization"), matchMap.get("location"), matchMap.get("inspect_template")); 241 } else if (PROJECT_LOCATION_INSPECT_TEMPLATE.matches(formattedString)) { 242 Map<String, String> matchMap = PROJECT_LOCATION_INSPECT_TEMPLATE.match(formattedString); 243 return ofProjectLocationInspectTemplateName( 244 matchMap.get("project"), matchMap.get("location"), matchMap.get("inspect_template")); 245 } 246 throw new ValidationException("InspectTemplateName.parse: formattedString not in valid format"); 247 } 248 isParsableFrom(String formattedString)249 public static boolean isParsableFrom(String formattedString) { 250 return ORGANIZATION_INSPECT_TEMPLATE.matches(formattedString) 251 || PROJECT_INSPECT_TEMPLATE.matches(formattedString) 252 || ORGANIZATION_LOCATION_INSPECT_TEMPLATE.matches(formattedString) 253 || PROJECT_LOCATION_INSPECT_TEMPLATE.matches(formattedString); 254 } 255 256 @Override getFieldValuesMap()257 public Map<String, String> getFieldValuesMap() { 258 if (fieldValuesMap == null) { 259 synchronized (this) { 260 if (fieldValuesMap == null) { 261 ImmutableMap.Builder<String, String> fieldMapBuilder = ImmutableMap.builder(); 262 if (organization != null) { 263 fieldMapBuilder.put("organization", organization); 264 } 265 if (inspectTemplate != null) { 266 fieldMapBuilder.put("inspect_template", inspectTemplate); 267 } 268 if (project != null) { 269 fieldMapBuilder.put("project", project); 270 } 271 if (location != null) { 272 fieldMapBuilder.put("location", location); 273 } 274 fieldValuesMap = fieldMapBuilder.build(); 275 } 276 } 277 } 278 return fieldValuesMap; 279 } 280 getFieldValue(String fieldName)281 public String getFieldValue(String fieldName) { 282 return getFieldValuesMap().get(fieldName); 283 } 284 285 @Override toString()286 public String toString() { 287 return fixedValue != null ? fixedValue : pathTemplate.instantiate(getFieldValuesMap()); 288 } 289 290 @Override equals(Object o)291 public boolean equals(Object o) { 292 if (o == this) { 293 return true; 294 } 295 if (o != null || getClass() == o.getClass()) { 296 InspectTemplateName that = ((InspectTemplateName) o); 297 return Objects.equals(this.organization, that.organization) 298 && Objects.equals(this.inspectTemplate, that.inspectTemplate) 299 && Objects.equals(this.project, that.project) 300 && Objects.equals(this.location, that.location); 301 } 302 return false; 303 } 304 305 @Override hashCode()306 public int hashCode() { 307 int h = 1; 308 h *= 1000003; 309 h ^= Objects.hashCode(fixedValue); 310 h *= 1000003; 311 h ^= Objects.hashCode(organization); 312 h *= 1000003; 313 h ^= Objects.hashCode(inspectTemplate); 314 h *= 1000003; 315 h ^= Objects.hashCode(project); 316 h *= 1000003; 317 h ^= Objects.hashCode(location); 318 return h; 319 } 320 321 /** Builder for organizations/{organization}/inspectTemplates/{inspect_template}. */ 322 public static class Builder { 323 private String organization; 324 private String inspectTemplate; 325 Builder()326 protected Builder() {} 327 getOrganization()328 public String getOrganization() { 329 return organization; 330 } 331 getInspectTemplate()332 public String getInspectTemplate() { 333 return inspectTemplate; 334 } 335 setOrganization(String organization)336 public Builder setOrganization(String organization) { 337 this.organization = organization; 338 return this; 339 } 340 setInspectTemplate(String inspectTemplate)341 public Builder setInspectTemplate(String inspectTemplate) { 342 this.inspectTemplate = inspectTemplate; 343 return this; 344 } 345 Builder(InspectTemplateName inspectTemplateName)346 private Builder(InspectTemplateName inspectTemplateName) { 347 Preconditions.checkArgument( 348 Objects.equals(inspectTemplateName.pathTemplate, ORGANIZATION_INSPECT_TEMPLATE), 349 "toBuilder is only supported when InspectTemplateName has the pattern of organizations/{organization}/inspectTemplates/{inspect_template}"); 350 this.organization = inspectTemplateName.organization; 351 this.inspectTemplate = inspectTemplateName.inspectTemplate; 352 } 353 build()354 public InspectTemplateName build() { 355 return new InspectTemplateName(this); 356 } 357 } 358 359 /** Builder for projects/{project}/inspectTemplates/{inspect_template}. */ 360 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") 361 public static class ProjectInspectTemplateBuilder { 362 private String project; 363 private String inspectTemplate; 364 ProjectInspectTemplateBuilder()365 protected ProjectInspectTemplateBuilder() {} 366 getProject()367 public String getProject() { 368 return project; 369 } 370 getInspectTemplate()371 public String getInspectTemplate() { 372 return inspectTemplate; 373 } 374 setProject(String project)375 public ProjectInspectTemplateBuilder setProject(String project) { 376 this.project = project; 377 return this; 378 } 379 setInspectTemplate(String inspectTemplate)380 public ProjectInspectTemplateBuilder setInspectTemplate(String inspectTemplate) { 381 this.inspectTemplate = inspectTemplate; 382 return this; 383 } 384 build()385 public InspectTemplateName build() { 386 return new InspectTemplateName(this); 387 } 388 } 389 390 /** 391 * Builder for 392 * organizations/{organization}/locations/{location}/inspectTemplates/{inspect_template}. 393 */ 394 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") 395 public static class OrganizationLocationInspectTemplateBuilder { 396 private String organization; 397 private String location; 398 private String inspectTemplate; 399 OrganizationLocationInspectTemplateBuilder()400 protected OrganizationLocationInspectTemplateBuilder() {} 401 getOrganization()402 public String getOrganization() { 403 return organization; 404 } 405 getLocation()406 public String getLocation() { 407 return location; 408 } 409 getInspectTemplate()410 public String getInspectTemplate() { 411 return inspectTemplate; 412 } 413 setOrganization(String organization)414 public OrganizationLocationInspectTemplateBuilder setOrganization(String organization) { 415 this.organization = organization; 416 return this; 417 } 418 setLocation(String location)419 public OrganizationLocationInspectTemplateBuilder setLocation(String location) { 420 this.location = location; 421 return this; 422 } 423 setInspectTemplate(String inspectTemplate)424 public OrganizationLocationInspectTemplateBuilder setInspectTemplate(String inspectTemplate) { 425 this.inspectTemplate = inspectTemplate; 426 return this; 427 } 428 build()429 public InspectTemplateName build() { 430 return new InspectTemplateName(this); 431 } 432 } 433 434 /** Builder for projects/{project}/locations/{location}/inspectTemplates/{inspect_template}. */ 435 @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.") 436 public static class ProjectLocationInspectTemplateBuilder { 437 private String project; 438 private String location; 439 private String inspectTemplate; 440 ProjectLocationInspectTemplateBuilder()441 protected ProjectLocationInspectTemplateBuilder() {} 442 getProject()443 public String getProject() { 444 return project; 445 } 446 getLocation()447 public String getLocation() { 448 return location; 449 } 450 getInspectTemplate()451 public String getInspectTemplate() { 452 return inspectTemplate; 453 } 454 setProject(String project)455 public ProjectLocationInspectTemplateBuilder setProject(String project) { 456 this.project = project; 457 return this; 458 } 459 setLocation(String location)460 public ProjectLocationInspectTemplateBuilder setLocation(String location) { 461 this.location = location; 462 return this; 463 } 464 setInspectTemplate(String inspectTemplate)465 public ProjectLocationInspectTemplateBuilder setInspectTemplate(String inspectTemplate) { 466 this.inspectTemplate = inspectTemplate; 467 return this; 468 } 469 build()470 public InspectTemplateName build() { 471 return new InspectTemplateName(this); 472 } 473 } 474 } 475