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