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