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

io.resys.hdes.client.api.ImmutableCreateEntity Maven / Gradle / Ivy

There is a newer version: 3.130.78
Show newest version
package io.resys.hdes.client.api;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import io.resys.hdes.client.api.ast.AstBody;
import io.resys.hdes.client.api.ast.AstCommand;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.value.Generated;

/**
 * Immutable implementation of {@link HdesComposer.CreateEntity}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableCreateEntity.builder()}. */ @Generated(from = "HdesComposer.CreateEntity", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue public final class ImmutableCreateEntity implements HdesComposer.CreateEntity { private final @Nullable String name; private final @Nullable String desc; private final AstBody.AstBodyType type; private final ImmutableList body; private ImmutableCreateEntity( @Nullable String name, @Nullable String desc, AstBody.AstBodyType type, ImmutableList body) { this.name = name; this.desc = desc; this.type = type; this.body = body; } /** * @return The value of the {@code name} attribute */ @JsonProperty("name") @Override public @Nullable String getName() { return name; } /** * @return The value of the {@code desc} attribute */ @JsonProperty("desc") @Override public @Nullable String getDesc() { return desc; } /** * @return The value of the {@code type} attribute */ @JsonProperty("type") @Override public AstBody.AstBodyType getType() { return type; } /** * @return The value of the {@code body} attribute */ @JsonProperty("body") @Override public ImmutableList getBody() { return body; } /** * Copy the current immutable object by setting a value for the {@link HdesComposer.CreateEntity#getName() name} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for name (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableCreateEntity withName(@Nullable String value) { if (Objects.equals(this.name, value)) return this; return new ImmutableCreateEntity(value, this.desc, this.type, this.body); } /** * Copy the current immutable object by setting a value for the {@link HdesComposer.CreateEntity#getDesc() desc} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for desc (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableCreateEntity withDesc(@Nullable String value) { if (Objects.equals(this.desc, value)) return this; return new ImmutableCreateEntity(this.name, value, this.type, this.body); } /** * Copy the current immutable object by setting a value for the {@link HdesComposer.CreateEntity#getType() type} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for type * @return A modified copy of the {@code this} object */ public final ImmutableCreateEntity withType(AstBody.AstBodyType value) { if (this.type == value) return this; AstBody.AstBodyType newValue = Objects.requireNonNull(value, "type"); if (this.type.equals(newValue)) return this; return new ImmutableCreateEntity(this.name, this.desc, newValue, this.body); } /** * Copy the current immutable object with elements that replace the content of {@link HdesComposer.CreateEntity#getBody() body}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableCreateEntity withBody(AstCommand... elements) { ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableCreateEntity(this.name, this.desc, this.type, newValue); } /** * Copy the current immutable object with elements that replace the content of {@link HdesComposer.CreateEntity#getBody() body}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of body elements to set * @return A modified copy of {@code this} object */ public final ImmutableCreateEntity withBody(Iterable elements) { if (this.body == elements) return this; ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableCreateEntity(this.name, this.desc, this.type, newValue); } /** * This instance is equal to all instances of {@code ImmutableCreateEntity} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(@Nullable Object another) { if (this == another) return true; return another instanceof ImmutableCreateEntity && equalTo((ImmutableCreateEntity) another); } private boolean equalTo(ImmutableCreateEntity another) { return Objects.equals(name, another.name) && Objects.equals(desc, another.desc) && type.equals(another.type) && body.equals(another.body); } /** * Computes a hash code from attributes: {@code name}, {@code desc}, {@code type}, {@code body}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + Objects.hashCode(name); h += (h << 5) + Objects.hashCode(desc); h += (h << 5) + type.hashCode(); h += (h << 5) + body.hashCode(); return h; } /** * Prints the immutable value {@code CreateEntity} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("CreateEntity") .omitNullValues() .add("name", name) .add("desc", desc) .add("type", type) .add("body", body) .toString(); } /** * Utility type used to correctly read immutable object from JSON representation. * @deprecated Do not use this type directly, it exists only for the Jackson-binding infrastructure */ @Generated(from = "HdesComposer.CreateEntity", generator = "Immutables") @Deprecated @SuppressWarnings("Immutable") @JsonDeserialize @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE) static final class Json implements HdesComposer.CreateEntity { @Nullable String name; @Nullable String desc; @Nullable AstBody.AstBodyType type; @Nullable List body = ImmutableList.of(); @JsonProperty("name") public void setName(@Nullable String name) { this.name = name; } @JsonProperty("desc") public void setDesc(@Nullable String desc) { this.desc = desc; } @JsonProperty("type") public void setType(AstBody.AstBodyType type) { this.type = type; } @JsonProperty("body") public void setBody(List body) { this.body = body; } @Override public String getName() { throw new UnsupportedOperationException(); } @Override public String getDesc() { throw new UnsupportedOperationException(); } @Override public AstBody.AstBodyType getType() { throw new UnsupportedOperationException(); } @Override public List getBody() { throw new UnsupportedOperationException(); } } /** * @param json A JSON-bindable data structure * @return An immutable value type * @deprecated Do not use this method directly, it exists only for the Jackson-binding infrastructure */ @Deprecated @JsonCreator(mode = JsonCreator.Mode.DELEGATING) static ImmutableCreateEntity fromJson(Json json) { ImmutableCreateEntity.Builder builder = ImmutableCreateEntity.builder(); if (json.name != null) { builder.name(json.name); } if (json.desc != null) { builder.desc(json.desc); } if (json.type != null) { builder.type(json.type); } if (json.body != null) { builder.addAllBody(json.body); } return builder.build(); } /** * Creates an immutable copy of a {@link HdesComposer.CreateEntity} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable CreateEntity instance */ public static ImmutableCreateEntity copyOf(HdesComposer.CreateEntity instance) { if (instance instanceof ImmutableCreateEntity) { return (ImmutableCreateEntity) instance; } return ImmutableCreateEntity.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableCreateEntity ImmutableCreateEntity}. *

   * ImmutableCreateEntity.builder()
   *    .name(String | null) // nullable {@link HdesComposer.CreateEntity#getName() name}
   *    .desc(String | null) // nullable {@link HdesComposer.CreateEntity#getDesc() desc}
   *    .type(io.resys.hdes.client.api.ast.AstBody.AstBodyType) // required {@link HdesComposer.CreateEntity#getType() type}
   *    .addBody|addAllBody(io.resys.hdes.client.api.ast.AstCommand) // {@link HdesComposer.CreateEntity#getBody() body} elements
   *    .build();
   * 
* @return A new ImmutableCreateEntity builder */ public static ImmutableCreateEntity.Builder builder() { return new ImmutableCreateEntity.Builder(); } /** * Builds instances of type {@link ImmutableCreateEntity ImmutableCreateEntity}. * Initialize attributes and then invoke the {@link #build()} method to create an * immutable instance. *

{@code Builder} is not thread-safe and generally should not be stored in a field or collection, * but instead used immediately to create instances. */ @Generated(from = "HdesComposer.CreateEntity", generator = "Immutables") @NotThreadSafe public static final class Builder { private static final long INIT_BIT_TYPE = 0x1L; private long initBits = 0x1L; private @Nullable String name; private @Nullable String desc; private @Nullable AstBody.AstBodyType type; private ImmutableList.Builder body = ImmutableList.builder(); private Builder() { } /** * Fill a builder with attribute values from the provided {@code CreateEntity} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * Collection elements and entries will be added, not replaced. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder from(HdesComposer.CreateEntity instance) { Objects.requireNonNull(instance, "instance"); @Nullable String nameValue = instance.getName(); if (nameValue != null) { name(nameValue); } @Nullable String descValue = instance.getDesc(); if (descValue != null) { desc(descValue); } type(instance.getType()); addAllBody(instance.getBody()); return this; } /** * Initializes the value for the {@link HdesComposer.CreateEntity#getName() name} attribute. * @param name The value for name (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("name") public final Builder name(@Nullable String name) { this.name = name; return this; } /** * Initializes the value for the {@link HdesComposer.CreateEntity#getDesc() desc} attribute. * @param desc The value for desc (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("desc") public final Builder desc(@Nullable String desc) { this.desc = desc; return this; } /** * Initializes the value for the {@link HdesComposer.CreateEntity#getType() type} attribute. * @param type The value for type * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("type") public final Builder type(AstBody.AstBodyType type) { this.type = Objects.requireNonNull(type, "type"); initBits &= ~INIT_BIT_TYPE; return this; } /** * Adds one element to {@link HdesComposer.CreateEntity#getBody() body} list. * @param element A body element * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addBody(AstCommand element) { this.body.add(element); return this; } /** * Adds elements to {@link HdesComposer.CreateEntity#getBody() body} list. * @param elements An array of body elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addBody(AstCommand... elements) { this.body.add(elements); return this; } /** * Sets or replaces all elements for {@link HdesComposer.CreateEntity#getBody() body} list. * @param elements An iterable of body elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("body") public final Builder body(Iterable elements) { this.body = ImmutableList.builder(); return addAllBody(elements); } /** * Adds elements to {@link HdesComposer.CreateEntity#getBody() body} list. * @param elements An iterable of body elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAllBody(Iterable elements) { this.body.addAll(elements); return this; } /** * Builds a new {@link ImmutableCreateEntity ImmutableCreateEntity}. * @return An immutable instance of CreateEntity * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableCreateEntity build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableCreateEntity(name, desc, type, body.build()); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_TYPE) != 0) attributes.add("type"); return "Cannot build CreateEntity, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy