
com.vendasta.salesorders.v1.internal.CommonField 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 to a common field may be shared between products
**/
public final class CommonField {
private final Field field;
private final List productIds;
private final List addonKeys;
private CommonField (
final Field field,
final List productIds,
final List addonKeys)
{
this.field = field;
this.productIds = productIds;
this.addonKeys = addonKeys;
}
/**
* The field that may be shared by multiple products
* @return The final value of field on the object
**/
public Field getField() {
return this.field;
}
/**
* List of unique product identifiers that share the common field
* @return The final value of productIds on the object
**/
public List getProductIds() {
return this.productIds;
}
/**
* List of addon keys that share the common field
* @return The final value of addonKeys on the object
**/
public List getAddonKeys() {
return this.addonKeys;
}
public static class Builder {
private Field field;
private List productIds;
private List addonKeys;
public Builder() {
this.field = null;
this.productIds = new ArrayList();
this.addonKeys = null;
}
/**
* 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(Field field) {
this.field = field;
return this;
}
/**
* Adds a value to the builder for productIds
* @param productIds Value to assign to the mutable Builder
* @return The Builder instance so that call chaining works
**/
public Builder setProductIds(List productIds) {
this.productIds = productIds;
return this;
}
/**
* Adds a value to the builder for addonKeys
* @param addonKeys Value to assign to the mutable Builder
* @return The Builder instance so that call chaining works
**/
public Builder setAddonKeys(List addonKeys) {
this.addonKeys = addonKeys;
return this;
}
/**
* Takes the configuration in the mutable Builder and uses it to instantiate a final instance
* of the CommonField class
* @return The instantiated final CommonField
**/
public CommonField build() {
return new CommonField(
this.field,
this.productIds,
this.addonKeys);
}
}
/**
* Returns a Builder for CommonField, which is a mutable representation of the object. Once the
* client has built up an object they can then create an immutable CommonField 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 CommonField instance
**/
public String toString() {
String result = "CommonField\n";
result += "-> field: (Field)"
+ StringUtils.join("\n ", Arrays.asList(String.valueOf(this.field).split("\n"))) + "\n";
result += "-> productIds: (List)"
+ StringUtils.join("\n ", Arrays.asList(String.valueOf(this.productIds).split("\n"))) + "\n";
result += "-> addonKeys: (List)"
+ StringUtils.join("\n ", Arrays.asList(String.valueOf(this.addonKeys).split("\n"))) + "\n";
return result;
}
/**
* Allows for simple conversion between the low-level generated protobuf object to
* CommonField, which is much more usable.
* @return An instance of CommonField representing the input proto object
**/
public static CommonField fromProto(SalesOrdersProto.CommonField proto) {
CommonField out = null;
if (proto != null) {
CommonField.Builder outBuilder = CommonField.newBuilder()
.setField(Field.fromProto(proto.getField()))
.setProductIds(proto.getProductIdsList())
.setAddonKeys(AddonKey.fromProtos(proto.getAddonKeysList()));
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 CommonField instances representing the input proto objects
**/
public static List fromProtos(List protos) {
List out = new ArrayList();
for(SalesOrdersProto.CommonField proto : protos) {
out.add(CommonField.fromProto(proto));
}
return out;
}
/**
* Allows for simple conversion of an object to the low-level generated protobuf object.
* @return An instance of SalesOrdersProto.CommonField which is a proto object ready for wire transmission
**/
public SalesOrdersProto.CommonField toProto() {
CommonField obj = this;
SalesOrdersProto.CommonField.Builder outBuilder = SalesOrdersProto.CommonField.newBuilder();
if(obj.getField() != null){outBuilder.setField(obj.getField().toProto());}
outBuilder.addAllProductIds(obj.getProductIds());
outBuilder.addAllAddonKeys(AddonKey.toProtos(obj.getAddonKeys()));
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.CommonField instances representing the input objects.
*/
public static List toProtos(List objects) {
List out = new ArrayList();
if(objects != null) {
for (CommonField obj : objects) {
out.add(obj!=null?obj.toProto():null);
}
}
return out;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy