
com.vendasta.sales.v1.internal.PagedResponseMetadata Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sales.v1 Show documentation
Show all versions of sales.v1 Show documentation
Java SDK for service sales
The newest version!
package com.vendasta.sales.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 org.apache.commons.lang3.StringUtils;
import com.vendasta.sales.v1.generated.ApiProto;
/**
* Contains metadata about the paged response
**/
public final class PagedResponseMetadata {
private final String nextCursor;
private final boolean hasMore;
private PagedResponseMetadata (
final String nextCursor,
final boolean hasMore)
{
this.nextCursor = nextCursor;
this.hasMore = hasMore;
}
/**
* 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;
}
public static class Builder {
private String nextCursor;
private boolean hasMore;
public Builder() {
this.nextCursor = "";
this.hasMore = false;
}
/**
* 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;
}
/**
* Takes the configuration in the mutable Builder and uses it to instantiate a final instance
* of the PagedResponseMetadata class
* @return The instantiated final PagedResponseMetadata
**/
public PagedResponseMetadata build() {
return new PagedResponseMetadata(
this.nextCursor,
this.hasMore);
}
}
/**
* Returns a Builder for PagedResponseMetadata, which is a mutable representation of the object. Once the
* client has built up an object they can then create an immutable PagedResponseMetadata 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 PagedResponseMetadata instance
**/
public String toString() {
String result = "PagedResponseMetadata\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";
return result;
}
/**
* Allows for simple conversion between the low-level generated protobuf object to
* PagedResponseMetadata, which is much more usable.
* @return An instance of PagedResponseMetadata representing the input proto object
**/
public static PagedResponseMetadata fromProto(ApiProto.PagedResponseMetadata proto) {
PagedResponseMetadata out = null;
if (proto != null) {
PagedResponseMetadata.Builder outBuilder = PagedResponseMetadata.newBuilder()
.setNextCursor(proto.getNextCursor())
.setHasMore(proto.getHasMore());
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 PagedResponseMetadata instances representing the input proto objects
**/
public static List fromProtos(List protos) {
List out = new ArrayList();
for(ApiProto.PagedResponseMetadata proto : protos) {
out.add(PagedResponseMetadata.fromProto(proto));
}
return out;
}
/**
* Allows for simple conversion of an object to the low-level generated protobuf object.
* @return An instance of ApiProto.PagedResponseMetadata which is a proto object ready for wire transmission
**/
public ApiProto.PagedResponseMetadata toProto() {
PagedResponseMetadata obj = this;
ApiProto.PagedResponseMetadata.Builder outBuilder = ApiProto.PagedResponseMetadata.newBuilder();
outBuilder.setNextCursor(obj.getNextCursor());
outBuilder.setHasMore(obj.getHasMore());
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.PagedResponseMetadata instances representing the input objects.
*/
public static List toProtos(List objects) {
List out = new ArrayList();
if(objects != null) {
for (PagedResponseMetadata obj : objects) {
out.add(obj!=null?obj.toProto():null);
}
}
return out;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy