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

co.elastic.clients.elasticsearch.rollup.DateHistogramGrouping 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.rollup;

import co.elastic.clients.elasticsearch._types.Time;
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.String;
import java.util.Objects;
import java.util.function.Function;
import javax.annotation.Nullable;

// typedef: rollup._types.DateHistogramGrouping

/**
 *
 * @see API
 *      specification
 */
@JsonpDeserializable
public class DateHistogramGrouping implements JsonpSerializable {
	@Nullable
	private final Time delay;

	private final String field;

	@Nullable
	private final String format;

	@Nullable
	private final Time interval;

	@Nullable
	private final Time calendarInterval;

	@Nullable
	private final Time fixedInterval;

	@Nullable
	private final String timeZone;

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

	private DateHistogramGrouping(Builder builder) {

		this.delay = builder.delay;
		this.field = ApiTypeHelper.requireNonNull(builder.field, this, "field");
		this.format = builder.format;
		this.interval = builder.interval;
		this.calendarInterval = builder.calendarInterval;
		this.fixedInterval = builder.fixedInterval;
		this.timeZone = builder.timeZone;

	}

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

	/**
	 * API name: {@code delay}
	 */
	@Nullable
	public final Time delay() {
		return this.delay;
	}

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

	/**
	 * API name: {@code format}
	 */
	@Nullable
	public final String format() {
		return this.format;
	}

	/**
	 * API name: {@code interval}
	 */
	@Nullable
	public final Time interval() {
		return this.interval;
	}

	/**
	 * API name: {@code calendar_interval}
	 */
	@Nullable
	public final Time calendarInterval() {
		return this.calendarInterval;
	}

	/**
	 * API name: {@code fixed_interval}
	 */
	@Nullable
	public final Time fixedInterval() {
		return this.fixedInterval;
	}

	/**
	 * API name: {@code time_zone}
	 */
	@Nullable
	public final String timeZone() {
		return this.timeZone;
	}

	/**
	 * 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) {

		if (this.delay != null) {
			generator.writeKey("delay");
			this.delay.serialize(generator, mapper);

		}
		generator.writeKey("field");
		generator.write(this.field);

		if (this.format != null) {
			generator.writeKey("format");
			generator.write(this.format);

		}
		if (this.interval != null) {
			generator.writeKey("interval");
			this.interval.serialize(generator, mapper);

		}
		if (this.calendarInterval != null) {
			generator.writeKey("calendar_interval");
			this.calendarInterval.serialize(generator, mapper);

		}
		if (this.fixedInterval != null) {
			generator.writeKey("fixed_interval");
			this.fixedInterval.serialize(generator, mapper);

		}
		if (this.timeZone != null) {
			generator.writeKey("time_zone");
			generator.write(this.timeZone);

		}

	}

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

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

	public static class Builder extends WithJsonObjectBuilderBase
			implements
				ObjectBuilder {
		@Nullable
		private Time delay;

		private String field;

		@Nullable
		private String format;

		@Nullable
		private Time interval;

		@Nullable
		private Time calendarInterval;

		@Nullable
		private Time fixedInterval;

		@Nullable
		private String timeZone;

		/**
		 * API name: {@code delay}
		 */
		public final Builder delay(@Nullable Time value) {
			this.delay = value;
			return this;
		}

		/**
		 * API name: {@code delay}
		 */
		public final Builder delay(Function> fn) {
			return this.delay(fn.apply(new Time.Builder()).build());
		}

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

		/**
		 * API name: {@code format}
		 */
		public final Builder format(@Nullable String value) {
			this.format = value;
			return this;
		}

		/**
		 * API name: {@code interval}
		 */
		public final Builder interval(@Nullable Time value) {
			this.interval = value;
			return this;
		}

		/**
		 * API name: {@code interval}
		 */
		public final Builder interval(Function> fn) {
			return this.interval(fn.apply(new Time.Builder()).build());
		}

		/**
		 * API name: {@code calendar_interval}
		 */
		public final Builder calendarInterval(@Nullable Time value) {
			this.calendarInterval = value;
			return this;
		}

		/**
		 * API name: {@code calendar_interval}
		 */
		public final Builder calendarInterval(Function> fn) {
			return this.calendarInterval(fn.apply(new Time.Builder()).build());
		}

		/**
		 * API name: {@code fixed_interval}
		 */
		public final Builder fixedInterval(@Nullable Time value) {
			this.fixedInterval = value;
			return this;
		}

		/**
		 * API name: {@code fixed_interval}
		 */
		public final Builder fixedInterval(Function> fn) {
			return this.fixedInterval(fn.apply(new Time.Builder()).build());
		}

		/**
		 * API name: {@code time_zone}
		 */
		public final Builder timeZone(@Nullable String value) {
			this.timeZone = value;
			return this;
		}

		@Override
		protected Builder self() {
			return this;
		}

		/**
		 * Builds a {@link DateHistogramGrouping}.
		 *
		 * @throws NullPointerException
		 *             if some of the required fields are null.
		 */
		public DateHistogramGrouping build() {
			_checkSingleUse();

			return new DateHistogramGrouping(this);
		}
	}

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

	/**
	 * Json deserializer for {@link DateHistogramGrouping}
	 */
	public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer
			.lazy(Builder::new, DateHistogramGrouping::setupDateHistogramGroupingDeserializer);

	protected static void setupDateHistogramGroupingDeserializer(ObjectDeserializer op) {

		op.add(Builder::delay, Time._DESERIALIZER, "delay");
		op.add(Builder::field, JsonpDeserializer.stringDeserializer(), "field");
		op.add(Builder::format, JsonpDeserializer.stringDeserializer(), "format");
		op.add(Builder::interval, Time._DESERIALIZER, "interval");
		op.add(Builder::calendarInterval, Time._DESERIALIZER, "calendar_interval");
		op.add(Builder::fixedInterval, Time._DESERIALIZER, "fixed_interval");
		op.add(Builder::timeZone, JsonpDeserializer.stringDeserializer(), "time_zone");

	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy