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.billing.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 BillingAccountName implements ResourceName { 32 private static final PathTemplate BILLING_ACCOUNT = 33 PathTemplate.createWithoutUrlEncoding("billingAccounts/{billing_account}"); 34 private volatile Map<String, String> fieldValuesMap; 35 private final String billingAccount; 36 37 @Deprecated BillingAccountName()38 protected BillingAccountName() { 39 billingAccount = null; 40 } 41 BillingAccountName(Builder builder)42 private BillingAccountName(Builder builder) { 43 billingAccount = Preconditions.checkNotNull(builder.getBillingAccount()); 44 } 45 getBillingAccount()46 public String getBillingAccount() { 47 return billingAccount; 48 } 49 newBuilder()50 public static Builder newBuilder() { 51 return new Builder(); 52 } 53 toBuilder()54 public Builder toBuilder() { 55 return new Builder(this); 56 } 57 of(String billingAccount)58 public static BillingAccountName of(String billingAccount) { 59 return newBuilder().setBillingAccount(billingAccount).build(); 60 } 61 format(String billingAccount)62 public static String format(String billingAccount) { 63 return newBuilder().setBillingAccount(billingAccount).build().toString(); 64 } 65 parse(String formattedString)66 public static BillingAccountName parse(String formattedString) { 67 if (formattedString.isEmpty()) { 68 return null; 69 } 70 Map<String, String> matchMap = 71 BILLING_ACCOUNT.validatedMatch( 72 formattedString, "BillingAccountName.parse: formattedString not in valid format"); 73 return of(matchMap.get("billing_account")); 74 } 75 parseList(List<String> formattedStrings)76 public static List<BillingAccountName> parseList(List<String> formattedStrings) { 77 List<BillingAccountName> list = new ArrayList<>(formattedStrings.size()); 78 for (String formattedString : formattedStrings) { 79 list.add(parse(formattedString)); 80 } 81 return list; 82 } 83 toStringList(List<BillingAccountName> values)84 public static List<String> toStringList(List<BillingAccountName> values) { 85 List<String> list = new ArrayList<>(values.size()); 86 for (BillingAccountName value : values) { 87 if (value == null) { 88 list.add(""); 89 } else { 90 list.add(value.toString()); 91 } 92 } 93 return list; 94 } 95 isParsableFrom(String formattedString)96 public static boolean isParsableFrom(String formattedString) { 97 return BILLING_ACCOUNT.matches(formattedString); 98 } 99 100 @Override getFieldValuesMap()101 public Map<String, String> getFieldValuesMap() { 102 if (fieldValuesMap == null) { 103 synchronized (this) { 104 if (fieldValuesMap == null) { 105 ImmutableMap.Builder<String, String> fieldMapBuilder = ImmutableMap.builder(); 106 if (billingAccount != null) { 107 fieldMapBuilder.put("billing_account", billingAccount); 108 } 109 fieldValuesMap = fieldMapBuilder.build(); 110 } 111 } 112 } 113 return fieldValuesMap; 114 } 115 getFieldValue(String fieldName)116 public String getFieldValue(String fieldName) { 117 return getFieldValuesMap().get(fieldName); 118 } 119 120 @Override toString()121 public String toString() { 122 return BILLING_ACCOUNT.instantiate("billing_account", billingAccount); 123 } 124 125 @Override equals(Object o)126 public boolean equals(Object o) { 127 if (o == this) { 128 return true; 129 } 130 if (o != null || getClass() == o.getClass()) { 131 BillingAccountName that = ((BillingAccountName) o); 132 return Objects.equals(this.billingAccount, that.billingAccount); 133 } 134 return false; 135 } 136 137 @Override hashCode()138 public int hashCode() { 139 int h = 1; 140 h *= 1000003; 141 h ^= Objects.hashCode(billingAccount); 142 return h; 143 } 144 145 /** Builder for billingAccounts/{billing_account}. */ 146 public static class Builder { 147 private String billingAccount; 148 Builder()149 protected Builder() {} 150 getBillingAccount()151 public String getBillingAccount() { 152 return billingAccount; 153 } 154 setBillingAccount(String billingAccount)155 public Builder setBillingAccount(String billingAccount) { 156 this.billingAccount = billingAccount; 157 return this; 158 } 159 Builder(BillingAccountName billingAccountName)160 private Builder(BillingAccountName billingAccountName) { 161 this.billingAccount = billingAccountName.billingAccount; 162 } 163 build()164 public BillingAccountName build() { 165 return new BillingAccountName(this); 166 } 167 } 168 } 169