• 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 ContextName implements ResourceName {
34   private static final PathTemplate PROJECT_SESSION_CONTEXT =
35       PathTemplate.createWithoutUrlEncoding(
36           "projects/{project}/agent/sessions/{session}/contexts/{context}");
37   private static final PathTemplate PROJECT_ENVIRONMENT_USER_SESSION_CONTEXT =
38       PathTemplate.createWithoutUrlEncoding(
39           "projects/{project}/agent/environments/{environment}/users/{user}/sessions/{session}/contexts/{context}");
40   private static final PathTemplate PROJECT_LOCATION_SESSION_CONTEXT =
41       PathTemplate.createWithoutUrlEncoding(
42           "projects/{project}/locations/{location}/agent/sessions/{session}/contexts/{context}");
43   private static final PathTemplate PROJECT_LOCATION_ENVIRONMENT_USER_SESSION_CONTEXT =
44       PathTemplate.createWithoutUrlEncoding(
45           "projects/{project}/locations/{location}/agent/environments/{environment}/users/{user}/sessions/{session}/contexts/{context}");
46   private volatile Map<String, String> fieldValuesMap;
47   private PathTemplate pathTemplate;
48   private String fixedValue;
49   private final String project;
50   private final String session;
51   private final String context;
52   private final String environment;
53   private final String user;
54   private final String location;
55 
56   @Deprecated
ContextName()57   protected ContextName() {
58     project = null;
59     session = null;
60     context = null;
61     environment = null;
62     user = null;
63     location = null;
64   }
65 
ContextName(Builder builder)66   private ContextName(Builder builder) {
67     project = Preconditions.checkNotNull(builder.getProject());
68     session = Preconditions.checkNotNull(builder.getSession());
69     context = Preconditions.checkNotNull(builder.getContext());
70     environment = null;
71     user = null;
72     location = null;
73     pathTemplate = PROJECT_SESSION_CONTEXT;
74   }
75 
ContextName(ProjectEnvironmentUserSessionContextBuilder builder)76   private ContextName(ProjectEnvironmentUserSessionContextBuilder builder) {
77     project = Preconditions.checkNotNull(builder.getProject());
78     environment = Preconditions.checkNotNull(builder.getEnvironment());
79     user = Preconditions.checkNotNull(builder.getUser());
80     session = Preconditions.checkNotNull(builder.getSession());
81     context = Preconditions.checkNotNull(builder.getContext());
82     location = null;
83     pathTemplate = PROJECT_ENVIRONMENT_USER_SESSION_CONTEXT;
84   }
85 
ContextName(ProjectLocationSessionContextBuilder builder)86   private ContextName(ProjectLocationSessionContextBuilder builder) {
87     project = Preconditions.checkNotNull(builder.getProject());
88     location = Preconditions.checkNotNull(builder.getLocation());
89     session = Preconditions.checkNotNull(builder.getSession());
90     context = Preconditions.checkNotNull(builder.getContext());
91     environment = null;
92     user = null;
93     pathTemplate = PROJECT_LOCATION_SESSION_CONTEXT;
94   }
95 
ContextName(ProjectLocationEnvironmentUserSessionContextBuilder builder)96   private ContextName(ProjectLocationEnvironmentUserSessionContextBuilder builder) {
97     project = Preconditions.checkNotNull(builder.getProject());
98     location = Preconditions.checkNotNull(builder.getLocation());
99     environment = Preconditions.checkNotNull(builder.getEnvironment());
100     user = Preconditions.checkNotNull(builder.getUser());
101     session = Preconditions.checkNotNull(builder.getSession());
102     context = Preconditions.checkNotNull(builder.getContext());
103     pathTemplate = PROJECT_LOCATION_ENVIRONMENT_USER_SESSION_CONTEXT;
104   }
105 
getProject()106   public String getProject() {
107     return project;
108   }
109 
getSession()110   public String getSession() {
111     return session;
112   }
113 
getContext()114   public String getContext() {
115     return context;
116   }
117 
getEnvironment()118   public String getEnvironment() {
119     return environment;
120   }
121 
getUser()122   public String getUser() {
123     return user;
124   }
125 
getLocation()126   public String getLocation() {
127     return location;
128   }
129 
newBuilder()130   public static Builder newBuilder() {
131     return new Builder();
132   }
133 
134   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
newProjectSessionContextBuilder()135   public static Builder newProjectSessionContextBuilder() {
136     return new Builder();
137   }
138 
139   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
140   public static ProjectEnvironmentUserSessionContextBuilder
newProjectEnvironmentUserSessionContextBuilder()141       newProjectEnvironmentUserSessionContextBuilder() {
142     return new ProjectEnvironmentUserSessionContextBuilder();
143   }
144 
145   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
newProjectLocationSessionContextBuilder()146   public static ProjectLocationSessionContextBuilder newProjectLocationSessionContextBuilder() {
147     return new ProjectLocationSessionContextBuilder();
148   }
149 
150   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
151   public static ProjectLocationEnvironmentUserSessionContextBuilder
newProjectLocationEnvironmentUserSessionContextBuilder()152       newProjectLocationEnvironmentUserSessionContextBuilder() {
153     return new ProjectLocationEnvironmentUserSessionContextBuilder();
154   }
155 
toBuilder()156   public Builder toBuilder() {
157     return new Builder(this);
158   }
159 
of(String project, String session, String context)160   public static ContextName of(String project, String session, String context) {
161     return newBuilder().setProject(project).setSession(session).setContext(context).build();
162   }
163 
164   @BetaApi("The static create methods are not stable yet and may be changed in the future.")
ofProjectSessionContextName( String project, String session, String context)165   public static ContextName ofProjectSessionContextName(
166       String project, String session, String context) {
167     return newBuilder().setProject(project).setSession(session).setContext(context).build();
168   }
169 
170   @BetaApi("The static create methods are not stable yet and may be changed in the future.")
ofProjectEnvironmentUserSessionContextName( String project, String environment, String user, String session, String context)171   public static ContextName ofProjectEnvironmentUserSessionContextName(
172       String project, String environment, String user, String session, String context) {
173     return newProjectEnvironmentUserSessionContextBuilder()
174         .setProject(project)
175         .setEnvironment(environment)
176         .setUser(user)
177         .setSession(session)
178         .setContext(context)
179         .build();
180   }
181 
182   @BetaApi("The static create methods are not stable yet and may be changed in the future.")
ofProjectLocationSessionContextName( String project, String location, String session, String context)183   public static ContextName ofProjectLocationSessionContextName(
184       String project, String location, String session, String context) {
185     return newProjectLocationSessionContextBuilder()
186         .setProject(project)
187         .setLocation(location)
188         .setSession(session)
189         .setContext(context)
190         .build();
191   }
192 
193   @BetaApi("The static create methods are not stable yet and may be changed in the future.")
ofProjectLocationEnvironmentUserSessionContextName( String project, String location, String environment, String user, String session, String context)194   public static ContextName ofProjectLocationEnvironmentUserSessionContextName(
195       String project,
196       String location,
197       String environment,
198       String user,
199       String session,
200       String context) {
201     return newProjectLocationEnvironmentUserSessionContextBuilder()
202         .setProject(project)
203         .setLocation(location)
204         .setEnvironment(environment)
205         .setUser(user)
206         .setSession(session)
207         .setContext(context)
208         .build();
209   }
210 
format(String project, String session, String context)211   public static String format(String project, String session, String context) {
212     return newBuilder()
213         .setProject(project)
214         .setSession(session)
215         .setContext(context)
216         .build()
217         .toString();
218   }
219 
220   @BetaApi("The static format methods are not stable yet and may be changed in the future.")
formatProjectSessionContextName( String project, String session, String context)221   public static String formatProjectSessionContextName(
222       String project, String session, String context) {
223     return newBuilder()
224         .setProject(project)
225         .setSession(session)
226         .setContext(context)
227         .build()
228         .toString();
229   }
230 
231   @BetaApi("The static format methods are not stable yet and may be changed in the future.")
formatProjectEnvironmentUserSessionContextName( String project, String environment, String user, String session, String context)232   public static String formatProjectEnvironmentUserSessionContextName(
233       String project, String environment, String user, String session, String context) {
234     return newProjectEnvironmentUserSessionContextBuilder()
235         .setProject(project)
236         .setEnvironment(environment)
237         .setUser(user)
238         .setSession(session)
239         .setContext(context)
240         .build()
241         .toString();
242   }
243 
244   @BetaApi("The static format methods are not stable yet and may be changed in the future.")
formatProjectLocationSessionContextName( String project, String location, String session, String context)245   public static String formatProjectLocationSessionContextName(
246       String project, String location, String session, String context) {
247     return newProjectLocationSessionContextBuilder()
248         .setProject(project)
249         .setLocation(location)
250         .setSession(session)
251         .setContext(context)
252         .build()
253         .toString();
254   }
255 
256   @BetaApi("The static format methods are not stable yet and may be changed in the future.")
formatProjectLocationEnvironmentUserSessionContextName( String project, String location, String environment, String user, String session, String context)257   public static String formatProjectLocationEnvironmentUserSessionContextName(
258       String project,
259       String location,
260       String environment,
261       String user,
262       String session,
263       String context) {
264     return newProjectLocationEnvironmentUserSessionContextBuilder()
265         .setProject(project)
266         .setLocation(location)
267         .setEnvironment(environment)
268         .setUser(user)
269         .setSession(session)
270         .setContext(context)
271         .build()
272         .toString();
273   }
274 
parse(String formattedString)275   public static ContextName parse(String formattedString) {
276     if (formattedString.isEmpty()) {
277       return null;
278     }
279     if (PROJECT_SESSION_CONTEXT.matches(formattedString)) {
280       Map<String, String> matchMap = PROJECT_SESSION_CONTEXT.match(formattedString);
281       return ofProjectSessionContextName(
282           matchMap.get("project"), matchMap.get("session"), matchMap.get("context"));
283     } else if (PROJECT_ENVIRONMENT_USER_SESSION_CONTEXT.matches(formattedString)) {
284       Map<String, String> matchMap =
285           PROJECT_ENVIRONMENT_USER_SESSION_CONTEXT.match(formattedString);
286       return ofProjectEnvironmentUserSessionContextName(
287           matchMap.get("project"),
288           matchMap.get("environment"),
289           matchMap.get("user"),
290           matchMap.get("session"),
291           matchMap.get("context"));
292     } else if (PROJECT_LOCATION_SESSION_CONTEXT.matches(formattedString)) {
293       Map<String, String> matchMap = PROJECT_LOCATION_SESSION_CONTEXT.match(formattedString);
294       return ofProjectLocationSessionContextName(
295           matchMap.get("project"),
296           matchMap.get("location"),
297           matchMap.get("session"),
298           matchMap.get("context"));
299     } else if (PROJECT_LOCATION_ENVIRONMENT_USER_SESSION_CONTEXT.matches(formattedString)) {
300       Map<String, String> matchMap =
301           PROJECT_LOCATION_ENVIRONMENT_USER_SESSION_CONTEXT.match(formattedString);
302       return ofProjectLocationEnvironmentUserSessionContextName(
303           matchMap.get("project"),
304           matchMap.get("location"),
305           matchMap.get("environment"),
306           matchMap.get("user"),
307           matchMap.get("session"),
308           matchMap.get("context"));
309     }
310     throw new ValidationException("ContextName.parse: formattedString not in valid format");
311   }
312 
parseList(List<String> formattedStrings)313   public static List<ContextName> parseList(List<String> formattedStrings) {
314     List<ContextName> list = new ArrayList<>(formattedStrings.size());
315     for (String formattedString : formattedStrings) {
316       list.add(parse(formattedString));
317     }
318     return list;
319   }
320 
toStringList(List<ContextName> values)321   public static List<String> toStringList(List<ContextName> values) {
322     List<String> list = new ArrayList<>(values.size());
323     for (ContextName value : values) {
324       if (value == null) {
325         list.add("");
326       } else {
327         list.add(value.toString());
328       }
329     }
330     return list;
331   }
332 
isParsableFrom(String formattedString)333   public static boolean isParsableFrom(String formattedString) {
334     return PROJECT_SESSION_CONTEXT.matches(formattedString)
335         || PROJECT_ENVIRONMENT_USER_SESSION_CONTEXT.matches(formattedString)
336         || PROJECT_LOCATION_SESSION_CONTEXT.matches(formattedString)
337         || PROJECT_LOCATION_ENVIRONMENT_USER_SESSION_CONTEXT.matches(formattedString);
338   }
339 
340   @Override
getFieldValuesMap()341   public Map<String, String> getFieldValuesMap() {
342     if (fieldValuesMap == null) {
343       synchronized (this) {
344         if (fieldValuesMap == null) {
345           ImmutableMap.Builder<String, String> fieldMapBuilder = ImmutableMap.builder();
346           if (project != null) {
347             fieldMapBuilder.put("project", project);
348           }
349           if (session != null) {
350             fieldMapBuilder.put("session", session);
351           }
352           if (context != null) {
353             fieldMapBuilder.put("context", context);
354           }
355           if (environment != null) {
356             fieldMapBuilder.put("environment", environment);
357           }
358           if (user != null) {
359             fieldMapBuilder.put("user", user);
360           }
361           if (location != null) {
362             fieldMapBuilder.put("location", location);
363           }
364           fieldValuesMap = fieldMapBuilder.build();
365         }
366       }
367     }
368     return fieldValuesMap;
369   }
370 
getFieldValue(String fieldName)371   public String getFieldValue(String fieldName) {
372     return getFieldValuesMap().get(fieldName);
373   }
374 
375   @Override
toString()376   public String toString() {
377     return fixedValue != null ? fixedValue : pathTemplate.instantiate(getFieldValuesMap());
378   }
379 
380   @Override
equals(Object o)381   public boolean equals(Object o) {
382     if (o == this) {
383       return true;
384     }
385     if (o != null || getClass() == o.getClass()) {
386       ContextName that = ((ContextName) o);
387       return Objects.equals(this.project, that.project)
388           && Objects.equals(this.session, that.session)
389           && Objects.equals(this.context, that.context)
390           && Objects.equals(this.environment, that.environment)
391           && Objects.equals(this.user, that.user)
392           && Objects.equals(this.location, that.location);
393     }
394     return false;
395   }
396 
397   @Override
hashCode()398   public int hashCode() {
399     int h = 1;
400     h *= 1000003;
401     h ^= Objects.hashCode(fixedValue);
402     h *= 1000003;
403     h ^= Objects.hashCode(project);
404     h *= 1000003;
405     h ^= Objects.hashCode(session);
406     h *= 1000003;
407     h ^= Objects.hashCode(context);
408     h *= 1000003;
409     h ^= Objects.hashCode(environment);
410     h *= 1000003;
411     h ^= Objects.hashCode(user);
412     h *= 1000003;
413     h ^= Objects.hashCode(location);
414     return h;
415   }
416 
417   /** Builder for projects/{project}/agent/sessions/{session}/contexts/{context}. */
418   public static class Builder {
419     private String project;
420     private String session;
421     private String context;
422 
Builder()423     protected Builder() {}
424 
getProject()425     public String getProject() {
426       return project;
427     }
428 
getSession()429     public String getSession() {
430       return session;
431     }
432 
getContext()433     public String getContext() {
434       return context;
435     }
436 
setProject(String project)437     public Builder setProject(String project) {
438       this.project = project;
439       return this;
440     }
441 
setSession(String session)442     public Builder setSession(String session) {
443       this.session = session;
444       return this;
445     }
446 
setContext(String context)447     public Builder setContext(String context) {
448       this.context = context;
449       return this;
450     }
451 
Builder(ContextName contextName)452     private Builder(ContextName contextName) {
453       Preconditions.checkArgument(
454           Objects.equals(contextName.pathTemplate, PROJECT_SESSION_CONTEXT),
455           "toBuilder is only supported when ContextName has the pattern of projects/{project}/agent/sessions/{session}/contexts/{context}");
456       this.project = contextName.project;
457       this.session = contextName.session;
458       this.context = contextName.context;
459     }
460 
build()461     public ContextName build() {
462       return new ContextName(this);
463     }
464   }
465 
466   /**
467    * Builder for
468    * projects/{project}/agent/environments/{environment}/users/{user}/sessions/{session}/contexts/{context}.
469    */
470   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
471   public static class ProjectEnvironmentUserSessionContextBuilder {
472     private String project;
473     private String environment;
474     private String user;
475     private String session;
476     private String context;
477 
ProjectEnvironmentUserSessionContextBuilder()478     protected ProjectEnvironmentUserSessionContextBuilder() {}
479 
getProject()480     public String getProject() {
481       return project;
482     }
483 
getEnvironment()484     public String getEnvironment() {
485       return environment;
486     }
487 
getUser()488     public String getUser() {
489       return user;
490     }
491 
getSession()492     public String getSession() {
493       return session;
494     }
495 
getContext()496     public String getContext() {
497       return context;
498     }
499 
setProject(String project)500     public ProjectEnvironmentUserSessionContextBuilder setProject(String project) {
501       this.project = project;
502       return this;
503     }
504 
setEnvironment(String environment)505     public ProjectEnvironmentUserSessionContextBuilder setEnvironment(String environment) {
506       this.environment = environment;
507       return this;
508     }
509 
setUser(String user)510     public ProjectEnvironmentUserSessionContextBuilder setUser(String user) {
511       this.user = user;
512       return this;
513     }
514 
setSession(String session)515     public ProjectEnvironmentUserSessionContextBuilder setSession(String session) {
516       this.session = session;
517       return this;
518     }
519 
setContext(String context)520     public ProjectEnvironmentUserSessionContextBuilder setContext(String context) {
521       this.context = context;
522       return this;
523     }
524 
build()525     public ContextName build() {
526       return new ContextName(this);
527     }
528   }
529 
530   /**
531    * Builder for
532    * projects/{project}/locations/{location}/agent/sessions/{session}/contexts/{context}.
533    */
534   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
535   public static class ProjectLocationSessionContextBuilder {
536     private String project;
537     private String location;
538     private String session;
539     private String context;
540 
ProjectLocationSessionContextBuilder()541     protected ProjectLocationSessionContextBuilder() {}
542 
getProject()543     public String getProject() {
544       return project;
545     }
546 
getLocation()547     public String getLocation() {
548       return location;
549     }
550 
getSession()551     public String getSession() {
552       return session;
553     }
554 
getContext()555     public String getContext() {
556       return context;
557     }
558 
setProject(String project)559     public ProjectLocationSessionContextBuilder setProject(String project) {
560       this.project = project;
561       return this;
562     }
563 
setLocation(String location)564     public ProjectLocationSessionContextBuilder setLocation(String location) {
565       this.location = location;
566       return this;
567     }
568 
setSession(String session)569     public ProjectLocationSessionContextBuilder setSession(String session) {
570       this.session = session;
571       return this;
572     }
573 
setContext(String context)574     public ProjectLocationSessionContextBuilder setContext(String context) {
575       this.context = context;
576       return this;
577     }
578 
build()579     public ContextName build() {
580       return new ContextName(this);
581     }
582   }
583 
584   /**
585    * Builder for
586    * projects/{project}/locations/{location}/agent/environments/{environment}/users/{user}/sessions/{session}/contexts/{context}.
587    */
588   @BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
589   public static class ProjectLocationEnvironmentUserSessionContextBuilder {
590     private String project;
591     private String location;
592     private String environment;
593     private String user;
594     private String session;
595     private String context;
596 
ProjectLocationEnvironmentUserSessionContextBuilder()597     protected ProjectLocationEnvironmentUserSessionContextBuilder() {}
598 
getProject()599     public String getProject() {
600       return project;
601     }
602 
getLocation()603     public String getLocation() {
604       return location;
605     }
606 
getEnvironment()607     public String getEnvironment() {
608       return environment;
609     }
610 
getUser()611     public String getUser() {
612       return user;
613     }
614 
getSession()615     public String getSession() {
616       return session;
617     }
618 
getContext()619     public String getContext() {
620       return context;
621     }
622 
setProject(String project)623     public ProjectLocationEnvironmentUserSessionContextBuilder setProject(String project) {
624       this.project = project;
625       return this;
626     }
627 
setLocation(String location)628     public ProjectLocationEnvironmentUserSessionContextBuilder setLocation(String location) {
629       this.location = location;
630       return this;
631     }
632 
setEnvironment(String environment)633     public ProjectLocationEnvironmentUserSessionContextBuilder setEnvironment(String environment) {
634       this.environment = environment;
635       return this;
636     }
637 
setUser(String user)638     public ProjectLocationEnvironmentUserSessionContextBuilder setUser(String user) {
639       this.user = user;
640       return this;
641     }
642 
setSession(String session)643     public ProjectLocationEnvironmentUserSessionContextBuilder setSession(String session) {
644       this.session = session;
645       return this;
646     }
647 
setContext(String context)648     public ProjectLocationEnvironmentUserSessionContextBuilder setContext(String context) {
649       this.context = context;
650       return this;
651     }
652 
build()653     public ContextName build() {
654       return new ContextName(this);
655     }
656   }
657 }
658