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