|
| 1 | +/* |
| 2 | + * Copyright 2018 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
| 5 | + * in compliance with the License. You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software distributed under the License |
| 10 | + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 11 | + * or implied. See the License for the specific language governing permissions and limitations under |
| 12 | + * the License. |
| 13 | + */ |
| 14 | + |
| 15 | +package com.google.cloud.automl.v1beta1; |
| 16 | + |
| 17 | +import com.google.api.pathtemplate.PathTemplate; |
| 18 | +import com.google.api.resourcenames.ResourceName; |
| 19 | +import com.google.common.base.Preconditions; |
| 20 | +import com.google.common.collect.ImmutableMap; |
| 21 | +import java.util.ArrayList; |
| 22 | +import java.util.List; |
| 23 | +import java.util.Map; |
| 24 | + |
| 25 | +// AUTO-GENERATED DOCUMENTATION AND CLASS |
| 26 | +@javax.annotation.Generated("by GAPIC protoc plugin") |
| 27 | +public class AnnotationSpecName implements ResourceName { |
| 28 | + |
| 29 | + private static final PathTemplate PATH_TEMPLATE = |
| 30 | + PathTemplate.createWithoutUrlEncoding( |
| 31 | + "projects/{project}/locations/{location}/datasets/{dataset}/annotationSpecs/{annotation_spec}"); |
| 32 | + |
| 33 | + private volatile Map<String, String> fieldValuesMap; |
| 34 | + |
| 35 | + private final String project; |
| 36 | + private final String location; |
| 37 | + private final String dataset; |
| 38 | + private final String annotationSpec; |
| 39 | + |
| 40 | + public String getProject() { |
| 41 | + return project; |
| 42 | + } |
| 43 | + |
| 44 | + public String getLocation() { |
| 45 | + return location; |
| 46 | + } |
| 47 | + |
| 48 | + public String getDataset() { |
| 49 | + return dataset; |
| 50 | + } |
| 51 | + |
| 52 | + public String getAnnotationSpec() { |
| 53 | + return annotationSpec; |
| 54 | + } |
| 55 | + |
| 56 | + public static Builder newBuilder() { |
| 57 | + return new Builder(); |
| 58 | + } |
| 59 | + |
| 60 | + public Builder toBuilder() { |
| 61 | + return new Builder(this); |
| 62 | + } |
| 63 | + |
| 64 | + private AnnotationSpecName(Builder builder) { |
| 65 | + project = Preconditions.checkNotNull(builder.getProject()); |
| 66 | + location = Preconditions.checkNotNull(builder.getLocation()); |
| 67 | + dataset = Preconditions.checkNotNull(builder.getDataset()); |
| 68 | + annotationSpec = Preconditions.checkNotNull(builder.getAnnotationSpec()); |
| 69 | + } |
| 70 | + |
| 71 | + public static AnnotationSpecName of( |
| 72 | + String project, String location, String dataset, String annotationSpec) { |
| 73 | + return newBuilder() |
| 74 | + .setProject(project) |
| 75 | + .setLocation(location) |
| 76 | + .setDataset(dataset) |
| 77 | + .setAnnotationSpec(annotationSpec) |
| 78 | + .build(); |
| 79 | + } |
| 80 | + |
| 81 | + public static String format( |
| 82 | + String project, String location, String dataset, String annotationSpec) { |
| 83 | + return newBuilder() |
| 84 | + .setProject(project) |
| 85 | + .setLocation(location) |
| 86 | + .setDataset(dataset) |
| 87 | + .setAnnotationSpec(annotationSpec) |
| 88 | + .build() |
| 89 | + .toString(); |
| 90 | + } |
| 91 | + |
| 92 | + public static AnnotationSpecName parse(String formattedString) { |
| 93 | + if (formattedString.isEmpty()) { |
| 94 | + return null; |
| 95 | + } |
| 96 | + Map<String, String> matchMap = |
| 97 | + PATH_TEMPLATE.validatedMatch( |
| 98 | + formattedString, "AnnotationSpecName.parse: formattedString not in valid format"); |
| 99 | + return of( |
| 100 | + matchMap.get("project"), |
| 101 | + matchMap.get("location"), |
| 102 | + matchMap.get("dataset"), |
| 103 | + matchMap.get("annotation_spec")); |
| 104 | + } |
| 105 | + |
| 106 | + public static List<AnnotationSpecName> parseList(List<String> formattedStrings) { |
| 107 | + List<AnnotationSpecName> list = new ArrayList<>(formattedStrings.size()); |
| 108 | + for (String formattedString : formattedStrings) { |
| 109 | + list.add(parse(formattedString)); |
| 110 | + } |
| 111 | + return list; |
| 112 | + } |
| 113 | + |
| 114 | + public static List<String> toStringList(List<AnnotationSpecName> values) { |
| 115 | + List<String> list = new ArrayList<String>(values.size()); |
| 116 | + for (AnnotationSpecName value : values) { |
| 117 | + if (value == null) { |
| 118 | + list.add(""); |
| 119 | + } else { |
| 120 | + list.add(value.toString()); |
| 121 | + } |
| 122 | + } |
| 123 | + return list; |
| 124 | + } |
| 125 | + |
| 126 | + public static boolean isParsableFrom(String formattedString) { |
| 127 | + return PATH_TEMPLATE.matches(formattedString); |
| 128 | + } |
| 129 | + |
| 130 | + public Map<String, String> getFieldValuesMap() { |
| 131 | + if (fieldValuesMap == null) { |
| 132 | + synchronized (this) { |
| 133 | + if (fieldValuesMap == null) { |
| 134 | + ImmutableMap.Builder<String, String> fieldMapBuilder = ImmutableMap.builder(); |
| 135 | + fieldMapBuilder.put("project", project); |
| 136 | + fieldMapBuilder.put("location", location); |
| 137 | + fieldMapBuilder.put("dataset", dataset); |
| 138 | + fieldMapBuilder.put("annotationSpec", annotationSpec); |
| 139 | + fieldValuesMap = fieldMapBuilder.build(); |
| 140 | + } |
| 141 | + } |
| 142 | + } |
| 143 | + return fieldValuesMap; |
| 144 | + } |
| 145 | + |
| 146 | + public String getFieldValue(String fieldName) { |
| 147 | + return getFieldValuesMap().get(fieldName); |
| 148 | + } |
| 149 | + |
| 150 | + @Override |
| 151 | + public String toString() { |
| 152 | + return PATH_TEMPLATE.instantiate( |
| 153 | + "project", |
| 154 | + project, |
| 155 | + "location", |
| 156 | + location, |
| 157 | + "dataset", |
| 158 | + dataset, |
| 159 | + "annotation_spec", |
| 160 | + annotationSpec); |
| 161 | + } |
| 162 | + |
| 163 | + /** Builder for AnnotationSpecName. */ |
| 164 | + public static class Builder { |
| 165 | + |
| 166 | + private String project; |
| 167 | + private String location; |
| 168 | + private String dataset; |
| 169 | + private String annotationSpec; |
| 170 | + |
| 171 | + public String getProject() { |
| 172 | + return project; |
| 173 | + } |
| 174 | + |
| 175 | + public String getLocation() { |
| 176 | + return location; |
| 177 | + } |
| 178 | + |
| 179 | + public String getDataset() { |
| 180 | + return dataset; |
| 181 | + } |
| 182 | + |
| 183 | + public String getAnnotationSpec() { |
| 184 | + return annotationSpec; |
| 185 | + } |
| 186 | + |
| 187 | + public Builder setProject(String project) { |
| 188 | + this.project = project; |
| 189 | + return this; |
| 190 | + } |
| 191 | + |
| 192 | + public Builder setLocation(String location) { |
| 193 | + this.location = location; |
| 194 | + return this; |
| 195 | + } |
| 196 | + |
| 197 | + public Builder setDataset(String dataset) { |
| 198 | + this.dataset = dataset; |
| 199 | + return this; |
| 200 | + } |
| 201 | + |
| 202 | + public Builder setAnnotationSpec(String annotationSpec) { |
| 203 | + this.annotationSpec = annotationSpec; |
| 204 | + return this; |
| 205 | + } |
| 206 | + |
| 207 | + private Builder() {} |
| 208 | + |
| 209 | + private Builder(AnnotationSpecName annotationSpecName) { |
| 210 | + project = annotationSpecName.project; |
| 211 | + location = annotationSpecName.location; |
| 212 | + dataset = annotationSpecName.dataset; |
| 213 | + annotationSpec = annotationSpecName.annotationSpec; |
| 214 | + } |
| 215 | + |
| 216 | + public AnnotationSpecName build() { |
| 217 | + return new AnnotationSpecName(this); |
| 218 | + } |
| 219 | + } |
| 220 | + |
| 221 | + @Override |
| 222 | + public boolean equals(Object o) { |
| 223 | + if (o == this) { |
| 224 | + return true; |
| 225 | + } |
| 226 | + if (o instanceof AnnotationSpecName) { |
| 227 | + AnnotationSpecName that = (AnnotationSpecName) o; |
| 228 | + return (this.project.equals(that.project)) |
| 229 | + && (this.location.equals(that.location)) |
| 230 | + && (this.dataset.equals(that.dataset)) |
| 231 | + && (this.annotationSpec.equals(that.annotationSpec)); |
| 232 | + } |
| 233 | + return false; |
| 234 | + } |
| 235 | + |
| 236 | + @Override |
| 237 | + public int hashCode() { |
| 238 | + int h = 1; |
| 239 | + h *= 1000003; |
| 240 | + h ^= project.hashCode(); |
| 241 | + h *= 1000003; |
| 242 | + h ^= location.hashCode(); |
| 243 | + h *= 1000003; |
| 244 | + h ^= dataset.hashCode(); |
| 245 | + h *= 1000003; |
| 246 | + h ^= annotationSpec.hashCode(); |
| 247 | + return h; |
| 248 | + } |
| 249 | +} |
0 commit comments