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