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