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