|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch B.V. under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch B.V. licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +//---------------------------------------------------- |
| 21 | +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. |
| 22 | +//---------------------------------------------------- |
| 23 | + |
| 24 | +package co.elastic.clients.elasticsearch._types; |
| 25 | + |
| 26 | +import co.elastic.clients.json.JsonEnum; |
| 27 | +import co.elastic.clients.json.JsonpDeserializable; |
| 28 | +import co.elastic.clients.json.JsonpDeserializer; |
| 29 | +import co.elastic.clients.json.JsonpMapper; |
| 30 | +import co.elastic.clients.json.JsonpSerializable; |
| 31 | +import co.elastic.clients.json.JsonpUtils; |
| 32 | +import co.elastic.clients.json.ObjectBuilderDeserializer; |
| 33 | +import co.elastic.clients.json.ObjectDeserializer; |
| 34 | +import co.elastic.clients.util.ApiTypeHelper; |
| 35 | +import co.elastic.clients.util.ObjectBuilder; |
| 36 | +import co.elastic.clients.util.TaggedUnion; |
| 37 | +import co.elastic.clients.util.TaggedUnionUtils; |
| 38 | +import co.elastic.clients.util.WithJsonObjectBuilderBase; |
| 39 | +import jakarta.json.stream.JsonGenerator; |
| 40 | +import java.lang.Object; |
| 41 | +import java.util.Objects; |
| 42 | +import java.util.function.Function; |
| 43 | +import javax.annotation.Nullable; |
| 44 | + |
| 45 | +// typedef: _types.RankContainer |
| 46 | + |
| 47 | +/** |
| 48 | + * |
| 49 | + * @see <a href="../doc-files/api-spec.html#_types.RankContainer">API |
| 50 | + * specification</a> |
| 51 | + */ |
| 52 | +@JsonpDeserializable |
| 53 | +public class Rank implements TaggedUnion<Rank.Kind, Object>, JsonpSerializable { |
| 54 | + |
| 55 | + /** |
| 56 | + * {@link Rank} variant kinds. |
| 57 | + * |
| 58 | + * @see <a href="../doc-files/api-spec.html#_types.RankContainer">API |
| 59 | + * specification</a> |
| 60 | + */ |
| 61 | + |
| 62 | + public enum Kind implements JsonEnum { |
| 63 | + Rrf("rrf"), |
| 64 | + |
| 65 | + ; |
| 66 | + |
| 67 | + private final String jsonValue; |
| 68 | + |
| 69 | + Kind(String jsonValue) { |
| 70 | + this.jsonValue = jsonValue; |
| 71 | + } |
| 72 | + |
| 73 | + public String jsonValue() { |
| 74 | + return this.jsonValue; |
| 75 | + } |
| 76 | + |
| 77 | + } |
| 78 | + |
| 79 | + private final Kind _kind; |
| 80 | + private final Object _value; |
| 81 | + |
| 82 | + @Override |
| 83 | + public final Kind _kind() { |
| 84 | + return _kind; |
| 85 | + } |
| 86 | + |
| 87 | + @Override |
| 88 | + public final Object _get() { |
| 89 | + return _value; |
| 90 | + } |
| 91 | + |
| 92 | + public Rank(RankVariant value) { |
| 93 | + |
| 94 | + this._kind = ApiTypeHelper.requireNonNull(value._rankKind(), this, "<variant kind>"); |
| 95 | + this._value = ApiTypeHelper.requireNonNull(value, this, "<variant value>"); |
| 96 | + |
| 97 | + } |
| 98 | + |
| 99 | + private Rank(Builder builder) { |
| 100 | + |
| 101 | + this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, "<variant kind>"); |
| 102 | + this._value = ApiTypeHelper.requireNonNull(builder._value, builder, "<variant value>"); |
| 103 | + |
| 104 | + } |
| 105 | + |
| 106 | + public static Rank of(Function<Builder, ObjectBuilder<Rank>> fn) { |
| 107 | + return fn.apply(new Builder()).build(); |
| 108 | + } |
| 109 | + |
| 110 | + /** |
| 111 | + * Is this variant instance of kind {@code rrf}? |
| 112 | + */ |
| 113 | + public boolean isRrf() { |
| 114 | + return _kind == Kind.Rrf; |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * Get the {@code rrf} variant value. |
| 119 | + * |
| 120 | + * @throws IllegalStateException |
| 121 | + * if the current variant is not of the {@code rrf} kind. |
| 122 | + */ |
| 123 | + public RrfRank rrf() { |
| 124 | + return TaggedUnionUtils.get(this, Kind.Rrf); |
| 125 | + } |
| 126 | + |
| 127 | + @Override |
| 128 | + @SuppressWarnings("unchecked") |
| 129 | + public void serialize(JsonGenerator generator, JsonpMapper mapper) { |
| 130 | + |
| 131 | + generator.writeStartObject(); |
| 132 | + |
| 133 | + generator.writeKey(_kind.jsonValue()); |
| 134 | + if (_value instanceof JsonpSerializable) { |
| 135 | + ((JsonpSerializable) _value).serialize(generator, mapper); |
| 136 | + } |
| 137 | + |
| 138 | + generator.writeEnd(); |
| 139 | + |
| 140 | + } |
| 141 | + |
| 142 | + @Override |
| 143 | + public String toString() { |
| 144 | + return JsonpUtils.toString(this); |
| 145 | + } |
| 146 | + |
| 147 | + public static class Builder extends WithJsonObjectBuilderBase<Builder> implements ObjectBuilder<Rank> { |
| 148 | + private Kind _kind; |
| 149 | + private Object _value; |
| 150 | + |
| 151 | + @Override |
| 152 | + protected Builder self() { |
| 153 | + return this; |
| 154 | + } |
| 155 | + public ObjectBuilder<Rank> rrf(RrfRank v) { |
| 156 | + this._kind = Kind.Rrf; |
| 157 | + this._value = v; |
| 158 | + return this; |
| 159 | + } |
| 160 | + |
| 161 | + public ObjectBuilder<Rank> rrf(Function<RrfRank.Builder, ObjectBuilder<RrfRank>> fn) { |
| 162 | + return this.rrf(fn.apply(new RrfRank.Builder()).build()); |
| 163 | + } |
| 164 | + |
| 165 | + public Rank build() { |
| 166 | + _checkSingleUse(); |
| 167 | + return new Rank(this); |
| 168 | + } |
| 169 | + |
| 170 | + } |
| 171 | + |
| 172 | + protected static void setupRankDeserializer(ObjectDeserializer<Builder> op) { |
| 173 | + |
| 174 | + op.add(Builder::rrf, RrfRank._DESERIALIZER, "rrf"); |
| 175 | + |
| 176 | + } |
| 177 | + |
| 178 | + public static final JsonpDeserializer<Rank> _DESERIALIZER = ObjectBuilderDeserializer.lazy(Builder::new, |
| 179 | + Rank::setupRankDeserializer, Builder::build); |
| 180 | +} |
0 commit comments