19
19
20
20
package co .elastic .clients .elasticsearch ._types .aggregations ;
21
21
22
- import co .elastic .clients .json .JsonEnum ;
23
22
import co .elastic .clients .json .JsonpDeserializable ;
24
23
import co .elastic .clients .json .JsonpDeserializer ;
25
24
import co .elastic .clients .json .JsonpMapper ;
26
25
import co .elastic .clients .json .JsonpSerializable ;
27
26
import co .elastic .clients .json .JsonpUtils ;
27
+ import co .elastic .clients .json .ObjectBuilderDeserializer ;
28
28
import co .elastic .clients .json .ObjectDeserializer ;
29
- import co .elastic .clients .json .UnionDeserializer ;
30
- import co .elastic .clients .util .ApiTypeHelper ;
31
29
import co .elastic .clients .util .ObjectBuilder ;
32
- import co .elastic .clients .util .ObjectBuilderBase ;
33
- import co .elastic .clients .util .TaggedUnion ;
34
- import co .elastic .clients .util .TaggedUnionUtils ;
30
+ import co .elastic .clients .util .WithJsonObjectBuilderBase ;
35
31
import jakarta .json .stream .JsonGenerator ;
32
+ import java .lang .Double ;
33
+ import java .lang .String ;
36
34
import java .util .Objects ;
37
35
import java .util .function .Function ;
38
36
import javax .annotation .Nullable ;
61
59
* specification</a>
62
60
*/
63
61
@ JsonpDeserializable
64
- public class AggregationRange
65
- implements
66
- TaggedUnion <AggregationRange .Kind , AggregationRangeVariant >,
67
- JsonpSerializable {
62
+ public class AggregationRange implements JsonpSerializable {
63
+ @ Nullable
64
+ private final Double from ;
68
65
69
- /**
70
- * {@link AggregationRange} variant kinds.
71
- *
72
- * @see <a href=
73
- * "../../doc-files/api-spec.html#_types.aggregations.AggregationRange">API
74
- * specification</a>
75
- */
76
-
77
- public enum Kind implements JsonEnum {
78
- Date ("date" ),
79
-
80
- Number ("number" ),
81
-
82
- Term ("term" ),
83
-
84
- Untyped ("untyped" ),
85
-
86
- ;
87
-
88
- private final String jsonValue ;
66
+ @ Nullable
67
+ private final String key ;
89
68
90
- Kind (String jsonValue ) {
91
- this .jsonValue = jsonValue ;
92
- }
93
-
94
- public String jsonValue () {
95
- return this .jsonValue ;
96
- }
97
-
98
- }
99
-
100
- private final Kind _kind ;
101
- private final AggregationRangeVariant _value ;
69
+ @ Nullable
70
+ private final Double to ;
102
71
103
- @ Override
104
- public final Kind _kind () {
105
- return _kind ;
106
- }
107
-
108
- @ Override
109
- public final AggregationRangeVariant _get () {
110
- return _value ;
111
- }
112
-
113
- public AggregationRange (AggregationRangeVariant value ) {
114
-
115
- this ._kind = ApiTypeHelper .requireNonNull (value ._aggregationRangeKind (), this , "<variant kind>" );
116
- this ._value = ApiTypeHelper .requireNonNull (value , this , "<variant value>" );
117
-
118
- }
119
-
120
- private AggregationRange (Kind kind , AggregationRangeVariant value ) {
121
- this ._kind = kind ;
122
- this ._value = value ;
123
- }
72
+ // ---------------------------------------------------------------------------------------------
124
73
125
74
private AggregationRange (Builder builder ) {
126
75
127
- this ._kind = ApiTypeHelper .requireNonNull (builder ._kind , builder , "<variant kind>" );
128
- this ._value = ApiTypeHelper .requireNonNull (builder ._value , builder , "<variant value>" );
76
+ this .from = builder .from ;
77
+ this .key = builder .key ;
78
+ this .to = builder .to ;
129
79
130
80
}
131
81
@@ -134,77 +84,61 @@ public static AggregationRange of(Function<Builder, ObjectBuilder<AggregationRan
134
84
}
135
85
136
86
/**
137
- * Is this variant instance of kind {@code date}?
87
+ * Start of the range (inclusive).
88
+ * <p>
89
+ * API name: {@code from}
138
90
*/
139
- public boolean isDate () {
140
- return _kind == Kind .Date ;
91
+ @ Nullable
92
+ public final Double from () {
93
+ return this .from ;
141
94
}
142
95
143
96
/**
144
- * Get the {@code date} variant value.
145
- *
146
- * @throws IllegalStateException
147
- * if the current variant is not of the {@code date} kind.
97
+ * Custom key to return the range with.
98
+ * <p>
99
+ * API name: {@code key}
148
100
*/
149
- public DateAggregationRange date () {
150
- return TaggedUnionUtils .get (this , Kind .Date );
101
+ @ Nullable
102
+ public final String key () {
103
+ return this .key ;
151
104
}
152
105
153
106
/**
154
- * Is this variant instance of kind {@code number}?
107
+ * End of the range (exclusive).
108
+ * <p>
109
+ * API name: {@code to}
155
110
*/
156
- public boolean isNumber () {
157
- return _kind == Kind .Number ;
111
+ @ Nullable
112
+ public final Double to () {
113
+ return this .to ;
158
114
}
159
115
160
116
/**
161
- * Get the {@code number} variant value.
162
- *
163
- * @throws IllegalStateException
164
- * if the current variant is not of the {@code number} kind.
117
+ * Serialize this object to JSON.
165
118
*/
166
- public NumberAggregationRange number () {
167
- return TaggedUnionUtils .get (this , Kind .Number );
168
- }
169
-
170
- /**
171
- * Is this variant instance of kind {@code term}?
172
- */
173
- public boolean isTerm () {
174
- return _kind == Kind .Term ;
119
+ public void serialize (JsonGenerator generator , JsonpMapper mapper ) {
120
+ generator .writeStartObject ();
121
+ serializeInternal (generator , mapper );
122
+ generator .writeEnd ();
175
123
}
176
124
177
- /**
178
- * Get the {@code term} variant value.
179
- *
180
- * @throws IllegalStateException
181
- * if the current variant is not of the {@code term} kind.
182
- */
183
- public TermAggregationRange term () {
184
- return TaggedUnionUtils .get (this , Kind .Term );
185
- }
125
+ protected void serializeInternal (JsonGenerator generator , JsonpMapper mapper ) {
186
126
187
- /**
188
- * Is this variant instance of kind {@code untyped}?
189
- */
190
- public boolean isUntyped () {
191
- return _kind == Kind .Untyped ;
192
- }
127
+ if (this .from != null ) {
128
+ generator .writeKey ("from" );
129
+ generator .write (this .from );
193
130
194
- /**
195
- * Get the {@code untyped} variant value.
196
- *
197
- * @throws IllegalStateException
198
- * if the current variant is not of the {@code untyped} kind.
199
- */
200
- public UntypedAggregationRange untyped () {
201
- return TaggedUnionUtils .get (this , Kind .Untyped );
202
- }
131
+ }
132
+ if (this .key != null ) {
133
+ generator .writeKey ("key" );
134
+ generator .write (this .key );
203
135
204
- @ Override
205
- public void serialize (JsonGenerator generator , JsonpMapper mapper ) {
136
+ }
137
+ if (this .to != null ) {
138
+ generator .writeKey ("to" );
139
+ generator .write (this .to );
206
140
207
- mapper . serialize ( _value , generator );
141
+ }
208
142
209
143
}
210
144
@@ -213,66 +147,84 @@ public String toString() {
213
147
return JsonpUtils .toString (this );
214
148
}
215
149
216
- public static class Builder extends ObjectBuilderBase implements ObjectBuilder <AggregationRange > {
217
- private Kind _kind ;
218
- private AggregationRangeVariant _value ;
150
+ // ---------------------------------------------------------------------------------------------
219
151
220
- public ObjectBuilder <AggregationRange > date (DateAggregationRange v ) {
221
- this ._kind = Kind .Date ;
222
- this ._value = v ;
223
- return this ;
224
- }
152
+ /**
153
+ * Builder for {@link AggregationRange}.
154
+ */
225
155
226
- public ObjectBuilder <AggregationRange > date (
227
- Function <DateAggregationRange .Builder , ObjectBuilder <DateAggregationRange >> fn ) {
228
- return this .date (fn .apply (new DateAggregationRange .Builder ()).build ());
229
- }
156
+ public static class Builder extends WithJsonObjectBuilderBase <Builder > implements ObjectBuilder <AggregationRange > {
157
+ @ Nullable
158
+ private Double from ;
230
159
231
- public ObjectBuilder <AggregationRange > number (NumberAggregationRange v ) {
232
- this ._kind = Kind .Number ;
233
- this ._value = v ;
234
- return this ;
235
- }
160
+ @ Nullable
161
+ private String key ;
236
162
237
- public ObjectBuilder <AggregationRange > number (
238
- Function <NumberAggregationRange .Builder , ObjectBuilder <NumberAggregationRange >> fn ) {
239
- return this .number (fn .apply (new NumberAggregationRange .Builder ()).build ());
240
- }
163
+ @ Nullable
164
+ private Double to ;
241
165
242
- public ObjectBuilder <AggregationRange > term (TermAggregationRange v ) {
243
- this ._kind = Kind .Term ;
244
- this ._value = v ;
166
+ /**
167
+ * Start of the range (inclusive).
168
+ * <p>
169
+ * API name: {@code from}
170
+ */
171
+ public final Builder from (@ Nullable Double value ) {
172
+ this .from = value ;
245
173
return this ;
246
174
}
247
175
248
- public ObjectBuilder <AggregationRange > term (
249
- Function <TermAggregationRange .Builder , ObjectBuilder <TermAggregationRange >> fn ) {
250
- return this .term (fn .apply (new TermAggregationRange .Builder ()).build ());
176
+ /**
177
+ * Custom key to return the range with.
178
+ * <p>
179
+ * API name: {@code key}
180
+ */
181
+ public final Builder key (@ Nullable String value ) {
182
+ this .key = value ;
183
+ return this ;
251
184
}
252
185
253
- public ObjectBuilder <AggregationRange > untyped (UntypedAggregationRange v ) {
254
- this ._kind = Kind .Untyped ;
255
- this ._value = v ;
186
+ /**
187
+ * End of the range (exclusive).
188
+ * <p>
189
+ * API name: {@code to}
190
+ */
191
+ public final Builder to (@ Nullable Double value ) {
192
+ this .to = value ;
256
193
return this ;
257
194
}
258
195
259
- public ObjectBuilder < AggregationRange > untyped (
260
- Function < UntypedAggregationRange . Builder , ObjectBuilder < UntypedAggregationRange >> fn ) {
261
- return this . untyped ( fn . apply ( new UntypedAggregationRange . Builder ()). build ()) ;
196
+ @ Override
197
+ protected Builder self ( ) {
198
+ return this ;
262
199
}
263
200
201
+ /**
202
+ * Builds a {@link AggregationRange}.
203
+ *
204
+ * @throws NullPointerException
205
+ * if some of the required fields are null.
206
+ */
264
207
public AggregationRange build () {
265
208
_checkSingleUse ();
209
+
266
210
return new AggregationRange (this );
267
211
}
268
-
269
212
}
270
213
271
- private static JsonpDeserializer <AggregationRange > buildAggregationRangeDeserializer () {
272
- return new UnionDeserializer .Builder <AggregationRange , Kind , AggregationRangeVariant >(AggregationRange ::new ,
273
- false ).addMember (Kind .Untyped , UntypedAggregationRange ._DESERIALIZER ).build ();
214
+ // ---------------------------------------------------------------------------------------------
215
+
216
+ /**
217
+ * Json deserializer for {@link AggregationRange}
218
+ */
219
+ public static final JsonpDeserializer <AggregationRange > _DESERIALIZER = ObjectBuilderDeserializer .lazy (Builder ::new ,
220
+ AggregationRange ::setupAggregationRangeDeserializer );
221
+
222
+ protected static void setupAggregationRangeDeserializer (ObjectDeserializer <AggregationRange .Builder > op ) {
223
+
224
+ op .add (Builder ::from , JsonpDeserializer .doubleDeserializer (), "from" );
225
+ op .add (Builder ::key , JsonpDeserializer .stringDeserializer (), "key" );
226
+ op .add (Builder ::to , JsonpDeserializer .doubleDeserializer (), "to" );
227
+
274
228
}
275
229
276
- public static final JsonpDeserializer <AggregationRange > _DESERIALIZER = JsonpDeserializer
277
- .lazy (AggregationRange ::buildAggregationRangeDeserializer );
278
230
}
0 commit comments