com.arakelian.elastic.model.ImmutableVersionComponents Maven / Gradle / Ivy
package com.arakelian.elastic.model;
import com.arakelian.core.feature.Nullable;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.CheckReturnValue;
import javax.annotation.Generated;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
/**
* Immutable implementation of {@link VersionComponents}.
*
* Use the builder to create immutable instances:
* {@code ImmutableVersionComponents.builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableVersionComponents extends VersionComponents {
private final int build;
private final int major;
private final int minor;
private final @Nullable String number;
private final boolean empty;
private ImmutableVersionComponents(ImmutableVersionComponents.Builder builder) {
this.number = builder.number;
if (builder.buildIsSet()) {
initShim.build(builder.build);
}
if (builder.majorIsSet()) {
initShim.major(builder.major);
}
if (builder.minorIsSet()) {
initShim.minor(builder.minor);
}
this.build = initShim.getBuild();
this.major = initShim.getMajor();
this.minor = initShim.getMinor();
this.empty = initShim.isEmpty();
this.initShim = null;
}
private static final byte STAGE_INITIALIZING = -1;
private static final byte STAGE_UNINITIALIZED = 0;
private static final byte STAGE_INITIALIZED = 1;
@SuppressWarnings("Immutable")
private transient volatile InitShim initShim = new InitShim();
private final class InitShim {
private byte buildBuildStage = STAGE_UNINITIALIZED;
private int build;
int getBuild() {
if (buildBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (buildBuildStage == STAGE_UNINITIALIZED) {
buildBuildStage = STAGE_INITIALIZING;
this.build = ImmutableVersionComponents.super.getBuild();
buildBuildStage = STAGE_INITIALIZED;
}
return this.build;
}
void build(int build) {
this.build = build;
buildBuildStage = STAGE_INITIALIZED;
}
private byte majorBuildStage = STAGE_UNINITIALIZED;
private int major;
int getMajor() {
if (majorBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (majorBuildStage == STAGE_UNINITIALIZED) {
majorBuildStage = STAGE_INITIALIZING;
this.major = ImmutableVersionComponents.super.getMajor();
majorBuildStage = STAGE_INITIALIZED;
}
return this.major;
}
void major(int major) {
this.major = major;
majorBuildStage = STAGE_INITIALIZED;
}
private byte minorBuildStage = STAGE_UNINITIALIZED;
private int minor;
int getMinor() {
if (minorBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (minorBuildStage == STAGE_UNINITIALIZED) {
minorBuildStage = STAGE_INITIALIZING;
this.minor = ImmutableVersionComponents.super.getMinor();
minorBuildStage = STAGE_INITIALIZED;
}
return this.minor;
}
void minor(int minor) {
this.minor = minor;
minorBuildStage = STAGE_INITIALIZED;
}
private byte emptyBuildStage = STAGE_UNINITIALIZED;
private boolean empty;
boolean isEmpty() {
if (emptyBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (emptyBuildStage == STAGE_UNINITIALIZED) {
emptyBuildStage = STAGE_INITIALIZING;
this.empty = ImmutableVersionComponents.super.isEmpty();
emptyBuildStage = STAGE_INITIALIZED;
}
return this.empty;
}
private String formatInitCycleMessage() {
List attributes = new ArrayList<>();
if (buildBuildStage == STAGE_INITIALIZING) attributes.add("build");
if (majorBuildStage == STAGE_INITIALIZING) attributes.add("major");
if (minorBuildStage == STAGE_INITIALIZING) attributes.add("minor");
if (emptyBuildStage == STAGE_INITIALIZING) attributes.add("empty");
return "Cannot build VersionComponents, attribute initializers form cycle " + attributes;
}
}
/**
* @return The value of the {@code build} attribute
*/
@JsonProperty("build")
@Override
public int getBuild() {
InitShim shim = this.initShim;
return shim != null
? shim.getBuild()
: this.build;
}
/**
* @return The value of the {@code major} attribute
*/
@JsonProperty("major")
@Override
public int getMajor() {
InitShim shim = this.initShim;
return shim != null
? shim.getMajor()
: this.major;
}
/**
* @return The value of the {@code minor} attribute
*/
@JsonProperty("minor")
@Override
public int getMinor() {
InitShim shim = this.initShim;
return shim != null
? shim.getMinor()
: this.minor;
}
/**
* @return The value of the {@code number} attribute
*/
@JsonProperty("number")
@Override
public @Nullable String getNumber() {
return number;
}
/**
* @return The computed-at-construction value of the {@code empty} attribute
*/
@JsonProperty("empty")
@JsonIgnore
@Override
public boolean isEmpty() {
InitShim shim = this.initShim;
return shim != null
? shim.isEmpty()
: this.empty;
}
/**
* This instance is equal to all instances of {@code ImmutableVersionComponents} that have equal attribute values.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/
@Override
public boolean equals(@javax.annotation.Nullable Object another) {
if (this == another) return true;
return another instanceof ImmutableVersionComponents
&& equalTo((ImmutableVersionComponents) another);
}
private boolean equalTo(ImmutableVersionComponents another) {
return Objects.equals(number, another.number);
}
/**
* Computes a hash code from attributes: {@code number}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + Objects.hashCode(number);
return h;
}
/**
* Prints the immutable value {@code VersionComponents} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("VersionComponents")
.omitNullValues()
.add("number", number)
.toString();
}
/**
* Creates a builder for {@link ImmutableVersionComponents ImmutableVersionComponents}.
* @return A new ImmutableVersionComponents builder
*/
public static ImmutableVersionComponents.Builder builder() {
return new ImmutableVersionComponents.Builder();
}
/**
* Builds instances of type {@link ImmutableVersionComponents ImmutableVersionComponents}.
* 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.
*/
@NotThreadSafe
public static final class Builder {
private static final long OPT_BIT_BUILD = 0x1L;
private static final long OPT_BIT_MAJOR = 0x2L;
private static final long OPT_BIT_MINOR = 0x4L;
private long optBits;
private int build;
private int major;
private int minor;
private @javax.annotation.Nullable String number;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code VersionComponents} instance.
* Regular attribute values will be replaced with those from the given instance.
* Absent optional values will not replace present values.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(VersionComponents instance) {
Objects.requireNonNull(instance, "instance");
build(instance.getBuild());
major(instance.getMajor());
minor(instance.getMinor());
String numberValue = instance.getNumber();
if (numberValue != null) {
number(numberValue);
}
return this;
}
/**
* Initializes the value for the {@link VersionComponents#getBuild() build} attribute.
*
If not set, this attribute will have a default value as returned by the initializer of {@link VersionComponents#getBuild() build}.
* @param build The value for build
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("build")
public final Builder build(int build) {
this.build = build;
optBits |= OPT_BIT_BUILD;
return this;
}
/**
* Initializes the value for the {@link VersionComponents#getMajor() major} attribute.
*
If not set, this attribute will have a default value as returned by the initializer of {@link VersionComponents#getMajor() major}.
* @param major The value for major
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("major")
public final Builder major(int major) {
this.major = major;
optBits |= OPT_BIT_MAJOR;
return this;
}
/**
* Initializes the value for the {@link VersionComponents#getMinor() minor} attribute.
*
If not set, this attribute will have a default value as returned by the initializer of {@link VersionComponents#getMinor() minor}.
* @param minor The value for minor
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("minor")
public final Builder minor(int minor) {
this.minor = minor;
optBits |= OPT_BIT_MINOR;
return this;
}
/**
* Initializes the value for the {@link VersionComponents#getNumber() number} attribute.
* @param number The value for number (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("number")
public final Builder number(@Nullable String number) {
this.number = number;
return this;
}
/**
* Builds a new {@link ImmutableVersionComponents ImmutableVersionComponents}.
* @return An immutable instance of VersionComponents
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableVersionComponents build() {
return new ImmutableVersionComponents(this);
}
private boolean buildIsSet() {
return (optBits & OPT_BIT_BUILD) != 0;
}
private boolean majorIsSet() {
return (optBits & OPT_BIT_MAJOR) != 0;
}
private boolean minorIsSet() {
return (optBits & OPT_BIT_MINOR) != 0;
}
}
}