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.tasks.v2beta2; 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 TaskName implements ResourceName { 32 private static final PathTemplate PROJECT_LOCATION_QUEUE_TASK = 33 PathTemplate.createWithoutUrlEncoding( 34 "projects/{project}/locations/{location}/queues/{queue}/tasks/{task}"); 35 private volatile Map<String, String> fieldValuesMap; 36 private final String project; 37 private final String location; 38 private final String queue; 39 private final String task; 40 41 @Deprecated TaskName()42 protected TaskName() { 43 project = null; 44 location = null; 45 queue = null; 46 task = null; 47 } 48 TaskName(Builder builder)49 private TaskName(Builder builder) { 50 project = Preconditions.checkNotNull(builder.getProject()); 51 location = Preconditions.checkNotNull(builder.getLocation()); 52 queue = Preconditions.checkNotNull(builder.getQueue()); 53 task = Preconditions.checkNotNull(builder.getTask()); 54 } 55 getProject()56 public String getProject() { 57 return project; 58 } 59 getLocation()60 public String getLocation() { 61 return location; 62 } 63 getQueue()64 public String getQueue() { 65 return queue; 66 } 67 getTask()68 public String getTask() { 69 return task; 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 queue, String task)80 public static TaskName of(String project, String location, String queue, String task) { 81 return newBuilder() 82 .setProject(project) 83 .setLocation(location) 84 .setQueue(queue) 85 .setTask(task) 86 .build(); 87 } 88 format(String project, String location, String queue, String task)89 public static String format(String project, String location, String queue, String task) { 90 return newBuilder() 91 .setProject(project) 92 .setLocation(location) 93 .setQueue(queue) 94 .setTask(task) 95 .build() 96 .toString(); 97 } 98 parse(String formattedString)99 public static TaskName parse(String formattedString) { 100 if (formattedString.isEmpty()) { 101 return null; 102 } 103 Map<String, String> matchMap = 104 PROJECT_LOCATION_QUEUE_TASK.validatedMatch( 105 formattedString, "TaskName.parse: formattedString not in valid format"); 106 return of( 107 matchMap.get("project"), 108 matchMap.get("location"), 109 matchMap.get("queue"), 110 matchMap.get("task")); 111 } 112 parseList(List<String> formattedStrings)113 public static List<TaskName> parseList(List<String> formattedStrings) { 114 List<TaskName> list = new ArrayList<>(formattedStrings.size()); 115 for (String formattedString : formattedStrings) { 116 list.add(parse(formattedString)); 117 } 118 return list; 119 } 120 toStringList(List<TaskName> values)121 public static List<String> toStringList(List<TaskName> values) { 122 List<String> list = new ArrayList<>(values.size()); 123 for (TaskName 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_QUEUE_TASK.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 (queue != null) { 150 fieldMapBuilder.put("queue", queue); 151 } 152 if (task != null) { 153 fieldMapBuilder.put("task", task); 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_QUEUE_TASK.instantiate( 169 "project", project, "location", location, "queue", queue, "task", task); 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 TaskName that = ((TaskName) o); 179 return Objects.equals(this.project, that.project) 180 && Objects.equals(this.location, that.location) 181 && Objects.equals(this.queue, that.queue) 182 && Objects.equals(this.task, that.task); 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(queue); 196 h *= 1000003; 197 h ^= Objects.hashCode(task); 198 return h; 199 } 200 201 /** Builder for projects/{project}/locations/{location}/queues/{queue}/tasks/{task}. */ 202 public static class Builder { 203 private String project; 204 private String location; 205 private String queue; 206 private String task; 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 getQueue()218 public String getQueue() { 219 return queue; 220 } 221 getTask()222 public String getTask() { 223 return task; 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 setQueue(String queue)236 public Builder setQueue(String queue) { 237 this.queue = queue; 238 return this; 239 } 240 setTask(String task)241 public Builder setTask(String task) { 242 this.task = task; 243 return this; 244 } 245 Builder(TaskName taskName)246 private Builder(TaskName taskName) { 247 this.project = taskName.project; 248 this.location = taskName.location; 249 this.queue = taskName.queue; 250 this.task = taskName.task; 251 } 252 build()253 public TaskName build() { 254 return new TaskName(this); 255 } 256 } 257 } 258