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

co.elastic.clients.elasticsearch.connector.Validation 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.
 */

package co.elastic.clients.elasticsearch.connector;

import co.elastic.clients.json.JsonEnum;
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.JsonpUtils;
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.TaggedUnion;
import co.elastic.clients.util.TaggedUnionUtils;
import co.elastic.clients.util.WithJsonObjectBuilderBase;
import jakarta.json.stream.JsonGenerator;
import java.util.Objects;
import java.util.function.Function;
import javax.annotation.Nullable;

//----------------------------------------------------------------
//       THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST.
//----------------------------------------------------------------
//
// This code is generated from the Elasticsearch API specification
// at https://github.com/elastic/elasticsearch-specification
//
// Manual updates to this file will be lost when the code is
// re-generated.
//
// If you find a property that is missing or wrongly typed, please
// open an issue or a PR on the API specification repository.
//
//----------------------------------------------------------------

// typedef: connector._types.Validation

/**
 *
 * @see API
 *      specification
 */
@JsonpDeserializable
public class Validation implements TaggedUnion, JsonpSerializable {

	/**
	 * {@link Validation} variant kinds.
	 * 
	 * @see API
	 *      specification
	 */

	public enum Kind implements JsonEnum {
		GreaterThan("greater_than"),

		IncludedIn("included_in"),

		LessThan("less_than"),

		ListType("list_type"),

		Regex("regex"),

		;

		private final String jsonValue;

		Kind(String jsonValue) {
			this.jsonValue = jsonValue;
		}

		public String jsonValue() {
			return this.jsonValue;
		}

	}

	private final Kind _kind;
	private final ValidationVariant _value;

	@Override
	public final Kind _kind() {
		return _kind;
	}

	@Override
	public final ValidationVariant _get() {
		return _value;
	}

	public Validation(ValidationVariant value) {

		this._kind = ApiTypeHelper.requireNonNull(value._validationKind(), this, "");
		this._value = ApiTypeHelper.requireNonNull(value, this, "");

	}

	private Validation(Builder builder) {

		this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, "");
		this._value = ApiTypeHelper.requireNonNull(builder._value, builder, "");

	}

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

	/**
	 * Is this variant instance of kind {@code greater_than}?
	 */
	public boolean isGreaterThan() {
		return _kind == Kind.GreaterThan;
	}

	/**
	 * Get the {@code greater_than} variant value.
	 *
	 * @throws IllegalStateException
	 *             if the current variant is not of the {@code greater_than} kind.
	 */
	public GreaterThanValidation greaterThan() {
		return TaggedUnionUtils.get(this, Kind.GreaterThan);
	}

	/**
	 * Is this variant instance of kind {@code included_in}?
	 */
	public boolean isIncludedIn() {
		return _kind == Kind.IncludedIn;
	}

	/**
	 * Get the {@code included_in} variant value.
	 *
	 * @throws IllegalStateException
	 *             if the current variant is not of the {@code included_in} kind.
	 */
	public IncludedInValidation includedIn() {
		return TaggedUnionUtils.get(this, Kind.IncludedIn);
	}

	/**
	 * Is this variant instance of kind {@code less_than}?
	 */
	public boolean isLessThan() {
		return _kind == Kind.LessThan;
	}

	/**
	 * Get the {@code less_than} variant value.
	 *
	 * @throws IllegalStateException
	 *             if the current variant is not of the {@code less_than} kind.
	 */
	public LessThanValidation lessThan() {
		return TaggedUnionUtils.get(this, Kind.LessThan);
	}

	/**
	 * Is this variant instance of kind {@code list_type}?
	 */
	public boolean isListType() {
		return _kind == Kind.ListType;
	}

	/**
	 * Get the {@code list_type} variant value.
	 *
	 * @throws IllegalStateException
	 *             if the current variant is not of the {@code list_type} kind.
	 */
	public ListTypeValidation listType() {
		return TaggedUnionUtils.get(this, Kind.ListType);
	}

	/**
	 * Is this variant instance of kind {@code regex}?
	 */
	public boolean isRegex() {
		return _kind == Kind.Regex;
	}

	/**
	 * Get the {@code regex} variant value.
	 *
	 * @throws IllegalStateException
	 *             if the current variant is not of the {@code regex} kind.
	 */
	public RegexValidation regex() {
		return TaggedUnionUtils.get(this, Kind.Regex);
	}

	@Override
	public void serialize(JsonGenerator generator, JsonpMapper mapper) {

		mapper.serialize(_value, generator);

	}

	@Override
	public String toString() {
		return JsonpUtils.toString(this);
	}

	public static class Builder extends WithJsonObjectBuilderBase implements ObjectBuilder {
		private Kind _kind;
		private ValidationVariant _value;

		@Override
		protected Builder self() {
			return this;
		}
		public ObjectBuilder greaterThan(GreaterThanValidation v) {
			this._kind = Kind.GreaterThan;
			this._value = v;
			return this;
		}

		public ObjectBuilder greaterThan(
				Function> fn) {
			return this.greaterThan(fn.apply(new GreaterThanValidation.Builder()).build());
		}

		public ObjectBuilder includedIn(IncludedInValidation v) {
			this._kind = Kind.IncludedIn;
			this._value = v;
			return this;
		}

		public ObjectBuilder includedIn(
				Function> fn) {
			return this.includedIn(fn.apply(new IncludedInValidation.Builder()).build());
		}

		public ObjectBuilder lessThan(LessThanValidation v) {
			this._kind = Kind.LessThan;
			this._value = v;
			return this;
		}

		public ObjectBuilder lessThan(
				Function> fn) {
			return this.lessThan(fn.apply(new LessThanValidation.Builder()).build());
		}

		public ObjectBuilder listType(ListTypeValidation v) {
			this._kind = Kind.ListType;
			this._value = v;
			return this;
		}

		public ObjectBuilder listType(
				Function> fn) {
			return this.listType(fn.apply(new ListTypeValidation.Builder()).build());
		}

		public ObjectBuilder regex(RegexValidation v) {
			this._kind = Kind.Regex;
			this._value = v;
			return this;
		}

		public ObjectBuilder regex(Function> fn) {
			return this.regex(fn.apply(new RegexValidation.Builder()).build());
		}

		public Validation build() {
			_checkSingleUse();
			return new Validation(this);
		}

	}

	protected static void setupValidationDeserializer(ObjectDeserializer op) {

		op.add(Builder::greaterThan, GreaterThanValidation._DESERIALIZER, "greater_than");
		op.add(Builder::includedIn, IncludedInValidation._DESERIALIZER, "included_in");
		op.add(Builder::lessThan, LessThanValidation._DESERIALIZER, "less_than");
		op.add(Builder::listType, ListTypeValidation._DESERIALIZER, "list_type");
		op.add(Builder::regex, RegexValidation._DESERIALIZER, "regex");

		op.setTypeProperty("type", null);

	}

	public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy(Builder::new,
			Validation::setupValidationDeserializer, Builder::build);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy