All Downloads are FREE. Search and download functionalities are using the official Maven repository.

co.elastic.clients.elasticsearch.sql.TranslateResponse Maven / Gradle / Ivy

/*
 * Licensed to Elasticsearch B.V. under one or more contributor
 * license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright
 * ownership. Elasticsearch B.V. licenses this file to you under
 * the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

//----------------------------------------------------
// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST.
//----------------------------------------------------

package co.elastic.clients.elasticsearch.sql;

import co.elastic.clients.elasticsearch._types.SortOptions;
import co.elastic.clients.elasticsearch.core.search.SourceConfig;
import co.elastic.clients.json.JsonpDeserializable;
import co.elastic.clients.json.JsonpDeserializer;
import co.elastic.clients.json.JsonpMapper;
import co.elastic.clients.json.JsonpSerializable;
import co.elastic.clients.json.ObjectBuilderDeserializer;
import co.elastic.clients.json.ObjectDeserializer;
import co.elastic.clients.util.ApiTypeHelper;
import co.elastic.clients.util.ObjectBuilder;
import co.elastic.clients.util.WithJsonObjectBuilderBase;
import jakarta.json.stream.JsonGenerator;
import java.lang.Long;
import java.lang.String;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import javax.annotation.Nullable;

// typedef: sql.translate.Response

/**
 *
 * @see API
 *      specification
 */
@JsonpDeserializable
public class TranslateResponse implements JsonpSerializable {
	private final long size;

	private final SourceConfig source;

	private final List> fields;

	private final List sort;

	// ---------------------------------------------------------------------------------------------

	private TranslateResponse(Builder builder) {

		this.size = ApiTypeHelper.requireNonNull(builder.size, this, "size");
		this.source = ApiTypeHelper.requireNonNull(builder.source, this, "source");
		this.fields = ApiTypeHelper.unmodifiableRequired(builder.fields, this, "fields");
		this.sort = ApiTypeHelper.unmodifiableRequired(builder.sort, this, "sort");

	}

	public static TranslateResponse of(Function> fn) {
		return fn.apply(new Builder()).build();
	}

	/**
	 * Required - API name: {@code size}
	 */
	public final long size() {
		return this.size;
	}

	/**
	 * Required - API name: {@code _source}
	 */
	public final SourceConfig source() {
		return this.source;
	}

	/**
	 * Required - API name: {@code fields}
	 */
	public final List> fields() {
		return this.fields;
	}

	/**
	 * Required - API name: {@code sort}
	 */
	public final List sort() {
		return this.sort;
	}

	/**
	 * Serialize this object to JSON.
	 */
	public void serialize(JsonGenerator generator, JsonpMapper mapper) {
		generator.writeStartObject();
		serializeInternal(generator, mapper);
		generator.writeEnd();
	}

	protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {

		generator.writeKey("size");
		generator.write(this.size);

		generator.writeKey("_source");
		this.source.serialize(generator, mapper);

		if (ApiTypeHelper.isDefined(this.fields)) {
			generator.writeKey("fields");
			generator.writeStartArray();
			for (Map item0 : this.fields) {
				generator.writeStartObject();
				if (item0 != null) {
					for (Map.Entry item1 : item0.entrySet()) {
						generator.writeKey(item1.getKey());
						generator.write(item1.getValue());

					}
				}
				generator.writeEnd();

			}
			generator.writeEnd();

		}
		if (ApiTypeHelper.isDefined(this.sort)) {
			generator.writeKey("sort");
			generator.writeStartArray();
			for (SortOptions item0 : this.sort) {
				item0.serialize(generator, mapper);

			}
			generator.writeEnd();

		}

	}

	// ---------------------------------------------------------------------------------------------

	/**
	 * Builder for {@link TranslateResponse}.
	 */

	public static class Builder extends WithJsonObjectBuilderBase implements ObjectBuilder {
		private Long size;

		private SourceConfig source;

		private List> fields;

		private List sort;

		/**
		 * Required - API name: {@code size}
		 */
		public final Builder size(long value) {
			this.size = value;
			return this;
		}

		/**
		 * Required - API name: {@code _source}
		 */
		public final Builder source(SourceConfig value) {
			this.source = value;
			return this;
		}

		/**
		 * Required - API name: {@code _source}
		 */
		public final Builder source(Function> fn) {
			return this.source(fn.apply(new SourceConfig.Builder()).build());
		}

		/**
		 * Required - API name: {@code fields}
		 * 

* Adds all elements of list to fields. */ public final Builder fields(List> list) { this.fields = _listAddAll(this.fields, list); return this; } /** * Required - API name: {@code fields} *

* Adds one or more values to fields. */ public final Builder fields(Map value, Map... values) { this.fields = _listAdd(this.fields, value, values); return this; } /** * Required - API name: {@code sort} *

* Adds all elements of list to sort. */ public final Builder sort(List list) { this.sort = _listAddAll(this.sort, list); return this; } /** * Required - API name: {@code sort} *

* Adds one or more values to sort. */ public final Builder sort(SortOptions value, SortOptions... values) { this.sort = _listAdd(this.sort, value, values); return this; } /** * Required - API name: {@code sort} *

* Adds a value to sort using a builder lambda. */ public final Builder sort(Function> fn) { return sort(fn.apply(new SortOptions.Builder()).build()); } @Override protected Builder self() { return this; } /** * Builds a {@link TranslateResponse}. * * @throws NullPointerException * if some of the required fields are null. */ public TranslateResponse build() { _checkSingleUse(); return new TranslateResponse(this); } } // --------------------------------------------------------------------------------------------- /** * Json deserializer for {@link TranslateResponse} */ public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer .lazy(Builder::new, TranslateResponse::setupTranslateResponseDeserializer); protected static void setupTranslateResponseDeserializer(ObjectDeserializer op) { op.add(Builder::size, JsonpDeserializer.longDeserializer(), "size"); op.add(Builder::source, SourceConfig._DESERIALIZER, "_source"); op.add(Builder::fields, JsonpDeserializer.arrayDeserializer( JsonpDeserializer.stringMapDeserializer(JsonpDeserializer.stringDeserializer())), "fields"); op.add(Builder::sort, JsonpDeserializer.arrayDeserializer(SortOptions._DESERIALIZER), "sort"); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy