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

io.resys.hdes.ast.api.nodes.ImmutableCommandInvocation Maven / Gradle / Ivy

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

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
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 ServiceNode.CommandInvocation}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableCommandInvocation.builder()}. */ @Generated(from = "ServiceNode.CommandInvocation", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") @Immutable public final class ImmutableCommandInvocation implements ServiceNode.CommandInvocation { private final HdesNode.Token token; private final InvocationNode className; private final MappingNode.ObjectMappingDef mapping; private final @Nullable ServiceNode.ServicePromise promise; private ImmutableCommandInvocation( HdesNode.Token token, InvocationNode className, MappingNode.ObjectMappingDef mapping, @Nullable ServiceNode.ServicePromise promise) { this.token = token; this.className = className; this.mapping = mapping; this.promise = promise; } /** * @return The value of the {@code token} attribute */ @Override public HdesNode.Token getToken() { return token; } /** * @return The value of the {@code className} attribute */ @Override public InvocationNode getClassName() { return className; } /** * @return The value of the {@code mapping} attribute */ @Override public MappingNode.ObjectMappingDef getMapping() { return mapping; } /** * @return The value of the {@code promise} attribute */ @Override public Optional getPromise() { return Optional.ofNullable(promise); } /** * Copy the current immutable object by setting a value for the {@link ServiceNode.CommandInvocation#getToken() token} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for token * @return A modified copy of the {@code this} object */ public final ImmutableCommandInvocation withToken(HdesNode.Token value) { if (this.token == value) return this; HdesNode.Token newValue = Objects.requireNonNull(value, "token"); return new ImmutableCommandInvocation(newValue, this.className, this.mapping, this.promise); } /** * Copy the current immutable object by setting a value for the {@link ServiceNode.CommandInvocation#getClassName() className} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for className * @return A modified copy of the {@code this} object */ public final ImmutableCommandInvocation withClassName(InvocationNode value) { if (this.className == value) return this; InvocationNode newValue = Objects.requireNonNull(value, "className"); return new ImmutableCommandInvocation(this.token, newValue, this.mapping, this.promise); } /** * Copy the current immutable object by setting a value for the {@link ServiceNode.CommandInvocation#getMapping() mapping} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for mapping * @return A modified copy of the {@code this} object */ public final ImmutableCommandInvocation withMapping(MappingNode.ObjectMappingDef value) { if (this.mapping == value) return this; MappingNode.ObjectMappingDef newValue = Objects.requireNonNull(value, "mapping"); return new ImmutableCommandInvocation(this.token, this.className, newValue, this.promise); } /** * Copy the current immutable object by setting a present value for the optional {@link ServiceNode.CommandInvocation#getPromise() promise} attribute. * @param value The value for promise * @return A modified copy of {@code this} object */ public final ImmutableCommandInvocation withPromise(ServiceNode.ServicePromise value) { @Nullable ServiceNode.ServicePromise newValue = Objects.requireNonNull(value, "promise"); if (this.promise == newValue) return this; return new ImmutableCommandInvocation(this.token, this.className, this.mapping, newValue); } /** * Copy the current immutable object by setting an optional value for the {@link ServiceNode.CommandInvocation#getPromise() promise} attribute. * A shallow reference equality check is used on unboxed optional value to prevent copying of the same value by returning {@code this}. * @param optional A value for promise * @return A modified copy of {@code this} object */ @SuppressWarnings("unchecked") // safe covariant cast public final ImmutableCommandInvocation withPromise(Optional optional) { @Nullable ServiceNode.ServicePromise value = optional.orElse(null); if (this.promise == value) return this; return new ImmutableCommandInvocation(this.token, this.className, this.mapping, value); } /** * This instance is equal to all instances of {@code ImmutableCommandInvocation} 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 ImmutableCommandInvocation && equalTo((ImmutableCommandInvocation) another); } private boolean equalTo(ImmutableCommandInvocation another) { return token.equals(another.token) && className.equals(another.className) && mapping.equals(another.mapping) && Objects.equals(promise, another.promise); } /** * Computes a hash code from attributes: {@code token}, {@code className}, {@code mapping}, {@code promise}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + token.hashCode(); h += (h << 5) + className.hashCode(); h += (h << 5) + mapping.hashCode(); h += (h << 5) + Objects.hashCode(promise); return h; } /** * Prints the immutable value {@code CommandInvocation} with attribute values. * @return A string representation of the value */ @Override public String toString() { StringBuilder builder = new StringBuilder("CommandInvocation{"); builder.append("token=").append(token); builder.append(", "); builder.append("className=").append(className); builder.append(", "); builder.append("mapping=").append(mapping); if (promise != null) { builder.append(", "); builder.append("promise=").append(promise); } return builder.append("}").toString(); } /** * Creates an immutable copy of a {@link ServiceNode.CommandInvocation} 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 CommandInvocation instance */ public static ImmutableCommandInvocation copyOf(ServiceNode.CommandInvocation instance) { if (instance instanceof ImmutableCommandInvocation) { return (ImmutableCommandInvocation) instance; } return ImmutableCommandInvocation.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableCommandInvocation ImmutableCommandInvocation}. *

   * ImmutableCommandInvocation.builder()
   *    .token(io.resys.hdes.ast.api.nodes.HdesNode.Token) // required {@link ServiceNode.CommandInvocation#getToken() token}
   *    .className(io.resys.hdes.ast.api.nodes.InvocationNode) // required {@link ServiceNode.CommandInvocation#getClassName() className}
   *    .mapping(io.resys.hdes.ast.api.nodes.MappingNode.ObjectMappingDef) // required {@link ServiceNode.CommandInvocation#getMapping() mapping}
   *    .promise(io.resys.hdes.ast.api.nodes.ServiceNode.ServicePromise) // optional {@link ServiceNode.CommandInvocation#getPromise() promise}
   *    .build();
   * 
* @return A new ImmutableCommandInvocation builder */ public static ImmutableCommandInvocation.Builder builder() { return new ImmutableCommandInvocation.Builder(); } /** * Builds instances of type {@link ImmutableCommandInvocation ImmutableCommandInvocation}. * 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 = "ServiceNode.CommandInvocation", generator = "Immutables") @NotThreadSafe public static final class Builder { private static final long INIT_BIT_TOKEN = 0x1L; private static final long INIT_BIT_CLASS_NAME = 0x2L; private static final long INIT_BIT_MAPPING = 0x4L; private long initBits = 0x7L; private @Nullable HdesNode.Token token; private @Nullable InvocationNode className; private @Nullable MappingNode.ObjectMappingDef mapping; private @Nullable ServiceNode.ServicePromise promise; private Builder() { } /** * Fill a builder with attribute values from the provided {@code io.resys.hdes.ast.api.nodes.ServiceNode.CommandInvocation} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(ServiceNode.CommandInvocation instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return this; } /** * Fill a builder with attribute values from the provided {@code io.resys.hdes.ast.api.nodes.HdesNode} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(HdesNode instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return this; } private void from(Object object) { if (object instanceof ServiceNode.CommandInvocation) { ServiceNode.CommandInvocation instance = (ServiceNode.CommandInvocation) object; mapping(instance.getMapping()); className(instance.getClassName()); Optional promiseOptional = instance.getPromise(); if (promiseOptional.isPresent()) { promise(promiseOptional); } } if (object instanceof HdesNode) { HdesNode instance = (HdesNode) object; token(instance.getToken()); } } /** * Initializes the value for the {@link ServiceNode.CommandInvocation#getToken() token} attribute. * @param token The value for token * @return {@code this} builder for use in a chained invocation */ public final Builder token(HdesNode.Token token) { this.token = Objects.requireNonNull(token, "token"); initBits &= ~INIT_BIT_TOKEN; return this; } /** * Initializes the value for the {@link ServiceNode.CommandInvocation#getClassName() className} attribute. * @param className The value for className * @return {@code this} builder for use in a chained invocation */ public final Builder className(InvocationNode className) { this.className = Objects.requireNonNull(className, "className"); initBits &= ~INIT_BIT_CLASS_NAME; return this; } /** * Initializes the value for the {@link ServiceNode.CommandInvocation#getMapping() mapping} attribute. * @param mapping The value for mapping * @return {@code this} builder for use in a chained invocation */ public final Builder mapping(MappingNode.ObjectMappingDef mapping) { this.mapping = Objects.requireNonNull(mapping, "mapping"); initBits &= ~INIT_BIT_MAPPING; return this; } /** * Initializes the optional value {@link ServiceNode.CommandInvocation#getPromise() promise} to promise. * @param promise The value for promise * @return {@code this} builder for chained invocation */ public final Builder promise(ServiceNode.ServicePromise promise) { this.promise = Objects.requireNonNull(promise, "promise"); return this; } /** * Initializes the optional value {@link ServiceNode.CommandInvocation#getPromise() promise} to promise. * @param promise The value for promise * @return {@code this} builder for use in a chained invocation */ public final Builder promise(Optional promise) { this.promise = promise.orElse(null); return this; } /** * Builds a new {@link ImmutableCommandInvocation ImmutableCommandInvocation}. * @return An immutable instance of CommandInvocation * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableCommandInvocation build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableCommandInvocation(token, className, mapping, promise); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_TOKEN) != 0) attributes.add("token"); if ((initBits & INIT_BIT_CLASS_NAME) != 0) attributes.add("className"); if ((initBits & INIT_BIT_MAPPING) != 0) attributes.add("mapping"); return "Cannot build CommandInvocation, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy