• 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.cx.v3;
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 IntentName implements ResourceName {
32   private static final PathTemplate PROJECT_LOCATION_AGENT_INTENT =
33       PathTemplate.createWithoutUrlEncoding(
34           "projects/{project}/locations/{location}/agents/{agent}/intents/{intent}");
35   private volatile Map<String, String> fieldValuesMap;
36   private final String project;
37   private final String location;
38   private final String agent;
39   private final String intent;
40 
41   @Deprecated
IntentName()42   protected IntentName() {
43     project = null;
44     location = null;
45     agent = null;
46     intent = null;
47   }
48 
IntentName(Builder builder)49   private IntentName(Builder builder) {
50     project = Preconditions.checkNotNull(builder.getProject());
51     location = Preconditions.checkNotNull(builder.getLocation());
52     agent = Preconditions.checkNotNull(builder.getAgent());
53     intent = Preconditions.checkNotNull(builder.getIntent());
54   }
55 
getProject()56   public String getProject() {
57     return project;
58   }
59 
getLocation()60   public String getLocation() {
61     return location;
62   }
63 
getAgent()64   public String getAgent() {
65     return agent;
66   }
67 
getIntent()68   public String getIntent() {
69     return intent;
70   }
71 
newBuilder()72   public static Builder newBuilder() {
73     return new Builder();
74   }
75 
toBuilder()76   public Builder toBuilder() {
77     return new Builder(this);
78   }
79 
of(String project, String location, String agent, String intent)80   public static IntentName of(String project, String location, String agent, String intent) {
81     return newBuilder()
82         .setProject(project)
83         .setLocation(location)
84         .setAgent(agent)
85         .setIntent(intent)
86         .build();
87   }
88 
format(String project, String location, String agent, String intent)89   public static String format(String project, String location, String agent, String intent) {
90     return newBuilder()
91         .setProject(project)
92         .setLocation(location)
93         .setAgent(agent)
94         .setIntent(intent)
95         .build()
96         .toString();
97   }
98 
parse(String formattedString)99   public static IntentName parse(String formattedString) {
100     if (formattedString.isEmpty()) {
101       return null;
102     }
103     Map<String, String> matchMap =
104         PROJECT_LOCATION_AGENT_INTENT.validatedMatch(
105             formattedString, "IntentName.parse: formattedString not in valid format");
106     return of(
107         matchMap.get("project"),
108         matchMap.get("location"),
109         matchMap.get("agent"),
110         matchMap.get("intent"));
111   }
112 
parseList(List<String> formattedStrings)113   public static List<IntentName> parseList(List<String> formattedStrings) {
114     List<IntentName> list = new ArrayList<>(formattedStrings.size());
115     for (String formattedString : formattedStrings) {
116       list.add(parse(formattedString));
117     }
118     return list;
119   }
120 
toStringList(List<IntentName> values)121   public static List<String> toStringList(List<IntentName> values) {
122     List<String> list = new ArrayList<>(values.size());
123     for (IntentName value : values) {
124       if (value == null) {
125         list.add("");
126       } else {
127         list.add(value.toString());
128       }
129     }
130     return list;
131   }
132 
isParsableFrom(String formattedString)133   public static boolean isParsableFrom(String formattedString) {
134     return PROJECT_LOCATION_AGENT_INTENT.matches(formattedString);
135   }
136 
137   @Override
getFieldValuesMap()138   public Map<String, String> getFieldValuesMap() {
139     if (fieldValuesMap == null) {
140       synchronized (this) {
141         if (fieldValuesMap == null) {
142           ImmutableMap.Builder<String, String> fieldMapBuilder = ImmutableMap.builder();
143           if (project != null) {
144             fieldMapBuilder.put("project", project);
145           }
146           if (location != null) {
147             fieldMapBuilder.put("location", location);
148           }
149           if (agent != null) {
150             fieldMapBuilder.put("agent", agent);
151           }
152           if (intent != null) {
153             fieldMapBuilder.put("intent", intent);
154           }
155           fieldValuesMap = fieldMapBuilder.build();
156         }
157       }
158     }
159     return fieldValuesMap;
160   }
161 
getFieldValue(String fieldName)162   public String getFieldValue(String fieldName) {
163     return getFieldValuesMap().get(fieldName);
164   }
165 
166   @Override
toString()167   public String toString() {
168     return PROJECT_LOCATION_AGENT_INTENT.instantiate(
169         "project", project, "location", location, "agent", agent, "intent", intent);
170   }
171 
172   @Override
equals(Object o)173   public boolean equals(Object o) {
174     if (o == this) {
175       return true;
176     }
177     if (o != null || getClass() == o.getClass()) {
178       IntentName that = ((IntentName) o);
179       return Objects.equals(this.project, that.project)
180           && Objects.equals(this.location, that.location)
181           && Objects.equals(this.agent, that.agent)
182           && Objects.equals(this.intent, that.intent);
183     }
184     return false;
185   }
186 
187   @Override
hashCode()188   public int hashCode() {
189     int h = 1;
190     h *= 1000003;
191     h ^= Objects.hashCode(project);
192     h *= 1000003;
193     h ^= Objects.hashCode(location);
194     h *= 1000003;
195     h ^= Objects.hashCode(agent);
196     h *= 1000003;
197     h ^= Objects.hashCode(intent);
198     return h;
199   }
200 
201   /** Builder for projects/{project}/locations/{location}/agents/{agent}/intents/{intent}. */
202   public static class Builder {
203     private String project;
204     private String location;
205     private String agent;
206     private String intent;
207 
Builder()208     protected Builder() {}
209 
getProject()210     public String getProject() {
211       return project;
212     }
213 
getLocation()214     public String getLocation() {
215       return location;
216     }
217 
getAgent()218     public String getAgent() {
219       return agent;
220     }
221 
getIntent()222     public String getIntent() {
223       return intent;
224     }
225 
setProject(String project)226     public Builder setProject(String project) {
227       this.project = project;
228       return this;
229     }
230 
setLocation(String location)231     public Builder setLocation(String location) {
232       this.location = location;
233       return this;
234     }
235 
setAgent(String agent)236     public Builder setAgent(String agent) {
237       this.agent = agent;
238       return this;
239     }
240 
setIntent(String intent)241     public Builder setIntent(String intent) {
242       this.intent = intent;
243       return this;
244     }
245 
Builder(IntentName intentName)246     private Builder(IntentName intentName) {
247       this.project = intentName.project;
248       this.location = intentName.location;
249       this.agent = intentName.agent;
250       this.intent = intentName.intent;
251     }
252 
build()253     public IntentName build() {
254       return new IntentName(this);
255     }
256   }
257 }
258