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