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

com.vendasta.accountgroup.v1.internal.PagedResponse Maven / Gradle / Ivy

The newest version!
package com.vendasta.accountgroup.v1.internal;

import java.util.List;
import java.util.ArrayList;
import java.util.Date;
import java.util.Map;
import java.util.HashMap;
import java.util.Collections;
import java.util.Arrays;
import java.time.Duration;
import org.apache.commons.lang3.StringUtils;
import com.vendasta.accountgroup.v1.generated.ApiProto;

/**
 * 
 **/
public final class PagedResponse {




	private final List accountGroups;
	private final String nextCursor;
	private final boolean hasMore;
	private final long totalResults;
	

	private PagedResponse (
		final List accountGroups,
		final String nextCursor,
		final boolean hasMore,
		final long totalResults)
		
	{
		this.accountGroups = accountGroups;
		this.nextCursor = nextCursor;
		this.hasMore = hasMore;
		this.totalResults = totalResults;
		
	}
	
	/**
	 * 
      * @return The final value of accountGroups on the object
	 **/
	public List getAccountGroups() {
		return this.accountGroups;
	}
	
	/**
	 * A cursor that can be provided to retrieve the next page of results
      * @return The final value of nextCursor on the object
	 **/
	public String getNextCursor() {
		return this.nextCursor;
	}
	
	/**
	 * Whether or not more results exist
      * @return The final value of hasMore on the object
	 **/
	public boolean getHasMore() {
		return this.hasMore;
	}
	
	/**
	 * The total number of results for this query across all pages
      * @return The final value of totalResults on the object
	 **/
	public long getTotalResults() {
		return this.totalResults;
	}
	

	public static class Builder {
		private List accountGroups;
		private String nextCursor;
		private boolean hasMore;
		private long totalResults;
		
		public Builder() {
			this.accountGroups = null;
			this.nextCursor = "";
			this.hasMore = false;
			this.totalResults = 0;
			
		}
		
		/**
		  * Adds a value to the builder for accountGroups
		  * @param accountGroups Value to assign to the mutable Builder
		  * @return The Builder instance so that call chaining works
		 **/
		public Builder setAccountGroups(List accountGroups) {
			this.accountGroups = accountGroups;
			return this;
		}
		
		/**
		  * Adds a value to the builder for nextCursor
		  * @param nextCursor Value to assign to the mutable Builder
		  * @return The Builder instance so that call chaining works
		 **/
		public Builder setNextCursor(String nextCursor) {
			this.nextCursor = nextCursor;
			return this;
		}
		
		/**
		  * Adds a value to the builder for hasMore
		  * @param hasMore Value to assign to the mutable Builder
		  * @return The Builder instance so that call chaining works
		 **/
		public Builder setHasMore(boolean hasMore) {
			this.hasMore = hasMore;
			return this;
		}
		
		/**
		  * Adds a value to the builder for totalResults
		  * @param totalResults Value to assign to the mutable Builder
		  * @return The Builder instance so that call chaining works
		 **/
		public Builder setTotalResults(long totalResults) {
			this.totalResults = totalResults;
			return this;
		}
		
		/**
		  * Takes the configuration in the mutable Builder and uses it to instantiate a final instance
		  * of the PagedResponse class
		  * @return The instantiated final PagedResponse
		 **/
		public PagedResponse build() {
			return new PagedResponse(
				this.accountGroups,
				this.nextCursor,
				this.hasMore,
				this.totalResults);
		}
	}

	/**
	 * Returns a Builder for PagedResponse, which is a mutable representation of the object.  Once the
	 * client has built up an object they can then create an immutable PagedResponse object using the
	 * build function.
	 * @return A fresh Builder instance with no values set
	 **/
	public static Builder newBuilder() {
		return new Builder();
	}

	/**
	 * Provides a human-readable representation of this object.  Useful for debugging.
	 * @return A string representation of the PagedResponse instance
	 **/
	 public String toString() {
		 String result = "PagedResponse\n";
		 result += "-> accountGroups: (List)"
		     + StringUtils.join("\n  ", Arrays.asList(String.valueOf(this.accountGroups).split("\n"))) + "\n"; 
		 result += "-> nextCursor: (String)"
		     + StringUtils.join("\n  ", Arrays.asList(String.valueOf(this.nextCursor).split("\n"))) + "\n"; 
		 result += "-> hasMore: (boolean)"
		     + StringUtils.join("\n  ", Arrays.asList(String.valueOf(this.hasMore).split("\n"))) + "\n"; 
		 result += "-> totalResults: (long)"
		     + StringUtils.join("\n  ", Arrays.asList(String.valueOf(this.totalResults).split("\n"))) + "\n"; 
		 
		 return result;
	 }
	/**
	* Allows for simple conversion between the low-level generated protobuf object to
	* PagedResponse, which is much more usable.
	* @return An instance of PagedResponse representing the input proto object
	**/
	public static PagedResponse fromProto(ApiProto.PagedResponse proto) {
		PagedResponse out = null;
		if (proto != null) {
			PagedResponse.Builder outBuilder = PagedResponse.newBuilder()
			.setAccountGroups(AccountGroup.fromProtos(proto.getAccountGroupsList()))
			.setNextCursor(proto.getNextCursor())
			.setHasMore(proto.getHasMore())
			.setTotalResults(proto.getTotalResults());
			out = outBuilder.build();
		}
		return out;
	}

	/**
	* Convenience method for handling lists of proto objects.  It calls .fromProto on each one
	* and returns a list of the converted results.
	* @return A list of PagedResponse instances representing the input proto objects
	**/
	public static List fromProtos(List protos) {
		List out = new ArrayList();
		for(ApiProto.PagedResponse proto : protos) {
			out.add(PagedResponse.fromProto(proto));
		}
		return out;
	}

	/**
	 * Allows for simple conversion of an object to the low-level generated protobuf object.
	 * @return An instance of ApiProto.PagedResponse which is a proto object ready for wire transmission
	 **/
	 public ApiProto.PagedResponse toProto() {
		 PagedResponse obj = this;
		 ApiProto.PagedResponse.Builder outBuilder = ApiProto.PagedResponse.newBuilder();
		 outBuilder.addAllAccountGroups(AccountGroup.toProtos(obj.getAccountGroups()));
		 outBuilder.setNextCursor(obj.getNextCursor());
		 outBuilder.setHasMore(obj.getHasMore());
		 outBuilder.setTotalResults(obj.getTotalResults());
		 return outBuilder.build();
	 }

	 /**
	  * Convenience method for handling lists of objects.  It calls .toProto on each one and
	  * returns a list of the converted results.
	  * @return A list of ApiProto.PagedResponse instances representing the input objects.
	  */
	public static List toProtos(List objects) {
		List out = new ArrayList();
		if(objects != null) {
			for (PagedResponse obj : objects) {
				out.add(obj!=null?obj.toProto():null);
			}
		}
		return out;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy