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