
com.vendasta.accountgroup.v1.internal.SortOptions Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of accountgroup.v1 Show documentation
Show all versions of accountgroup.v1 Show documentation
Java SDK for service account-group
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;
/**
* Options for controlling the order of query results
**/
public final class SortOptions {
private final SortDirection direction;
private final SortField field;
private SortOptions (
final SortDirection direction,
final SortField field)
{
this.direction = direction;
this.field = field;
}
/**
* A direction to sort results in
* @return The final value of direction on the object
**/
public SortDirection getDirection() {
return this.direction;
}
/**
* Field to sort on
* @return The final value of field on the object
**/
public SortField getField() {
return this.field;
}
public static class Builder {
private SortDirection direction;
private SortField field;
public Builder() {
this.direction = null;
this.field = null;
}
/**
* Adds a value to the builder for direction
* @param direction Value to assign to the mutable Builder
* @return The Builder instance so that call chaining works
**/
public Builder setDirection(SortDirection direction) {
this.direction = direction;
return this;
}
/**
* Adds a value to the builder for field
* @param field Value to assign to the mutable Builder
* @return The Builder instance so that call chaining works
**/
public Builder setField(SortField field) {
this.field = field;
return this;
}
/**
* Takes the configuration in the mutable Builder and uses it to instantiate a final instance
* of the SortOptions class
* @return The instantiated final SortOptions
**/
public SortOptions build() {
return new SortOptions(
this.direction,
this.field);
}
}
/**
* Returns a Builder for SortOptions, which is a mutable representation of the object. Once the
* client has built up an object they can then create an immutable SortOptions 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 SortOptions instance
**/
public String toString() {
String result = "SortOptions\n";
result += "-> direction: (SortDirection)"
+ StringUtils.join("\n ", Arrays.asList(String.valueOf(this.direction).split("\n"))) + "\n";
result += "-> field: (SortField)"
+ StringUtils.join("\n ", Arrays.asList(String.valueOf(this.field).split("\n"))) + "\n";
return result;
}
/**
* Allows for simple conversion between the low-level generated protobuf object to
* SortOptions, which is much more usable.
* @return An instance of SortOptions representing the input proto object
**/
public static SortOptions fromProto(ApiProto.SortOptions proto) {
SortOptions out = null;
if (proto != null) {
SortOptions.Builder outBuilder = SortOptions.newBuilder()
.setDirection(SortDirection.fromProto(proto.getDirection()))
.setField(SortField.fromProto(proto.getField()));
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 SortOptions instances representing the input proto objects
**/
public static List fromProtos(List protos) {
List out = new ArrayList();
for(ApiProto.SortOptions proto : protos) {
out.add(SortOptions.fromProto(proto));
}
return out;
}
/**
* Allows for simple conversion of an object to the low-level generated protobuf object.
* @return An instance of ApiProto.SortOptions which is a proto object ready for wire transmission
**/
public ApiProto.SortOptions toProto() {
SortOptions obj = this;
ApiProto.SortOptions.Builder outBuilder = ApiProto.SortOptions.newBuilder();
outBuilder.setDirection(obj.getDirection() != null?obj.getDirection().toProto():null);
outBuilder.setField(obj.getField() != null?obj.getField().toProto():null);
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.SortOptions instances representing the input objects.
*/
public static List toProtos(List objects) {
List out = new ArrayList();
if(objects != null) {
for (SortOptions obj : objects) {
out.add(obj!=null?obj.toProto():null);
}
}
return out;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy