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