|
| 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.JsonpDeserializable; |
| 27 | +import co.elastic.clients.json.JsonpDeserializer; |
| 28 | +import co.elastic.clients.json.JsonpMapper; |
| 29 | +import co.elastic.clients.json.JsonpSerializable; |
| 30 | +import co.elastic.clients.json.ObjectDeserializer; |
| 31 | +import co.elastic.clients.json.UnionDeserializer; |
| 32 | +import co.elastic.clients.util.ApiTypeHelper; |
| 33 | +import co.elastic.clients.util.ObjectBuilder; |
| 34 | +import co.elastic.clients.util.ObjectBuilderBase; |
| 35 | +import co.elastic.clients.util.TaggedUnion; |
| 36 | +import co.elastic.clients.util.TaggedUnionUtils; |
| 37 | +import jakarta.json.stream.JsonGenerator; |
| 38 | +import java.lang.Integer; |
| 39 | +import java.lang.Object; |
| 40 | +import java.util.Objects; |
| 41 | +import java.util.function.Function; |
| 42 | +import javax.annotation.Nullable; |
| 43 | + |
| 44 | +// typedef: _types.Slices |
| 45 | + |
| 46 | +/** |
| 47 | + * Slices configuration used to parallelize a process. |
| 48 | + * |
| 49 | + * @see <a href="../doc-files/api-spec.html#_types.Slices">API specification</a> |
| 50 | + */ |
| 51 | +@JsonpDeserializable |
| 52 | +public class Slices implements TaggedUnion<Slices.Kind, Object>, JsonpSerializable { |
| 53 | + |
| 54 | + public enum Kind { |
| 55 | + Computed, Value |
| 56 | + |
| 57 | + } |
| 58 | + |
| 59 | + private final Kind _kind; |
| 60 | + private final Object _value; |
| 61 | + |
| 62 | + @Override |
| 63 | + public final Kind _kind() { |
| 64 | + return _kind; |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + public final Object _get() { |
| 69 | + return _value; |
| 70 | + } |
| 71 | + |
| 72 | + private Slices(Kind kind, Object value) { |
| 73 | + this._kind = kind; |
| 74 | + this._value = value; |
| 75 | + } |
| 76 | + |
| 77 | + public String _toJsonString() { |
| 78 | + switch (_kind) { |
| 79 | + case Computed : |
| 80 | + return this.computed().jsonValue(); |
| 81 | + case Value : |
| 82 | + return String.valueOf(this.value()); |
| 83 | + |
| 84 | + default : |
| 85 | + throw new IllegalStateException("Unknown kind " + _kind); |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + private Slices(Builder builder) { |
| 90 | + |
| 91 | + this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, "<variant kind>"); |
| 92 | + this._value = ApiTypeHelper.requireNonNull(builder._value, builder, "<variant value>"); |
| 93 | + |
| 94 | + } |
| 95 | + |
| 96 | + public static Slices of(Function<Builder, ObjectBuilder<Slices>> fn) { |
| 97 | + return fn.apply(new Builder()).build(); |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * Is this variant instance of kind {@code computed}? |
| 102 | + */ |
| 103 | + public boolean isComputed() { |
| 104 | + return _kind == Kind.Computed; |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Get the {@code computed} variant value. |
| 109 | + * |
| 110 | + * @throws IllegalStateException |
| 111 | + * if the current variant is not of the {@code computed} kind. |
| 112 | + */ |
| 113 | + public SlicesCalculation computed() { |
| 114 | + return TaggedUnionUtils.get(this, Kind.Computed); |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * Is this variant instance of kind {@code value}? |
| 119 | + */ |
| 120 | + public boolean isValue() { |
| 121 | + return _kind == Kind.Value; |
| 122 | + } |
| 123 | + |
| 124 | + /** |
| 125 | + * Get the {@code value} variant value. |
| 126 | + * |
| 127 | + * @throws IllegalStateException |
| 128 | + * if the current variant is not of the {@code value} kind. |
| 129 | + */ |
| 130 | + public Integer value() { |
| 131 | + return TaggedUnionUtils.get(this, Kind.Value); |
| 132 | + } |
| 133 | + |
| 134 | + @Override |
| 135 | + public void serialize(JsonGenerator generator, JsonpMapper mapper) { |
| 136 | + if (_value instanceof JsonpSerializable) { |
| 137 | + ((JsonpSerializable) _value).serialize(generator, mapper); |
| 138 | + } else { |
| 139 | + switch (_kind) { |
| 140 | + case Value : |
| 141 | + generator.write(((Integer) this._value)); |
| 142 | + |
| 143 | + break; |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + } |
| 148 | + |
| 149 | + public static class Builder extends ObjectBuilderBase implements ObjectBuilder<Slices> { |
| 150 | + private Kind _kind; |
| 151 | + private Object _value; |
| 152 | + |
| 153 | + public ObjectBuilder<Slices> computed(SlicesCalculation v) { |
| 154 | + this._kind = Kind.Computed; |
| 155 | + this._value = v; |
| 156 | + return this; |
| 157 | + } |
| 158 | + |
| 159 | + public ObjectBuilder<Slices> value(Integer v) { |
| 160 | + this._kind = Kind.Value; |
| 161 | + this._value = v; |
| 162 | + return this; |
| 163 | + } |
| 164 | + |
| 165 | + public Slices build() { |
| 166 | + _checkSingleUse(); |
| 167 | + return new Slices(this); |
| 168 | + } |
| 169 | + |
| 170 | + } |
| 171 | + |
| 172 | + private static JsonpDeserializer<Slices> buildSlicesDeserializer() { |
| 173 | + return new UnionDeserializer.Builder<Slices, Kind, Object>(Slices::new, false) |
| 174 | + .addMember(Kind.Computed, SlicesCalculation._DESERIALIZER) |
| 175 | + .addMember(Kind.Value, JsonpDeserializer.integerDeserializer()).build(); |
| 176 | + } |
| 177 | + |
| 178 | + public static final JsonpDeserializer<Slices> _DESERIALIZER = JsonpDeserializer |
| 179 | + .lazy(Slices::buildSlicesDeserializer); |
| 180 | +} |
0 commit comments