Skip to content

Commit

Permalink
Generate CharFilter variants
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia committed Nov 12, 2024
1 parent c55b24f commit 14d27fd
Show file tree
Hide file tree
Showing 12 changed files with 295 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,21 @@
* GitHub history for details.
*/

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

package org.opensearch.client.opensearch._types.analysis;

import jakarta.json.stream.JsonGenerator;
import java.util.Objects;
import java.util.function.Function;
import javax.annotation.Generated;
import org.opensearch.client.json.JsonpDeserializable;
import org.opensearch.client.json.JsonpDeserializer;
import org.opensearch.client.json.JsonpMapper;
import org.opensearch.client.json.JsonpSerializable;
import org.opensearch.client.json.PlainJsonSerializable;
import org.opensearch.client.json.UnionDeserializer;
import org.opensearch.client.util.ApiTypeHelper;
import org.opensearch.client.util.ObjectBuilder;
Expand All @@ -48,12 +55,14 @@
// typedef: _types.analysis.CharFilter

@JsonpDeserializable
public class CharFilter implements TaggedUnion<CharFilter.Kind, Object>, JsonpSerializable {

@Generated("org.opensearch.client.codegen.CodeGenerator")
public class CharFilter implements TaggedUnion<CharFilter.Kind, Object>, PlainJsonSerializable {
/**
* {@link CharFilter} variant kinds.
*/
public enum Kind {
Definition,
Name

}

private final Kind _kind;
Expand All @@ -75,13 +84,11 @@ private CharFilter(Kind kind, Object value) {
}

private CharFilter(Builder builder) {

this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, "<variant kind>");
this._value = ApiTypeHelper.requireNonNull(builder._value, builder, "<variant value>");

}

public static CharFilter of(Function<Builder, ObjectBuilder<CharFilter>> fn) {
public static CharFilter of(Function<CharFilter.Builder, ObjectBuilder<CharFilter>> fn) {
return fn.apply(new Builder()).build();
}

Expand All @@ -95,8 +102,7 @@ public boolean isDefinition() {
/**
* Get the {@code definition} variant value.
*
* @throws IllegalStateException
* if the current variant is not of the {@code definition} kind.
* @throws IllegalStateException if the current variant is not the {@code definition} kind.
*/
public CharFilterDefinition definition() {
return TaggedUnionUtils.get(this, Kind.Definition);
Expand All @@ -112,8 +118,7 @@ public boolean isName() {
/**
* Get the {@code name} variant value.
*
* @throws IllegalStateException
* if the current variant is not of the {@code name} kind.
* @throws IllegalStateException if the current variant is not the {@code name} kind.
*/
public String name() {
return TaggedUnionUtils.get(this, Kind.Name);
Expand All @@ -127,11 +132,9 @@ public void serialize(JsonGenerator generator, JsonpMapper mapper) {
switch (_kind) {
case Name:
generator.write(((String) this._value));

break;
}
}

}

public static class Builder extends ObjectBuilderBase implements ObjectBuilder<CharFilter> {
Expand All @@ -154,11 +157,11 @@ public ObjectBuilder<CharFilter> name(String v) {
return this;
}

@Override
public CharFilter build() {
_checkSingleUse();
return new CharFilter(this);
}

}

private static JsonpDeserializer<CharFilter> buildCharFilterDeserializer() {
Expand All @@ -169,4 +172,20 @@ private static JsonpDeserializer<CharFilter> buildCharFilterDeserializer() {
}

public static final JsonpDeserializer<CharFilter> _DESERIALIZER = JsonpDeserializer.lazy(CharFilter::buildCharFilterDeserializer);

@Override
public int hashCode() {
int result = 17;
result = 31 * result + Objects.hashCode(this._kind);
result = 31 * result + Objects.hashCode(this._value);
return result;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || this.getClass() != o.getClass()) return false;
CharFilter other = (CharFilter) o;
return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@
* GitHub history for details.
*/

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

package org.opensearch.client.opensearch._types.analysis;

import jakarta.json.stream.JsonGenerator;
import java.util.Objects;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import org.opensearch.client.json.JsonpDeserializer;
import org.opensearch.client.json.JsonpMapper;
Expand All @@ -42,16 +48,16 @@

// typedef: _types.analysis.CharFilterBase

@Generated("org.opensearch.client.codegen.CodeGenerator")
public abstract class CharFilterBase implements PlainJsonSerializable {

@Nullable
private final String version;

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

protected CharFilterBase(AbstractBuilder<?> builder) {

this.version = builder.version;

}

/**
Expand All @@ -65,22 +71,22 @@ public final String version() {
/**
* Serialize this object to JSON.
*/
@Override
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
generator.writeStartObject();
serializeInternal(generator, mapper);
generator.writeEnd();
}

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {

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

}

}

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

protected abstract static class AbstractBuilder<BuilderT extends AbstractBuilder<BuilderT>> extends ObjectBuilderBase {
@Nullable
private String version;
Expand All @@ -94,14 +100,26 @@ public final BuilderT version(@Nullable String value) {
}

protected abstract BuilderT self();

}

// ---------------------------------------------------------------------------------------------
protected static <BuilderT extends AbstractBuilder<BuilderT>> void setupCharFilterBaseDeserializer(ObjectDeserializer<BuilderT> op) {

protected static <BuilderT extends AbstractBuilder<BuilderT>> void setupCharFilterBaseDeserializer(ObjectDeserializer<BuilderT> op) {
op.add(AbstractBuilder::version, JsonpDeserializer.stringDeserializer(), "version");
}

@Override
public int hashCode() {
int result = 17;
result = 31 * result + Objects.hashCode(this.version);
return result;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || this.getClass() != o.getClass()) return false;
CharFilterBase other = (CharFilterBase) o;
return Objects.equals(this.version, other.version);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,30 @@
* GitHub history for details.
*/

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

package org.opensearch.client.opensearch._types.analysis;

import javax.annotation.Generated;

/**
* <p>
* Builders for {@link CharFilter} variants.
* </p>
* <p>
* Variants <code>name</code> are not available here as they don't have a
* dedicated class. Use {@link CharFilter}'s builder for these.
*
* Variants <code>name</code> are not available here as they don't have a dedicated class. Use {@link CharFilter}'s builder for these.
* </p>
*/
@Generated("org.opensearch.client.codegen.CodeGenerator")
public class CharFilterBuilders {
private CharFilterBuilders() {}

/**
* Creates a builder for the {@link CharFilterDefinition definition}
* {@code CharFilter} variant.
* Creates a builder for the {@link CharFilterDefinition definition} {@code CharFilter} variant.
*/
public static CharFilterDefinition.Builder definition() {
return new CharFilterDefinition.Builder();
}

}
Loading

0 comments on commit 14d27fd

Please sign in to comment.