com.spotify.github.v3.prs.ImmutableAutoMerge Maven / Gradle / Ivy
package com.spotify.github.v3.prs;
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.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import com.spotify.github.v3.User;
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 AutoMerge}.
*
* Use the builder to create immutable instances:
* {@code ImmutableAutoMerge.builder()}.
*/
@Generated(from = "AutoMerge", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableAutoMerge implements AutoMerge {
private final User enabledBy;
private final String mergeMethod;
private final @Nullable String commitTitle;
private final @Nullable String commitMessage;
private ImmutableAutoMerge(
User enabledBy,
String mergeMethod,
@Nullable String commitTitle,
@Nullable String commitMessage) {
this.enabledBy = enabledBy;
this.mergeMethod = mergeMethod;
this.commitTitle = commitTitle;
this.commitMessage = commitMessage;
}
/**
* @return The value of the {@code enabledBy} attribute
*/
@JsonProperty
@Override
public User enabledBy() {
return enabledBy;
}
/**
* @return The value of the {@code mergeMethod} attribute
*/
@JsonProperty
@Override
public String mergeMethod() {
return mergeMethod;
}
/**
* @return The value of the {@code commitTitle} attribute
*/
@JsonProperty
@Override
public @Nullable String commitTitle() {
return commitTitle;
}
/**
* @return The value of the {@code commitMessage} attribute
*/
@JsonProperty
@Override
public @Nullable String commitMessage() {
return commitMessage;
}
/**
* Copy the current immutable object by setting a value for the {@link AutoMerge#enabledBy() enabledBy} 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 enabledBy
* @return A modified copy of the {@code this} object
*/
public final ImmutableAutoMerge withEnabledBy(User value) {
if (this.enabledBy == value) return this;
User newValue = Objects.requireNonNull(value, "enabledBy");
return new ImmutableAutoMerge(newValue, this.mergeMethod, this.commitTitle, this.commitMessage);
}
/**
* Copy the current immutable object by setting a value for the {@link AutoMerge#mergeMethod() mergeMethod} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for mergeMethod
* @return A modified copy of the {@code this} object
*/
public final ImmutableAutoMerge withMergeMethod(String value) {
String newValue = Objects.requireNonNull(value, "mergeMethod");
if (this.mergeMethod.equals(newValue)) return this;
return new ImmutableAutoMerge(this.enabledBy, newValue, this.commitTitle, this.commitMessage);
}
/**
* Copy the current immutable object by setting a value for the {@link AutoMerge#commitTitle() commitTitle} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for commitTitle (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableAutoMerge withCommitTitle(@Nullable String value) {
if (Objects.equals(this.commitTitle, value)) return this;
return new ImmutableAutoMerge(this.enabledBy, this.mergeMethod, value, this.commitMessage);
}
/**
* Copy the current immutable object by setting a value for the {@link AutoMerge#commitMessage() commitMessage} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for commitMessage (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableAutoMerge withCommitMessage(@Nullable String value) {
if (Objects.equals(this.commitMessage, value)) return this;
return new ImmutableAutoMerge(this.enabledBy, this.mergeMethod, this.commitTitle, value);
}
/**
* This instance is equal to all instances of {@code ImmutableAutoMerge} 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 ImmutableAutoMerge
&& equalTo(0, (ImmutableAutoMerge) another);
}
private boolean equalTo(int synthetic, ImmutableAutoMerge another) {
return enabledBy.equals(another.enabledBy)
&& mergeMethod.equals(another.mergeMethod)
&& Objects.equals(commitTitle, another.commitTitle)
&& Objects.equals(commitMessage, another.commitMessage);
}
/**
* Computes a hash code from attributes: {@code enabledBy}, {@code mergeMethod}, {@code commitTitle}, {@code commitMessage}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + enabledBy.hashCode();
h += (h << 5) + mergeMethod.hashCode();
h += (h << 5) + Objects.hashCode(commitTitle);
h += (h << 5) + Objects.hashCode(commitMessage);
return h;
}
/**
* Prints the immutable value {@code AutoMerge} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "AutoMerge{"
+ "enabledBy=" + enabledBy
+ ", mergeMethod=" + mergeMethod
+ ", commitTitle=" + commitTitle
+ ", commitMessage=" + commitMessage
+ "}";
}
/**
* 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 = "AutoMerge", generator = "Immutables")
@Deprecated
@SuppressWarnings("Immutable")
@JsonDeserialize
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements AutoMerge {
@Nullable User enabledBy;
@Nullable String mergeMethod;
@Nullable String commitTitle;
@Nullable String commitMessage;
@JsonProperty
public void setEnabledBy(User enabledBy) {
this.enabledBy = enabledBy;
}
@JsonProperty
public void setMergeMethod(String mergeMethod) {
this.mergeMethod = mergeMethod;
}
@JsonProperty
public void setCommitTitle(@Nullable String commitTitle) {
this.commitTitle = commitTitle;
}
@JsonProperty
public void setCommitMessage(@Nullable String commitMessage) {
this.commitMessage = commitMessage;
}
@Override
public User enabledBy() { throw new UnsupportedOperationException(); }
@Override
public String mergeMethod() { throw new UnsupportedOperationException(); }
@Override
public String commitTitle() { throw new UnsupportedOperationException(); }
@Override
public String commitMessage() { 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 ImmutableAutoMerge fromJson(Json json) {
ImmutableAutoMerge.Builder builder = ImmutableAutoMerge.builder();
if (json.enabledBy != null) {
builder.enabledBy(json.enabledBy);
}
if (json.mergeMethod != null) {
builder.mergeMethod(json.mergeMethod);
}
if (json.commitTitle != null) {
builder.commitTitle(json.commitTitle);
}
if (json.commitMessage != null) {
builder.commitMessage(json.commitMessage);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link AutoMerge} 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 AutoMerge instance
*/
public static ImmutableAutoMerge copyOf(AutoMerge instance) {
if (instance instanceof ImmutableAutoMerge) {
return (ImmutableAutoMerge) instance;
}
return ImmutableAutoMerge.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableAutoMerge ImmutableAutoMerge}.
*
* ImmutableAutoMerge.builder()
* .enabledBy(com.spotify.github.v3.User) // required {@link AutoMerge#enabledBy() enabledBy}
* .mergeMethod(String) // required {@link AutoMerge#mergeMethod() mergeMethod}
* .commitTitle(String | null) // nullable {@link AutoMerge#commitTitle() commitTitle}
* .commitMessage(String | null) // nullable {@link AutoMerge#commitMessage() commitMessage}
* .build();
*
* @return A new ImmutableAutoMerge builder
*/
public static ImmutableAutoMerge.Builder builder() {
return new ImmutableAutoMerge.Builder();
}
/**
* Builds instances of type {@link ImmutableAutoMerge ImmutableAutoMerge}.
* 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 = "AutoMerge", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_ENABLED_BY = 0x1L;
private static final long INIT_BIT_MERGE_METHOD = 0x2L;
private long initBits = 0x3L;
private @Nullable User enabledBy;
private @Nullable String mergeMethod;
private @Nullable String commitTitle;
private @Nullable String commitMessage;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code AutoMerge} 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(AutoMerge instance) {
Objects.requireNonNull(instance, "instance");
enabledBy(instance.enabledBy());
mergeMethod(instance.mergeMethod());
@Nullable String commitTitleValue = instance.commitTitle();
if (commitTitleValue != null) {
commitTitle(commitTitleValue);
}
@Nullable String commitMessageValue = instance.commitMessage();
if (commitMessageValue != null) {
commitMessage(commitMessageValue);
}
return this;
}
/**
* Initializes the value for the {@link AutoMerge#enabledBy() enabledBy} attribute.
* @param enabledBy The value for enabledBy
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty
public final Builder enabledBy(User enabledBy) {
this.enabledBy = Objects.requireNonNull(enabledBy, "enabledBy");
initBits &= ~INIT_BIT_ENABLED_BY;
return this;
}
/**
* Initializes the value for the {@link AutoMerge#mergeMethod() mergeMethod} attribute.
* @param mergeMethod The value for mergeMethod
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty
public final Builder mergeMethod(String mergeMethod) {
this.mergeMethod = Objects.requireNonNull(mergeMethod, "mergeMethod");
initBits &= ~INIT_BIT_MERGE_METHOD;
return this;
}
/**
* Initializes the value for the {@link AutoMerge#commitTitle() commitTitle} attribute.
* @param commitTitle The value for commitTitle (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty
public final Builder commitTitle(@Nullable String commitTitle) {
this.commitTitle = commitTitle;
return this;
}
/**
* Initializes the value for the {@link AutoMerge#commitMessage() commitMessage} attribute.
* @param commitMessage The value for commitMessage (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty
public final Builder commitMessage(@Nullable String commitMessage) {
this.commitMessage = commitMessage;
return this;
}
/**
* Builds a new {@link ImmutableAutoMerge ImmutableAutoMerge}.
* @return An immutable instance of AutoMerge
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableAutoMerge build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableAutoMerge(enabledBy, mergeMethod, commitTitle, commitMessage);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_ENABLED_BY) != 0) attributes.add("enabledBy");
if ((initBits & INIT_BIT_MERGE_METHOD) != 0) attributes.add("mergeMethod");
return "Cannot build AutoMerge, some of required attributes are not set " + attributes;
}
}
}