23
23
24
24
package co .elastic .clients .elasticsearch ._types .aggregations ;
25
25
26
+ import co .elastic .clients .elasticsearch .ml .ClassificationInferenceOptions ;
27
+ import co .elastic .clients .elasticsearch .ml .RegressionInferenceOptions ;
28
+ import co .elastic .clients .json .JsonEnum ;
26
29
import co .elastic .clients .json .JsonpDeserializable ;
27
30
import co .elastic .clients .json .JsonpDeserializer ;
28
31
import co .elastic .clients .json .JsonpMapper ;
29
32
import co .elastic .clients .json .JsonpSerializable ;
30
33
import co .elastic .clients .json .ObjectBuilderDeserializer ;
31
34
import co .elastic .clients .json .ObjectDeserializer ;
35
+ import co .elastic .clients .util .ApiTypeHelper ;
32
36
import co .elastic .clients .util .ObjectBuilder ;
37
+ import co .elastic .clients .util .TaggedUnion ;
38
+ import co .elastic .clients .util .TaggedUnionUtils ;
33
39
import co .elastic .clients .util .WithJsonObjectBuilderBase ;
34
40
import jakarta .json .stream .JsonGenerator ;
41
+ import java .lang .Object ;
35
42
import java .util .Objects ;
36
43
import java .util .function .Function ;
37
44
import javax .annotation .Nullable ;
45
52
* specification</a>
46
53
*/
47
54
@ JsonpDeserializable
48
- public class InferenceConfig implements JsonpSerializable {
49
- @ Nullable
50
- private final RegressionInferenceOptions regression ;
55
+ public class InferenceConfig implements TaggedUnion <InferenceConfig .Kind , Object >, JsonpSerializable {
51
56
52
- @ Nullable
53
- private final ClassificationInferenceOptions classification ;
57
+ /**
58
+ * {@link InferenceConfig} variant kinds.
59
+ */
60
+ /**
61
+ * {@link InferenceConfig} variant kinds.
62
+ *
63
+ * @see <a href=
64
+ * "../../doc-files/api-spec.html#_types.aggregations.InferenceConfigContainer">API
65
+ * specification</a>
66
+ */
67
+
68
+ public enum Kind implements JsonEnum {
69
+ Regression ("regression" ),
70
+
71
+ Classification ("classification" ),
72
+
73
+ ;
74
+
75
+ private final String jsonValue ;
76
+
77
+ Kind (String jsonValue ) {
78
+ this .jsonValue = jsonValue ;
79
+ }
80
+
81
+ public String jsonValue () {
82
+ return this .jsonValue ;
83
+ }
84
+
85
+ }
54
86
55
- // ---------------------------------------------------------------------------------------------
87
+ private final Kind _kind ;
88
+ private final Object _value ;
89
+
90
+ @ Override
91
+ public final Kind _kind () {
92
+ return _kind ;
93
+ }
94
+
95
+ @ Override
96
+ public final Object _get () {
97
+ return _value ;
98
+ }
99
+
100
+ public InferenceConfig (InferenceConfigVariant value ) {
101
+
102
+ this ._kind = ApiTypeHelper .requireNonNull (value ._inferenceConfigKind (), this , "<variant kind>" );
103
+ this ._value = ApiTypeHelper .requireNonNull (value , this , "<variant value>" );
104
+
105
+ }
56
106
57
107
private InferenceConfig (Builder builder ) {
58
108
59
- this .regression = builder .regression ;
60
- this .classification = builder .classification ;
109
+ this ._kind = ApiTypeHelper . requireNonNull ( builder ._kind , builder , "<variant kind>" ) ;
110
+ this ._value = ApiTypeHelper . requireNonNull ( builder ._value , builder , "<variant value>" ) ;
61
111
62
112
}
63
113
@@ -66,133 +116,98 @@ public static InferenceConfig of(Function<Builder, ObjectBuilder<InferenceConfig
66
116
}
67
117
68
118
/**
69
- * Regression configuration for inference.
70
- * <p>
71
- * API name: {@code regression}
119
+ * Is this variant instance of kind {@code regression}?
72
120
*/
73
- @ Nullable
74
- public final RegressionInferenceOptions regression () {
75
- return this .regression ;
121
+ public boolean isRegression () {
122
+ return _kind == Kind .Regression ;
76
123
}
77
124
78
125
/**
79
- * Classification configuration for inference.
80
- * <p>
81
- * API name: {@code classification}
126
+ * Get the {@code regression} variant value.
127
+ *
128
+ * @throws IllegalStateException
129
+ * if the current variant is not of the {@code regression} kind.
82
130
*/
83
- @ Nullable
84
- public final ClassificationInferenceOptions classification () {
85
- return this .classification ;
131
+ public RegressionInferenceOptions regression () {
132
+ return TaggedUnionUtils .get (this , Kind .Regression );
86
133
}
87
134
88
135
/**
89
- * Serialize this object to JSON.
136
+ * Is this variant instance of kind {@code classification}?
90
137
*/
91
- public void serialize (JsonGenerator generator , JsonpMapper mapper ) {
92
- generator .writeStartObject ();
93
- serializeInternal (generator , mapper );
94
- generator .writeEnd ();
138
+ public boolean isClassification () {
139
+ return _kind == Kind .Classification ;
95
140
}
96
141
97
- protected void serializeInternal (JsonGenerator generator , JsonpMapper mapper ) {
142
+ /**
143
+ * Get the {@code classification} variant value.
144
+ *
145
+ * @throws IllegalStateException
146
+ * if the current variant is not of the {@code classification} kind.
147
+ */
148
+ public ClassificationInferenceOptions classification () {
149
+ return TaggedUnionUtils .get (this , Kind .Classification );
150
+ }
98
151
99
- if ( this . regression != null ) {
100
- generator . writeKey ( "regression" );
101
- this . regression . serialize (generator , mapper );
152
+ @ Override
153
+ @ SuppressWarnings ( "unchecked" )
154
+ public void serialize (JsonGenerator generator , JsonpMapper mapper ) {
102
155
103
- }
104
- if (this .classification != null ) {
105
- generator .writeKey ("classification" );
106
- this .classification .serialize (generator , mapper );
156
+ generator .writeStartObject ();
107
157
158
+ generator .writeKey (_kind .jsonValue ());
159
+ if (_value instanceof JsonpSerializable ) {
160
+ ((JsonpSerializable ) _value ).serialize (generator , mapper );
108
161
}
109
162
110
- }
111
-
112
- // ---------------------------------------------------------------------------------------------
163
+ generator .writeEnd ();
113
164
114
- /**
115
- * Builder for {@link InferenceConfig}.
116
- */
165
+ }
117
166
118
167
public static class Builder extends WithJsonObjectBuilderBase <Builder > implements ObjectBuilder <InferenceConfig > {
119
- @ Nullable
120
- private RegressionInferenceOptions regression ;
121
-
122
- @ Nullable
123
- private ClassificationInferenceOptions classification ;
124
-
125
- /**
126
- * Regression configuration for inference.
127
- * <p>
128
- * API name: {@code regression}
129
- */
130
- public final Builder regression (@ Nullable RegressionInferenceOptions value ) {
131
- this .regression = value ;
168
+ private Kind _kind ;
169
+ private Object _value ;
170
+
171
+ @ Override
172
+ protected Builder self () {
173
+ return this ;
174
+ }
175
+ public ObjectBuilder <InferenceConfig > regression (RegressionInferenceOptions v ) {
176
+ this ._kind = Kind .Regression ;
177
+ this ._value = v ;
132
178
return this ;
133
179
}
134
180
135
- /**
136
- * Regression configuration for inference.
137
- * <p>
138
- * API name: {@code regression}
139
- */
140
- public final Builder regression (
181
+ public ObjectBuilder <InferenceConfig > regression (
141
182
Function <RegressionInferenceOptions .Builder , ObjectBuilder <RegressionInferenceOptions >> fn ) {
142
183
return this .regression (fn .apply (new RegressionInferenceOptions .Builder ()).build ());
143
184
}
144
185
145
- /**
146
- * Classification configuration for inference.
147
- * <p>
148
- * API name: {@code classification}
149
- */
150
- public final Builder classification (@ Nullable ClassificationInferenceOptions value ) {
151
- this .classification = value ;
186
+ public ObjectBuilder <InferenceConfig > classification (ClassificationInferenceOptions v ) {
187
+ this ._kind = Kind .Classification ;
188
+ this ._value = v ;
152
189
return this ;
153
190
}
154
191
155
- /**
156
- * Classification configuration for inference.
157
- * <p>
158
- * API name: {@code classification}
159
- */
160
- public final Builder classification (
192
+ public ObjectBuilder <InferenceConfig > classification (
161
193
Function <ClassificationInferenceOptions .Builder , ObjectBuilder <ClassificationInferenceOptions >> fn ) {
162
194
return this .classification (fn .apply (new ClassificationInferenceOptions .Builder ()).build ());
163
195
}
164
196
165
- @ Override
166
- protected Builder self () {
167
- return this ;
168
- }
169
-
170
- /**
171
- * Builds a {@link InferenceConfig}.
172
- *
173
- * @throws NullPointerException
174
- * if some of the required fields are null.
175
- */
176
197
public InferenceConfig build () {
177
198
_checkSingleUse ();
178
-
179
199
return new InferenceConfig (this );
180
200
}
181
- }
182
201
183
- // ---------------------------------------------------------------------------------------------
184
-
185
- /**
186
- * Json deserializer for {@link InferenceConfig}
187
- */
188
- public static final JsonpDeserializer <InferenceConfig > _DESERIALIZER = ObjectBuilderDeserializer .lazy (Builder ::new ,
189
- InferenceConfig ::setupInferenceConfigDeserializer );
202
+ }
190
203
191
- protected static void setupInferenceConfigDeserializer (ObjectDeserializer <InferenceConfig . Builder > op ) {
204
+ protected static void setupInferenceConfigDeserializer (ObjectDeserializer <Builder > op ) {
192
205
193
206
op .add (Builder ::regression , RegressionInferenceOptions ._DESERIALIZER , "regression" );
194
207
op .add (Builder ::classification , ClassificationInferenceOptions ._DESERIALIZER , "classification" );
195
208
196
209
}
197
210
211
+ public static final JsonpDeserializer <InferenceConfig > _DESERIALIZER = ObjectBuilderDeserializer .lazy (Builder ::new ,
212
+ InferenceConfig ::setupInferenceConfigDeserializer , Builder ::build );
198
213
}
0 commit comments