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