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

com.orbitz.consul.model.ImmutableEventResponse Maven / Gradle / Ivy

The newest version!
package com.orbitz.consul.model;

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 com.orbitz.consul.model.event.Event;
import java.math.BigInteger;
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 EventResponse}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableEventResponse.builder()}. * Use the static factory method to create immutable instances: * {@code ImmutableEventResponse.of()}. */ @Generated(from = "EventResponse", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue public final class ImmutableEventResponse extends EventResponse { private final ImmutableList events; private final BigInteger index; private ImmutableEventResponse(Iterable events, BigInteger index) { this.events = ImmutableList.copyOf(events); this.index = Objects.requireNonNull(index, "index"); } private ImmutableEventResponse( ImmutableEventResponse original, ImmutableList events, BigInteger index) { this.events = events; this.index = index; } /** * @return The value of the {@code events} attribute */ @JsonProperty("events") @Override public ImmutableList getEvents() { return events; } /** * @return The value of the {@code index} attribute */ @JsonProperty("index") @Override public BigInteger getIndex() { return index; } /** * Copy the current immutable object with elements that replace the content of {@link EventResponse#getEvents() events}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableEventResponse withEvents(Event... elements) { ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableEventResponse(this, newValue, this.index); } /** * Copy the current immutable object with elements that replace the content of {@link EventResponse#getEvents() events}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of events elements to set * @return A modified copy of {@code this} object */ public final ImmutableEventResponse withEvents(Iterable elements) { if (this.events == elements) return this; ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableEventResponse(this, newValue, this.index); } /** * Copy the current immutable object by setting a value for the {@link EventResponse#getIndex() index} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for index * @return A modified copy of the {@code this} object */ public final ImmutableEventResponse withIndex(BigInteger value) { BigInteger newValue = Objects.requireNonNull(value, "index"); if (this.index.equals(newValue)) return this; return new ImmutableEventResponse(this, this.events, newValue); } /** * This instance is equal to all instances of {@code ImmutableEventResponse} 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 ImmutableEventResponse && equalTo((ImmutableEventResponse) another); } private boolean equalTo(ImmutableEventResponse another) { return events.equals(another.events) && index.equals(another.index); } /** * Computes a hash code from attributes: {@code events}, {@code index}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + events.hashCode(); h += (h << 5) + index.hashCode(); return h; } /** * Prints the immutable value {@code EventResponse} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("EventResponse") .omitNullValues() .add("events", events) .add("index", index) .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 = "EventResponse", generator = "Immutables") @Deprecated @SuppressWarnings("Immutable") @JsonDeserialize @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE) static final class Json extends EventResponse { @Nullable List events = ImmutableList.of(); @Nullable BigInteger index; @JsonProperty("events") public void setEvents(List events) { this.events = events; } @JsonProperty("index") public void setIndex(BigInteger index) { this.index = index; } @Override public List getEvents() { throw new UnsupportedOperationException(); } @Override public BigInteger getIndex() { 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 ImmutableEventResponse fromJson(Json json) { ImmutableEventResponse.Builder builder = ImmutableEventResponse.builder(); if (json.events != null) { builder.addAllEvents(json.events); } if (json.index != null) { builder.index(json.index); } return builder.build(); } /** * Construct a new immutable {@code EventResponse} instance. * @param events The value for the {@code events} attribute * @param index The value for the {@code index} attribute * @return An immutable EventResponse instance */ public static ImmutableEventResponse of(List events, BigInteger index) { return of((Iterable) events, index); } /** * Construct a new immutable {@code EventResponse} instance. * @param events The value for the {@code events} attribute * @param index The value for the {@code index} attribute * @return An immutable EventResponse instance */ public static ImmutableEventResponse of(Iterable events, BigInteger index) { return new ImmutableEventResponse(events, index); } /** * Creates an immutable copy of a {@link EventResponse} 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 EventResponse instance */ public static ImmutableEventResponse copyOf(EventResponse instance) { if (instance instanceof ImmutableEventResponse) { return (ImmutableEventResponse) instance; } return ImmutableEventResponse.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableEventResponse ImmutableEventResponse}. *

   * ImmutableEventResponse.builder()
   *    .addEvents|addAllEvents(com.orbitz.consul.model.event.Event) // {@link EventResponse#getEvents() events} elements
   *    .index(java.math.BigInteger) // required {@link EventResponse#getIndex() index}
   *    .build();
   * 
* @return A new ImmutableEventResponse builder */ public static ImmutableEventResponse.Builder builder() { return new ImmutableEventResponse.Builder(); } /** * Builds instances of type {@link ImmutableEventResponse ImmutableEventResponse}. * 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 = "EventResponse", generator = "Immutables") @NotThreadSafe public static final class Builder { private static final long INIT_BIT_INDEX = 0x1L; private long initBits = 0x1L; private ImmutableList.Builder events = ImmutableList.builder(); private @Nullable BigInteger index; private Builder() { } /** * Fill a builder with attribute values from the provided {@code EventResponse} 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(EventResponse instance) { Objects.requireNonNull(instance, "instance"); addAllEvents(instance.getEvents()); index(instance.getIndex()); return this; } /** * Adds one element to {@link EventResponse#getEvents() events} list. * @param element A events element * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addEvents(Event element) { this.events.add(element); return this; } /** * Adds elements to {@link EventResponse#getEvents() events} list. * @param elements An array of events elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addEvents(Event... elements) { this.events.add(elements); return this; } /** * Sets or replaces all elements for {@link EventResponse#getEvents() events} list. * @param elements An iterable of events elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("events") public final Builder events(Iterable elements) { this.events = ImmutableList.builder(); return addAllEvents(elements); } /** * Adds elements to {@link EventResponse#getEvents() events} list. * @param elements An iterable of events elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAllEvents(Iterable elements) { this.events.addAll(elements); return this; } /** * Initializes the value for the {@link EventResponse#getIndex() index} attribute. * @param index The value for index * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("index") public final Builder index(BigInteger index) { this.index = Objects.requireNonNull(index, "index"); initBits &= ~INIT_BIT_INDEX; return this; } /** * Builds a new {@link ImmutableEventResponse ImmutableEventResponse}. * @return An immutable instance of EventResponse * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableEventResponse build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableEventResponse(null, events.build(), index); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_INDEX) != 0) attributes.add("index"); return "Cannot build EventResponse, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy