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