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