• 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.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 DlpJobName implements ResourceName {
34   private static final PathTemplate PROJECT_DLP_JOB =
35       PathTemplate.createWithoutUrlEncoding("projects/{project}/dlpJobs/{dlp_job}");
36   private static final PathTemplate PROJECT_LOCATION_DLP_JOB =
37       PathTemplate.createWithoutUrlEncoding(
38           "projects/{project}/locations/{location}/dlpJobs/{dlp_job}");
39   private volatile Map<String, String> fieldValuesMap;
40   private PathTemplate pathTemplate;
41   private String fixedValue;
42   private final String project;
43   private final String dlpJob;
44   private final String location;
45 
46   @Deprecated
DlpJobName()47   protected DlpJobName() {
48     project = null;
49     dlpJob = null;
50     location = null;
51   }
52 
DlpJobName(Builder builder)53   private DlpJobName(Builder builder) {
54     project = Preconditions.checkNotNull(builder.getProject());
55     dlpJob = Preconditions.checkNotNull(builder.getDlpJob());
56     location = null;
57     pathTemplate = PROJECT_DLP_JOB;
58   }
59 
DlpJobName(ProjectLocationDlpJobBuilder builder)60   private DlpJobName(ProjectLocationDlpJobBuilder builder) {
61     project = Preconditions.checkNotNull(builder.getProject());
62     location = Preconditions.checkNotNull(builder.getLocation());
63     dlpJob = Preconditions.checkNotNull(builder.getDlpJob());
64     pathTemplate = PROJECT_LOCATION_DLP_JOB;
65   }
66 
getProject()67   public String getProject() {
68     return project;
69   }
70 
getDlpJob()71   public String getDlpJob() {
72     return dlpJob;
73   }
74 
getLocation()75   public String getLocation() {
76     return location;
77   }
78 
newBuilder()79   public static Builder newBuilder() {
80     return new Builder();
81   }
82 
83   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
newProjectDlpJobBuilder()84   public static Builder newProjectDlpJobBuilder() {
85     return new Builder();
86   }
87 
88   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
newProjectLocationDlpJobBuilder()89   public static ProjectLocationDlpJobBuilder newProjectLocationDlpJobBuilder() {
90     return new ProjectLocationDlpJobBuilder();
91   }
92 
toBuilder()93   public Builder toBuilder() {
94     return new Builder(this);
95   }
96 
of(String project, String dlpJob)97   public static DlpJobName of(String project, String dlpJob) {
98     return newBuilder().setProject(project).setDlpJob(dlpJob).build();
99   }
100 
101   @BetaApi("The static create methods are not stable yet and may be changed in the future.")
ofProjectDlpJobName(String project, String dlpJob)102   public static DlpJobName ofProjectDlpJobName(String project, String dlpJob) {
103     return newBuilder().setProject(project).setDlpJob(dlpJob).build();
104   }
105 
106   @BetaApi("The static create methods are not stable yet and may be changed in the future.")
ofProjectLocationDlpJobName( String project, String location, String dlpJob)107   public static DlpJobName ofProjectLocationDlpJobName(
108       String project, String location, String dlpJob) {
109     return newProjectLocationDlpJobBuilder()
110         .setProject(project)
111         .setLocation(location)
112         .setDlpJob(dlpJob)
113         .build();
114   }
115 
format(String project, String dlpJob)116   public static String format(String project, String dlpJob) {
117     return newBuilder().setProject(project).setDlpJob(dlpJob).build().toString();
118   }
119 
120   @BetaApi("The static format methods are not stable yet and may be changed in the future.")
formatProjectDlpJobName(String project, String dlpJob)121   public static String formatProjectDlpJobName(String project, String dlpJob) {
122     return newBuilder().setProject(project).setDlpJob(dlpJob).build().toString();
123   }
124 
125   @BetaApi("The static format methods are not stable yet and may be changed in the future.")
formatProjectLocationDlpJobName( String project, String location, String dlpJob)126   public static String formatProjectLocationDlpJobName(
127       String project, String location, String dlpJob) {
128     return newProjectLocationDlpJobBuilder()
129         .setProject(project)
130         .setLocation(location)
131         .setDlpJob(dlpJob)
132         .build()
133         .toString();
134   }
135 
parse(String formattedString)136   public static DlpJobName parse(String formattedString) {
137     if (formattedString.isEmpty()) {
138       return null;
139     }
140     if (PROJECT_DLP_JOB.matches(formattedString)) {
141       Map<String, String> matchMap = PROJECT_DLP_JOB.match(formattedString);
142       return ofProjectDlpJobName(matchMap.get("project"), matchMap.get("dlp_job"));
143     } else if (PROJECT_LOCATION_DLP_JOB.matches(formattedString)) {
144       Map<String, String> matchMap = PROJECT_LOCATION_DLP_JOB.match(formattedString);
145       return ofProjectLocationDlpJobName(
146           matchMap.get("project"), matchMap.get("location"), matchMap.get("dlp_job"));
147     }
148     throw new ValidationException("DlpJobName.parse: formattedString not in valid format");
149   }
150 
parseList(List<String> formattedStrings)151   public static List<DlpJobName> parseList(List<String> formattedStrings) {
152     List<DlpJobName> list = new ArrayList<>(formattedStrings.size());
153     for (String formattedString : formattedStrings) {
154       list.add(parse(formattedString));
155     }
156     return list;
157   }
158 
toStringList(List<DlpJobName> values)159   public static List<String> toStringList(List<DlpJobName> values) {
160     List<String> list = new ArrayList<>(values.size());
161     for (DlpJobName value : values) {
162       if (value == null) {
163         list.add("");
164       } else {
165         list.add(value.toString());
166       }
167     }
168     return list;
169   }
170 
isParsableFrom(String formattedString)171   public static boolean isParsableFrom(String formattedString) {
172     return PROJECT_DLP_JOB.matches(formattedString)
173         || PROJECT_LOCATION_DLP_JOB.matches(formattedString);
174   }
175 
176   @Override
getFieldValuesMap()177   public Map<String, String> getFieldValuesMap() {
178     if (fieldValuesMap == null) {
179       synchronized (this) {
180         if (fieldValuesMap == null) {
181           ImmutableMap.Builder<String, String> fieldMapBuilder = ImmutableMap.builder();
182           if (project != null) {
183             fieldMapBuilder.put("project", project);
184           }
185           if (dlpJob != null) {
186             fieldMapBuilder.put("dlp_job", dlpJob);
187           }
188           if (location != null) {
189             fieldMapBuilder.put("location", location);
190           }
191           fieldValuesMap = fieldMapBuilder.build();
192         }
193       }
194     }
195     return fieldValuesMap;
196   }
197 
getFieldValue(String fieldName)198   public String getFieldValue(String fieldName) {
199     return getFieldValuesMap().get(fieldName);
200   }
201 
202   @Override
toString()203   public String toString() {
204     return fixedValue != null ? fixedValue : pathTemplate.instantiate(getFieldValuesMap());
205   }
206 
207   @Override
equals(Object o)208   public boolean equals(Object o) {
209     if (o == this) {
210       return true;
211     }
212     if (o != null || getClass() == o.getClass()) {
213       DlpJobName that = ((DlpJobName) o);
214       return Objects.equals(this.project, that.project)
215           && Objects.equals(this.dlpJob, that.dlpJob)
216           && Objects.equals(this.location, that.location);
217     }
218     return false;
219   }
220 
221   @Override
hashCode()222   public int hashCode() {
223     int h = 1;
224     h *= 1000003;
225     h ^= Objects.hashCode(fixedValue);
226     h *= 1000003;
227     h ^= Objects.hashCode(project);
228     h *= 1000003;
229     h ^= Objects.hashCode(dlpJob);
230     h *= 1000003;
231     h ^= Objects.hashCode(location);
232     return h;
233   }
234 
235   /** Builder for projects/{project}/dlpJobs/{dlp_job}. */
236   public static class Builder {
237     private String project;
238     private String dlpJob;
239 
Builder()240     protected Builder() {}
241 
getProject()242     public String getProject() {
243       return project;
244     }
245 
getDlpJob()246     public String getDlpJob() {
247       return dlpJob;
248     }
249 
setProject(String project)250     public Builder setProject(String project) {
251       this.project = project;
252       return this;
253     }
254 
setDlpJob(String dlpJob)255     public Builder setDlpJob(String dlpJob) {
256       this.dlpJob = dlpJob;
257       return this;
258     }
259 
Builder(DlpJobName dlpJobName)260     private Builder(DlpJobName dlpJobName) {
261       Preconditions.checkArgument(
262           Objects.equals(dlpJobName.pathTemplate, PROJECT_DLP_JOB),
263           "toBuilder is only supported when DlpJobName has the pattern of projects/{project}/dlpJobs/{dlp_job}");
264       this.project = dlpJobName.project;
265       this.dlpJob = dlpJobName.dlpJob;
266     }
267 
build()268     public DlpJobName build() {
269       return new DlpJobName(this);
270     }
271   }
272 
273   /** Builder for projects/{project}/locations/{location}/dlpJobs/{dlp_job}. */
274   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
275   public static class ProjectLocationDlpJobBuilder {
276     private String project;
277     private String location;
278     private String dlpJob;
279 
ProjectLocationDlpJobBuilder()280     protected ProjectLocationDlpJobBuilder() {}
281 
getProject()282     public String getProject() {
283       return project;
284     }
285 
getLocation()286     public String getLocation() {
287       return location;
288     }
289 
getDlpJob()290     public String getDlpJob() {
291       return dlpJob;
292     }
293 
setProject(String project)294     public ProjectLocationDlpJobBuilder setProject(String project) {
295       this.project = project;
296       return this;
297     }
298 
setLocation(String location)299     public ProjectLocationDlpJobBuilder setLocation(String location) {
300       this.location = location;
301       return this;
302     }
303 
setDlpJob(String dlpJob)304     public ProjectLocationDlpJobBuilder setDlpJob(String dlpJob) {
305       this.dlpJob = dlpJob;
306       return this;
307     }
308 
build()309     public DlpJobName build() {
310       return new DlpJobName(this);
311     }
312   }
313 }
314