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