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