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

com.spotify.google.cloud.pubsub.client.PullResponseBuilder Maven / Gradle / Ivy

There is a newer version: 1.34
Show newest version
package com.spotify.google.cloud.pubsub.client;

import io.norberg.automatter.AutoMatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Generated;

@Generated("io.norberg.automatter.processor.AutoMatterProcessor")
final class PullResponseBuilder {
  private List receivedMessages;

  public PullResponseBuilder() {
  }

  private PullResponseBuilder(PullResponse v) {
    List _receivedMessages = v.receivedMessages();
    this.receivedMessages = (_receivedMessages == null) ? null : new ArrayList(_receivedMessages);
  }

  private PullResponseBuilder(PullResponseBuilder v) {
    this.receivedMessages = (v.receivedMessages == null) ? null : new ArrayList(v.receivedMessages);
  }

  public List receivedMessages() {
    if (this.receivedMessages == null) {
      this.receivedMessages = new ArrayList();
    }
    return receivedMessages;
  }

  public PullResponseBuilder receivedMessages(List receivedMessages) {
    return receivedMessages((Collection) receivedMessages);
  }

  public PullResponseBuilder receivedMessages(Collection receivedMessages) {
    if (receivedMessages == null) {
      throw new NullPointerException("receivedMessages");
    }
    for (ReceivedMessage item : receivedMessages) {
      if (item == null) {
        throw new NullPointerException("receivedMessages: null item");
      }
    }
    this.receivedMessages = new ArrayList(receivedMessages);
    return this;
  }

  public PullResponseBuilder receivedMessages(Iterable receivedMessages) {
    if (receivedMessages == null) {
      throw new NullPointerException("receivedMessages");
    }
    if (receivedMessages instanceof Collection) {
      return receivedMessages((Collection) receivedMessages);
    }
    return receivedMessages(receivedMessages.iterator());
  }

  public PullResponseBuilder receivedMessages(Iterator receivedMessages) {
    if (receivedMessages == null) {
      throw new NullPointerException("receivedMessages");
    }
    this.receivedMessages = new ArrayList();
    while (receivedMessages.hasNext()) {
      ReceivedMessage item = receivedMessages.next();
      if (item == null) {
        throw new NullPointerException("receivedMessages: null item");
      }
      this.receivedMessages.add(item);
    }
    return this;
  }

  public PullResponseBuilder receivedMessages(ReceivedMessage... receivedMessages) {
    if (receivedMessages == null) {
      throw new NullPointerException("receivedMessages");
    }
    return receivedMessages(Arrays.asList(receivedMessages));
  }

  public PullResponseBuilder addReceivedMessage(ReceivedMessage receivedMessage) {
    if (receivedMessage == null) {
      throw new NullPointerException("receivedMessage");
    }
    if (this.receivedMessages == null) {
      this.receivedMessages = new ArrayList();
    }
    receivedMessages.add(receivedMessage);
    return this;
  }

  public PullResponse build() {
    List _receivedMessages = (receivedMessages != null) ? Collections.unmodifiableList(new ArrayList(receivedMessages)) : Collections.emptyList();
    return new Value(_receivedMessages);
  }

  public static PullResponseBuilder from(PullResponse v) {
    return new PullResponseBuilder(v);
  }

  public static PullResponseBuilder from(PullResponseBuilder v) {
    return new PullResponseBuilder(v);
  }

  private static final class Value implements PullResponse {
    private final List receivedMessages;

    private Value(@AutoMatter.Field("receivedMessages") List receivedMessages) {
      this.receivedMessages = (receivedMessages != null) ? receivedMessages : Collections.emptyList();
    }

    @AutoMatter.Field
    @Override
    public List receivedMessages() {
      return receivedMessages;
    }

    public PullResponseBuilder builder() {
      return new PullResponseBuilder(this);
    }

    @Override
    public boolean equals(Object o) {
      if (this == o) {
        return true;
      }
      if (!(o instanceof PullResponse)) {
        return false;
      }
      final PullResponse that = (PullResponse) o;
      if (receivedMessages != null ? !receivedMessages.equals(that.receivedMessages()) : that.receivedMessages() != null) {
        return false;
      }
      return true;
    }

    @Override
    public int hashCode() {
      int result = 1;
      long temp;
      result = 31 * result + (receivedMessages != null ? receivedMessages.hashCode() : 0);
      return result;
    }

    @Override
    public String toString() {
      return "PullResponse{" +
      "receivedMessages=" + receivedMessages +
      '}';
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy