com.spotify.github.v3.prs.ImmutablePartialPullRequestItem 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.CloseTracking;
import com.spotify.github.GitHubInstant;
import com.spotify.github.UpdateTracking;
import java.net.URI;
import java.util.Objects;
import java.util.Optional;
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 PartialPullRequestItem}.
*
* Use the builder to create immutable instances:
* {@code ImmutablePartialPullRequestItem.builder()}.
*/
@Generated(from = "PartialPullRequestItem", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutablePartialPullRequestItem implements PartialPullRequestItem {
private final @Nullable GitHubInstant createdAt;
private final @Nullable GitHubInstant updatedAt;
private final @Nullable GitHubInstant closedAt;
private final @Nullable Long id;
private final @Nullable URI url;
private final @Nullable Long number;
private final @Nullable PullRequestRef head;
private final @Nullable PullRequestRef base;
private ImmutablePartialPullRequestItem(
@Nullable GitHubInstant createdAt,
@Nullable GitHubInstant updatedAt,
@Nullable GitHubInstant closedAt,
@Nullable Long id,
@Nullable URI url,
@Nullable Long number,
@Nullable PullRequestRef head,
@Nullable PullRequestRef base) {
this.createdAt = createdAt;
this.updatedAt = updatedAt;
this.closedAt = closedAt;
this.id = id;
this.url = url;
this.number = number;
this.head = head;
this.base = base;
}
/**
* Created date
* @return The date when the issue was created
*/
@JsonProperty
@Override
public @Nullable GitHubInstant createdAt() {
return createdAt;
}
/**
* Updated date
* @return The date when the issue was updated
*/
@JsonProperty
@Override
public @Nullable GitHubInstant updatedAt() {
return updatedAt;
}
/**
* Closed date.
* @return The date when the issue was closed
*/
@JsonProperty
@Override
public Optional closedAt() {
return Optional.ofNullable(closedAt);
}
/**
*ID.
*/
@JsonProperty
@Override
public @Nullable Long id() {
return id;
}
/**
*URL.
*/
@JsonProperty
@Override
public @Nullable URI url() {
return url;
}
/**
*Number.
*/
@JsonProperty
@Override
public @Nullable Long number() {
return number;
}
/**
*Head reference.
*/
@JsonProperty
@Override
public @Nullable PullRequestRef head() {
return head;
}
/**
*Base reference.
*/
@JsonProperty
@Override
public @Nullable PullRequestRef base() {
return base;
}
/**
* Copy the current immutable object by setting a value for the {@link PartialPullRequestItem#createdAt() createdAt} 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 createdAt (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutablePartialPullRequestItem withCreatedAt(@Nullable GitHubInstant value) {
if (this.createdAt == value) return this;
return new ImmutablePartialPullRequestItem(value, this.updatedAt, this.closedAt, this.id, this.url, this.number, this.head, this.base);
}
/**
* Copy the current immutable object by setting a value for the {@link PartialPullRequestItem#updatedAt() updatedAt} 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 updatedAt (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutablePartialPullRequestItem withUpdatedAt(@Nullable GitHubInstant value) {
if (this.updatedAt == value) return this;
return new ImmutablePartialPullRequestItem(this.createdAt, value, this.closedAt, this.id, this.url, this.number, this.head, this.base);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link PartialPullRequestItem#closedAt() closedAt} attribute.
* @param value The value for closedAt
* @return A modified copy of {@code this} object
*/
public final ImmutablePartialPullRequestItem withClosedAt(GitHubInstant value) {
GitHubInstant newValue = Objects.requireNonNull(value, "closedAt");
if (this.closedAt == newValue) return this;
return new ImmutablePartialPullRequestItem(this.createdAt, this.updatedAt, newValue, this.id, this.url, this.number, this.head, this.base);
}
/**
* Copy the current immutable object by setting an optional value for the {@link PartialPullRequestItem#closedAt() closedAt} 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 closedAt
* @return A modified copy of {@code this} object
*/
@SuppressWarnings("unchecked") // safe covariant cast
public final ImmutablePartialPullRequestItem withClosedAt(Optional extends GitHubInstant> optional) {
@Nullable GitHubInstant value = optional.orElse(null);
if (this.closedAt == value) return this;
return new ImmutablePartialPullRequestItem(this.createdAt, this.updatedAt, value, this.id, this.url, this.number, this.head, this.base);
}
/**
* Copy the current immutable object by setting a value for the {@link PartialPullRequestItem#id() id} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for id (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutablePartialPullRequestItem withId(@Nullable Long value) {
if (Objects.equals(this.id, value)) return this;
return new ImmutablePartialPullRequestItem(
this.createdAt,
this.updatedAt,
this.closedAt,
value,
this.url,
this.number,
this.head,
this.base);
}
/**
* Copy the current immutable object by setting a value for the {@link PartialPullRequestItem#url() url} 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 url (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutablePartialPullRequestItem withUrl(@Nullable URI value) {
if (this.url == value) return this;
return new ImmutablePartialPullRequestItem(
this.createdAt,
this.updatedAt,
this.closedAt,
this.id,
value,
this.number,
this.head,
this.base);
}
/**
* Copy the current immutable object by setting a value for the {@link PartialPullRequestItem#number() number} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for number (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutablePartialPullRequestItem withNumber(@Nullable Long value) {
if (Objects.equals(this.number, value)) return this;
return new ImmutablePartialPullRequestItem(this.createdAt, this.updatedAt, this.closedAt, this.id, this.url, value, this.head, this.base);
}
/**
* Copy the current immutable object by setting a value for the {@link PartialPullRequestItem#head() head} 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 head (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutablePartialPullRequestItem withHead(@Nullable PullRequestRef value) {
if (this.head == value) return this;
return new ImmutablePartialPullRequestItem(this.createdAt, this.updatedAt, this.closedAt, this.id, this.url, this.number, value, this.base);
}
/**
* Copy the current immutable object by setting a value for the {@link PartialPullRequestItem#base() base} 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 base (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutablePartialPullRequestItem withBase(@Nullable PullRequestRef value) {
if (this.base == value) return this;
return new ImmutablePartialPullRequestItem(this.createdAt, this.updatedAt, this.closedAt, this.id, this.url, this.number, this.head, value);
}
/**
* This instance is equal to all instances of {@code ImmutablePartialPullRequestItem} 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 ImmutablePartialPullRequestItem
&& equalTo(0, (ImmutablePartialPullRequestItem) another);
}
private boolean equalTo(int synthetic, ImmutablePartialPullRequestItem another) {
return Objects.equals(createdAt, another.createdAt)
&& Objects.equals(updatedAt, another.updatedAt)
&& Objects.equals(closedAt, another.closedAt)
&& Objects.equals(id, another.id)
&& Objects.equals(url, another.url)
&& Objects.equals(number, another.number)
&& Objects.equals(head, another.head)
&& Objects.equals(base, another.base);
}
/**
* Computes a hash code from attributes: {@code createdAt}, {@code updatedAt}, {@code closedAt}, {@code id}, {@code url}, {@code number}, {@code head}, {@code base}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + Objects.hashCode(createdAt);
h += (h << 5) + Objects.hashCode(updatedAt);
h += (h << 5) + Objects.hashCode(closedAt);
h += (h << 5) + Objects.hashCode(id);
h += (h << 5) + Objects.hashCode(url);
h += (h << 5) + Objects.hashCode(number);
h += (h << 5) + Objects.hashCode(head);
h += (h << 5) + Objects.hashCode(base);
return h;
}
/**
* Prints the immutable value {@code PartialPullRequestItem} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder("PartialPullRequestItem{");
if (createdAt != null) {
builder.append("createdAt=").append(createdAt);
}
if (updatedAt != null) {
if (builder.length() > 23) builder.append(", ");
builder.append("updatedAt=").append(updatedAt);
}
if (closedAt != null) {
if (builder.length() > 23) builder.append(", ");
builder.append("closedAt=").append(closedAt);
}
if (id != null) {
if (builder.length() > 23) builder.append(", ");
builder.append("id=").append(id);
}
if (url != null) {
if (builder.length() > 23) builder.append(", ");
builder.append("url=").append(url);
}
if (number != null) {
if (builder.length() > 23) builder.append(", ");
builder.append("number=").append(number);
}
if (head != null) {
if (builder.length() > 23) builder.append(", ");
builder.append("head=").append(head);
}
if (base != null) {
if (builder.length() > 23) builder.append(", ");
builder.append("base=").append(base);
}
return builder.append("}").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 = "PartialPullRequestItem", generator = "Immutables")
@Deprecated
@SuppressWarnings("Immutable")
@JsonDeserialize
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements PartialPullRequestItem {
@Nullable GitHubInstant createdAt;
@Nullable GitHubInstant updatedAt;
@Nullable Optional closedAt = Optional.empty();
@Nullable Long id;
@Nullable URI url;
@Nullable Long number;
@Nullable PullRequestRef head;
@Nullable PullRequestRef base;
@JsonProperty
public void setCreatedAt(@Nullable GitHubInstant createdAt) {
this.createdAt = createdAt;
}
@JsonProperty
public void setUpdatedAt(@Nullable GitHubInstant updatedAt) {
this.updatedAt = updatedAt;
}
@JsonProperty
public void setClosedAt(Optional closedAt) {
this.closedAt = closedAt;
}
@JsonProperty
public void setId(@Nullable Long id) {
this.id = id;
}
@JsonProperty
public void setUrl(@Nullable URI url) {
this.url = url;
}
@JsonProperty
public void setNumber(@Nullable Long number) {
this.number = number;
}
@JsonProperty
public void setHead(@Nullable PullRequestRef head) {
this.head = head;
}
@JsonProperty
public void setBase(@Nullable PullRequestRef base) {
this.base = base;
}
@Override
public GitHubInstant createdAt() { throw new UnsupportedOperationException(); }
@Override
public GitHubInstant updatedAt() { throw new UnsupportedOperationException(); }
@Override
public Optional closedAt() { throw new UnsupportedOperationException(); }
@Override
public Long id() { throw new UnsupportedOperationException(); }
@Override
public URI url() { throw new UnsupportedOperationException(); }
@Override
public Long number() { throw new UnsupportedOperationException(); }
@Override
public PullRequestRef head() { throw new UnsupportedOperationException(); }
@Override
public PullRequestRef base() { 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 ImmutablePartialPullRequestItem fromJson(Json json) {
ImmutablePartialPullRequestItem.Builder builder = ImmutablePartialPullRequestItem.builder();
if (json.createdAt != null) {
builder.createdAt(json.createdAt);
}
if (json.updatedAt != null) {
builder.updatedAt(json.updatedAt);
}
if (json.closedAt != null) {
builder.closedAt(json.closedAt);
}
if (json.id != null) {
builder.id(json.id);
}
if (json.url != null) {
builder.url(json.url);
}
if (json.number != null) {
builder.number(json.number);
}
if (json.head != null) {
builder.head(json.head);
}
if (json.base != null) {
builder.base(json.base);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link PartialPullRequestItem} 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 PartialPullRequestItem instance
*/
public static ImmutablePartialPullRequestItem copyOf(PartialPullRequestItem instance) {
if (instance instanceof ImmutablePartialPullRequestItem) {
return (ImmutablePartialPullRequestItem) instance;
}
return ImmutablePartialPullRequestItem.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutablePartialPullRequestItem ImmutablePartialPullRequestItem}.
*
* ImmutablePartialPullRequestItem.builder()
* .createdAt(com.spotify.github.GitHubInstant | null) // nullable {@link PartialPullRequestItem#createdAt() createdAt}
* .updatedAt(com.spotify.github.GitHubInstant | null) // nullable {@link PartialPullRequestItem#updatedAt() updatedAt}
* .closedAt(com.spotify.github.GitHubInstant) // optional {@link PartialPullRequestItem#closedAt() closedAt}
* .id(Long | null) // nullable {@link PartialPullRequestItem#id() id}
* .url(java.net.URI | null) // nullable {@link PartialPullRequestItem#url() url}
* .number(Long | null) // nullable {@link PartialPullRequestItem#number() number}
* .head(com.spotify.github.v3.prs.PullRequestRef | null) // nullable {@link PartialPullRequestItem#head() head}
* .base(com.spotify.github.v3.prs.PullRequestRef | null) // nullable {@link PartialPullRequestItem#base() base}
* .build();
*
* @return A new ImmutablePartialPullRequestItem builder
*/
public static ImmutablePartialPullRequestItem.Builder builder() {
return new ImmutablePartialPullRequestItem.Builder();
}
/**
* Builds instances of type {@link ImmutablePartialPullRequestItem ImmutablePartialPullRequestItem}.
* 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 = "PartialPullRequestItem", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private @Nullable GitHubInstant createdAt;
private @Nullable GitHubInstant updatedAt;
private @Nullable GitHubInstant closedAt;
private @Nullable Long id;
private @Nullable URI url;
private @Nullable Long number;
private @Nullable PullRequestRef head;
private @Nullable PullRequestRef base;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code com.spotify.github.CloseTracking} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(CloseTracking instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code com.spotify.github.v3.prs.PartialPullRequestItem} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(PartialPullRequestItem instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code com.spotify.github.UpdateTracking} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(UpdateTracking instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
private void from(Object object) {
@Var long bits = 0;
if (object instanceof CloseTracking) {
CloseTracking instance = (CloseTracking) object;
if ((bits & 0x2L) == 0) {
Optional closedAtOptional = instance.closedAt();
if (closedAtOptional.isPresent()) {
closedAt(closedAtOptional);
}
bits |= 0x2L;
}
if ((bits & 0x1L) == 0) {
@Nullable GitHubInstant createdAtValue = instance.createdAt();
if (createdAtValue != null) {
createdAt(createdAtValue);
}
bits |= 0x1L;
}
if ((bits & 0x4L) == 0) {
@Nullable GitHubInstant updatedAtValue = instance.updatedAt();
if (updatedAtValue != null) {
updatedAt(updatedAtValue);
}
bits |= 0x4L;
}
}
if (object instanceof PartialPullRequestItem) {
PartialPullRequestItem instance = (PartialPullRequestItem) object;
@Nullable PullRequestRef headValue = instance.head();
if (headValue != null) {
head(headValue);
}
if ((bits & 0x1L) == 0) {
@Nullable GitHubInstant createdAtValue = instance.createdAt();
if (createdAtValue != null) {
createdAt(createdAtValue);
}
bits |= 0x1L;
}
@Nullable Long numberValue = instance.number();
if (numberValue != null) {
number(numberValue);
}
@Nullable Long idValue = instance.id();
if (idValue != null) {
id(idValue);
}
if ((bits & 0x2L) == 0) {
Optional closedAtOptional = instance.closedAt();
if (closedAtOptional.isPresent()) {
closedAt(closedAtOptional);
}
bits |= 0x2L;
}
@Nullable URI urlValue = instance.url();
if (urlValue != null) {
url(urlValue);
}
if ((bits & 0x4L) == 0) {
@Nullable GitHubInstant updatedAtValue = instance.updatedAt();
if (updatedAtValue != null) {
updatedAt(updatedAtValue);
}
bits |= 0x4L;
}
@Nullable PullRequestRef baseValue = instance.base();
if (baseValue != null) {
base(baseValue);
}
}
if (object instanceof UpdateTracking) {
UpdateTracking instance = (UpdateTracking) object;
if ((bits & 0x1L) == 0) {
@Nullable GitHubInstant createdAtValue = instance.createdAt();
if (createdAtValue != null) {
createdAt(createdAtValue);
}
bits |= 0x1L;
}
if ((bits & 0x4L) == 0) {
@Nullable GitHubInstant updatedAtValue = instance.updatedAt();
if (updatedAtValue != null) {
updatedAt(updatedAtValue);
}
bits |= 0x4L;
}
}
}
/**
* Initializes the value for the {@link PartialPullRequestItem#createdAt() createdAt} attribute.
* @param createdAt The value for createdAt (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty
public final Builder createdAt(@Nullable GitHubInstant createdAt) {
this.createdAt = createdAt;
return this;
}
/**
* Initializes the value for the {@link PartialPullRequestItem#updatedAt() updatedAt} attribute.
* @param updatedAt The value for updatedAt (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty
public final Builder updatedAt(@Nullable GitHubInstant updatedAt) {
this.updatedAt = updatedAt;
return this;
}
/**
* Initializes the optional value {@link PartialPullRequestItem#closedAt() closedAt} to closedAt.
* @param closedAt The value for closedAt
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder closedAt(GitHubInstant closedAt) {
this.closedAt = Objects.requireNonNull(closedAt, "closedAt");
return this;
}
/**
* Initializes the optional value {@link PartialPullRequestItem#closedAt() closedAt} to closedAt.
* @param closedAt The value for closedAt
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty
public final Builder closedAt(Optional extends GitHubInstant> closedAt) {
this.closedAt = closedAt.orElse(null);
return this;
}
/**
* Initializes the value for the {@link PartialPullRequestItem#id() id} attribute.
* @param id The value for id (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty
public final Builder id(@Nullable Long id) {
this.id = id;
return this;
}
/**
* Initializes the value for the {@link PartialPullRequestItem#url() url} attribute.
* @param url The value for url (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty
public final Builder url(@Nullable URI url) {
this.url = url;
return this;
}
/**
* Initializes the value for the {@link PartialPullRequestItem#number() number} attribute.
* @param number The value for number (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty
public final Builder number(@Nullable Long number) {
this.number = number;
return this;
}
/**
* Initializes the value for the {@link PartialPullRequestItem#head() head} attribute.
* @param head The value for head (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty
public final Builder head(@Nullable PullRequestRef head) {
this.head = head;
return this;
}
/**
* Initializes the value for the {@link PartialPullRequestItem#base() base} attribute.
* @param base The value for base (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty
public final Builder base(@Nullable PullRequestRef base) {
this.base = base;
return this;
}
/**
* Builds a new {@link ImmutablePartialPullRequestItem ImmutablePartialPullRequestItem}.
* @return An immutable instance of PartialPullRequestItem
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutablePartialPullRequestItem build() {
return new ImmutablePartialPullRequestItem(createdAt, updatedAt, closedAt, id, url, number, head, base);
}
}
}