|
| 1 | +/* |
| 2 | + * Copyright 2020 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.logging.type; |
| 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 | + |
| 27 | +/** AUTO-GENERATED DOCUMENTATION AND CLASS */ |
| 28 | +@javax.annotation.Generated("by GAPIC protoc plugin") |
| 29 | +public class BillingAccountLocationName implements ResourceName { |
| 30 | + |
| 31 | + private static final PathTemplate PATH_TEMPLATE = |
| 32 | + PathTemplate.createWithoutUrlEncoding( |
| 33 | + "billingAccounts/{billing_account}/locations/{location}"); |
| 34 | + |
| 35 | + private volatile Map<String, String> fieldValuesMap; |
| 36 | + |
| 37 | + private final String billingAccount; |
| 38 | + private final String location; |
| 39 | + |
| 40 | + public String getBillingAccount() { |
| 41 | + return billingAccount; |
| 42 | + } |
| 43 | + |
| 44 | + public String getLocation() { |
| 45 | + return location; |
| 46 | + } |
| 47 | + |
| 48 | + public static Builder newBuilder() { |
| 49 | + return new Builder(); |
| 50 | + } |
| 51 | + |
| 52 | + public Builder toBuilder() { |
| 53 | + return new Builder(this); |
| 54 | + } |
| 55 | + |
| 56 | + private BillingAccountLocationName(Builder builder) { |
| 57 | + billingAccount = Preconditions.checkNotNull(builder.getBillingAccount()); |
| 58 | + location = Preconditions.checkNotNull(builder.getLocation()); |
| 59 | + } |
| 60 | + |
| 61 | + public static BillingAccountLocationName of(String billingAccount, String location) { |
| 62 | + return newBuilder().setBillingAccount(billingAccount).setLocation(location).build(); |
| 63 | + } |
| 64 | + |
| 65 | + public static String format(String billingAccount, String location) { |
| 66 | + return newBuilder().setBillingAccount(billingAccount).setLocation(location).build().toString(); |
| 67 | + } |
| 68 | + |
| 69 | + public static BillingAccountLocationName parse(String formattedString) { |
| 70 | + if (formattedString.isEmpty()) { |
| 71 | + return null; |
| 72 | + } |
| 73 | + Map<String, String> matchMap = |
| 74 | + PATH_TEMPLATE.validatedMatch( |
| 75 | + formattedString, |
| 76 | + "BillingAccountLocationName.parse: formattedString not in valid format"); |
| 77 | + return of(matchMap.get("billing_account"), matchMap.get("location")); |
| 78 | + } |
| 79 | + |
| 80 | + public static List<BillingAccountLocationName> parseList(List<String> formattedStrings) { |
| 81 | + List<BillingAccountLocationName> list = new ArrayList<>(formattedStrings.size()); |
| 82 | + for (String formattedString : formattedStrings) { |
| 83 | + list.add(parse(formattedString)); |
| 84 | + } |
| 85 | + return list; |
| 86 | + } |
| 87 | + |
| 88 | + public static List<String> toStringList(List<BillingAccountLocationName> values) { |
| 89 | + List<String> list = new ArrayList<String>(values.size()); |
| 90 | + for (BillingAccountLocationName value : values) { |
| 91 | + if (value == null) { |
| 92 | + list.add(""); |
| 93 | + } else { |
| 94 | + list.add(value.toString()); |
| 95 | + } |
| 96 | + } |
| 97 | + return list; |
| 98 | + } |
| 99 | + |
| 100 | + public static boolean isParsableFrom(String formattedString) { |
| 101 | + return PATH_TEMPLATE.matches(formattedString); |
| 102 | + } |
| 103 | + |
| 104 | + public Map<String, String> getFieldValuesMap() { |
| 105 | + if (fieldValuesMap == null) { |
| 106 | + synchronized (this) { |
| 107 | + if (fieldValuesMap == null) { |
| 108 | + ImmutableMap.Builder<String, String> fieldMapBuilder = ImmutableMap.builder(); |
| 109 | + fieldMapBuilder.put("billingAccount", billingAccount); |
| 110 | + fieldMapBuilder.put("location", location); |
| 111 | + fieldValuesMap = fieldMapBuilder.build(); |
| 112 | + } |
| 113 | + } |
| 114 | + } |
| 115 | + return fieldValuesMap; |
| 116 | + } |
| 117 | + |
| 118 | + public String getFieldValue(String fieldName) { |
| 119 | + return getFieldValuesMap().get(fieldName); |
| 120 | + } |
| 121 | + |
| 122 | + @Override |
| 123 | + public String toString() { |
| 124 | + return PATH_TEMPLATE.instantiate("billing_account", billingAccount, "location", location); |
| 125 | + } |
| 126 | + |
| 127 | + /** Builder for BillingAccountLocationName. */ |
| 128 | + public static class Builder { |
| 129 | + |
| 130 | + private String billingAccount; |
| 131 | + private String location; |
| 132 | + |
| 133 | + public String getBillingAccount() { |
| 134 | + return billingAccount; |
| 135 | + } |
| 136 | + |
| 137 | + public String getLocation() { |
| 138 | + return location; |
| 139 | + } |
| 140 | + |
| 141 | + public Builder setBillingAccount(String billingAccount) { |
| 142 | + this.billingAccount = billingAccount; |
| 143 | + return this; |
| 144 | + } |
| 145 | + |
| 146 | + public Builder setLocation(String location) { |
| 147 | + this.location = location; |
| 148 | + return this; |
| 149 | + } |
| 150 | + |
| 151 | + private Builder() {} |
| 152 | + |
| 153 | + private Builder(BillingAccountLocationName billingAccountLocationName) { |
| 154 | + billingAccount = billingAccountLocationName.billingAccount; |
| 155 | + location = billingAccountLocationName.location; |
| 156 | + } |
| 157 | + |
| 158 | + public BillingAccountLocationName build() { |
| 159 | + return new BillingAccountLocationName(this); |
| 160 | + } |
| 161 | + } |
| 162 | + |
| 163 | + @Override |
| 164 | + public boolean equals(Object o) { |
| 165 | + if (o == this) { |
| 166 | + return true; |
| 167 | + } |
| 168 | + if (o instanceof BillingAccountLocationName) { |
| 169 | + BillingAccountLocationName that = (BillingAccountLocationName) o; |
| 170 | + return (this.billingAccount.equals(that.billingAccount)) |
| 171 | + && (this.location.equals(that.location)); |
| 172 | + } |
| 173 | + return false; |
| 174 | + } |
| 175 | + |
| 176 | + @Override |
| 177 | + public int hashCode() { |
| 178 | + int h = 1; |
| 179 | + h *= 1000003; |
| 180 | + h ^= billingAccount.hashCode(); |
| 181 | + h *= 1000003; |
| 182 | + h ^= location.hashCode(); |
| 183 | + return h; |
| 184 | + } |
| 185 | +} |
0 commit comments