
com.vendasta.salesorders.v1.internal.CustomField Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of salesorders.v1 Show documentation
Show all versions of salesorders.v1 Show documentation
Java SDK for service sales-orders
The newest version!
package com.vendasta.salesorders.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.salesorders.v1.generated.SalesOrdersProto;
/**
* Represents the answer(s) to a custom field that is unique to a product
**/
public final class CustomField {
private final List fields;
private final String productId;
private final AddonKey addonKey;
private CustomField (
final List fields,
final String productId,
final AddonKey addonKey)
{
this.fields = fields;
this.productId = productId;
this.addonKey = addonKey;
}
/**
* List of custom fields for a given product
* @return The final value of fields on the object
**/
public List getFields() {
return this.fields;
}
/**
* Unique identifier of a single product that the custom questions belong to, and will not be provided if the custom field belongs to an addon
* @return The final value of productId on the object
**/
public String getProductId() {
return this.productId;
}
/**
* Addon key of an addon that the custom questions belong to, and will not be provided if the custom field belongs to a product
* @return The final value of addonKey on the object
**/
public AddonKey getAddonKey() {
return this.addonKey;
}
public static class Builder {
private List fields;
private String productId;
private AddonKey addonKey;
public Builder() {
this.fields = null;
this.productId = "";
this.addonKey = null;
}
/**
* Adds a value to the builder for fields
* @param fields Value to assign to the mutable Builder
* @return The Builder instance so that call chaining works
**/
public Builder setFields(List fields) {
this.fields = fields;
return this;
}
/**
* Adds a value to the builder for productId
* @param productId Value to assign to the mutable Builder
* @return The Builder instance so that call chaining works
**/
public Builder setProductId(String productId) {
this.productId = productId;
return this;
}
/**
* Adds a value to the builder for addonKey
* @param addonKey Value to assign to the mutable Builder
* @return The Builder instance so that call chaining works
**/
public Builder setAddonKey(AddonKey addonKey) {
this.addonKey = addonKey;
return this;
}
/**
* Takes the configuration in the mutable Builder and uses it to instantiate a final instance
* of the CustomField class
* @return The instantiated final CustomField
**/
public CustomField build() {
return new CustomField(
this.fields,
this.productId,
this.addonKey);
}
}
/**
* Returns a Builder for CustomField, which is a mutable representation of the object. Once the
* client has built up an object they can then create an immutable CustomField 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 CustomField instance
**/
public String toString() {
String result = "CustomField\n";
result += "-> fields: (List)"
+ StringUtils.join("\n ", Arrays.asList(String.valueOf(this.fields).split("\n"))) + "\n";
result += "-> productId: (String)"
+ StringUtils.join("\n ", Arrays.asList(String.valueOf(this.productId).split("\n"))) + "\n";
result += "-> addonKey: (AddonKey)"
+ StringUtils.join("\n ", Arrays.asList(String.valueOf(this.addonKey).split("\n"))) + "\n";
return result;
}
/**
* Allows for simple conversion between the low-level generated protobuf object to
* CustomField, which is much more usable.
* @return An instance of CustomField representing the input proto object
**/
public static CustomField fromProto(SalesOrdersProto.CustomField proto) {
CustomField out = null;
if (proto != null) {
CustomField.Builder outBuilder = CustomField.newBuilder()
.setFields(Field.fromProtos(proto.getFieldsList()))
.setProductId(proto.getProductId())
.setAddonKey(AddonKey.fromProto(proto.getAddonKey()));
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 CustomField instances representing the input proto objects
**/
public static List fromProtos(List protos) {
List out = new ArrayList();
for(SalesOrdersProto.CustomField proto : protos) {
out.add(CustomField.fromProto(proto));
}
return out;
}
/**
* Allows for simple conversion of an object to the low-level generated protobuf object.
* @return An instance of SalesOrdersProto.CustomField which is a proto object ready for wire transmission
**/
public SalesOrdersProto.CustomField toProto() {
CustomField obj = this;
SalesOrdersProto.CustomField.Builder outBuilder = SalesOrdersProto.CustomField.newBuilder();
outBuilder.addAllFields(Field.toProtos(obj.getFields()));
outBuilder.setProductId(obj.getProductId());
if(obj.getAddonKey() != null){outBuilder.setAddonKey(obj.getAddonKey().toProto());}
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 SalesOrdersProto.CustomField instances representing the input objects.
*/
public static List toProtos(List objects) {
List out = new ArrayList();
if(objects != null) {
for (CustomField obj : objects) {
out.add(obj!=null?obj.toProto():null);
}
}
return out;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy