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.aiplatform.v1; 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 DataItemName implements ResourceName { 32 private static final PathTemplate PROJECT_LOCATION_DATASET_DATA_ITEM = 33 PathTemplate.createWithoutUrlEncoding( 34 "projects/{project}/locations/{location}/datasets/{dataset}/dataItems/{data_item}"); 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 dataItem; 40 41 @Deprecated DataItemName()42 protected DataItemName() { 43 project = null; 44 location = null; 45 dataset = null; 46 dataItem = null; 47 } 48 DataItemName(Builder builder)49 private DataItemName(Builder builder) { 50 project = Preconditions.checkNotNull(builder.getProject()); 51 location = Preconditions.checkNotNull(builder.getLocation()); 52 dataset = Preconditions.checkNotNull(builder.getDataset()); 53 dataItem = Preconditions.checkNotNull(builder.getDataItem()); 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 getDataItem()68 public String getDataItem() { 69 return dataItem; 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 dataItem)80 public static DataItemName of(String project, String location, String dataset, String dataItem) { 81 return newBuilder() 82 .setProject(project) 83 .setLocation(location) 84 .setDataset(dataset) 85 .setDataItem(dataItem) 86 .build(); 87 } 88 format(String project, String location, String dataset, String dataItem)89 public static String format(String project, String location, String dataset, String dataItem) { 90 return newBuilder() 91 .setProject(project) 92 .setLocation(location) 93 .setDataset(dataset) 94 .setDataItem(dataItem) 95 .build() 96 .toString(); 97 } 98 parse(String formattedString)99 public static DataItemName parse(String formattedString) { 100 if (formattedString.isEmpty()) { 101 return null; 102 } 103 Map<String, String> matchMap = 104 PROJECT_LOCATION_DATASET_DATA_ITEM.validatedMatch( 105 formattedString, "DataItemName.parse: formattedString not in valid format"); 106 return of( 107 matchMap.get("project"), 108 matchMap.get("location"), 109 matchMap.get("dataset"), 110 matchMap.get("data_item")); 111 } 112 parseList(List<String> formattedStrings)113 public static List<DataItemName> parseList(List<String> formattedStrings) { 114 List<DataItemName> list = new ArrayList<>(formattedStrings.size()); 115 for (String formattedString : formattedStrings) { 116 list.add(parse(formattedString)); 117 } 118 return list; 119 } 120 toStringList(List<DataItemName> values)121 public static List<String> toStringList(List<DataItemName> values) { 122 List<String> list = new ArrayList<>(values.size()); 123 for (DataItemName 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_DATASET_DATA_ITEM.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 (dataset != null) { 150 fieldMapBuilder.put("dataset", dataset); 151 } 152 if (dataItem != null) { 153 fieldMapBuilder.put("data_item", dataItem); 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_DATASET_DATA_ITEM.instantiate( 169 "project", project, "location", location, "dataset", dataset, "data_item", dataItem); 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 DataItemName that = ((DataItemName) o); 179 return Objects.equals(this.project, that.project) 180 && Objects.equals(this.location, that.location) 181 && Objects.equals(this.dataset, that.dataset) 182 && Objects.equals(this.dataItem, that.dataItem); 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(dataset); 196 h *= 1000003; 197 h ^= Objects.hashCode(dataItem); 198 return h; 199 } 200 201 /** 202 * Builder for projects/{project}/locations/{location}/datasets/{dataset}/dataItems/{data_item}. 203 */ 204 public static class Builder { 205 private String project; 206 private String location; 207 private String dataset; 208 private String dataItem; 209 Builder()210 protected Builder() {} 211 getProject()212 public String getProject() { 213 return project; 214 } 215 getLocation()216 public String getLocation() { 217 return location; 218 } 219 getDataset()220 public String getDataset() { 221 return dataset; 222 } 223 getDataItem()224 public String getDataItem() { 225 return dataItem; 226 } 227 setProject(String project)228 public Builder setProject(String project) { 229 this.project = project; 230 return this; 231 } 232 setLocation(String location)233 public Builder setLocation(String location) { 234 this.location = location; 235 return this; 236 } 237 setDataset(String dataset)238 public Builder setDataset(String dataset) { 239 this.dataset = dataset; 240 return this; 241 } 242 setDataItem(String dataItem)243 public Builder setDataItem(String dataItem) { 244 this.dataItem = dataItem; 245 return this; 246 } 247 Builder(DataItemName dataItemName)248 private Builder(DataItemName dataItemName) { 249 this.project = dataItemName.project; 250 this.location = dataItemName.location; 251 this.dataset = dataItemName.dataset; 252 this.dataItem = dataItemName.dataItem; 253 } 254 build()255 public DataItemName build() { 256 return new DataItemName(this); 257 } 258 } 259 } 260