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

com.vendasta.salesorders.v1.internal.Package Maven / Gradle / Ivy

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;

/**
 * Representing a package in an order
 **/
public final class Package {




	private final String packageId;
	private final Currency currency;
	private final Revenue revenue;
	private final long quantity;
	private final List productIds;
	private final List addonKeys;
	

	private Package (
		final String packageId,
		final Currency currency,
		final Revenue revenue,
		final long quantity,
		final List productIds,
		final List addonKeys)
		
	{
		this.packageId = packageId;
		this.currency = currency;
		this.revenue = revenue;
		this.quantity = quantity;
		this.productIds = productIds;
		this.addonKeys = addonKeys;
		
	}
	
	/**
	 * Unique identifier of a package
      * @return The final value of packageId on the object
	 **/
	public String getPackageId() {
		return this.packageId;
	}
	
	/**
	 * Type of currency the revenue of a package is in
      * @return The final value of currency on the object
	 **/
	public Currency getCurrency() {
		return this.currency;
	}
	
	/**
	 * Revenue of a package
      * @return The final value of revenue on the object
	 **/
	public Revenue getRevenue() {
		return this.revenue;
	}
	
	/**
	 * How many of the package is being requested
      * @return The final value of quantity on the object
	 **/
	public long getQuantity() {
		return this.quantity;
	}
	
	/**
	 * List of unique identifiers for the products that belong to the package
      * @return The final value of productIds on the object
	 **/
	public List getProductIds() {
		return this.productIds;
	}
	
	/**
	 * List of addon keys that belong to the package
      * @return The final value of addonKeys on the object
	 **/
	public List getAddonKeys() {
		return this.addonKeys;
	}
	

	public static class Builder {
		private String packageId;
		private Currency currency;
		private Revenue revenue;
		private long quantity;
		private List productIds;
		private List addonKeys;
		
		public Builder() {
			this.packageId = "";
			this.currency = null;
			this.revenue = null;
			this.quantity = 0;
			this.productIds = new ArrayList();
			this.addonKeys = null;
			
		}
		
		/**
		  * Adds a value to the builder for packageId
		  * @param packageId Value to assign to the mutable Builder
		  * @return The Builder instance so that call chaining works
		 **/
		public Builder setPackageId(String packageId) {
			this.packageId = packageId;
			return this;
		}
		
		/**
		  * Adds a value to the builder for currency
		  * @param currency Value to assign to the mutable Builder
		  * @return The Builder instance so that call chaining works
		 **/
		public Builder setCurrency(Currency currency) {
			this.currency = currency;
			return this;
		}
		
		/**
		  * Adds a value to the builder for revenue
		  * @param revenue Value to assign to the mutable Builder
		  * @return The Builder instance so that call chaining works
		 **/
		public Builder setRevenue(Revenue revenue) {
			this.revenue = revenue;
			return this;
		}
		
		/**
		  * Adds a value to the builder for quantity
		  * @param quantity Value to assign to the mutable Builder
		  * @return The Builder instance so that call chaining works
		 **/
		public Builder setQuantity(long quantity) {
			this.quantity = quantity;
			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 Package class
		  * @return The instantiated final Package
		 **/
		public Package build() {
			return new Package(
				this.packageId,
				this.currency,
				this.revenue,
				this.quantity,
				this.productIds,
				this.addonKeys);
		}
	}

	/**
	 * Returns a Builder for Package, which is a mutable representation of the object.  Once the
	 * client has built up an object they can then create an immutable Package 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 Package instance
	 **/
	 public String toString() {
		 String result = "Package\n";
		 result += "-> packageId: (String)"
		     + StringUtils.join("\n  ", Arrays.asList(String.valueOf(this.packageId).split("\n"))) + "\n"; 
		 result += "-> currency: (Currency)"
		     + StringUtils.join("\n  ", Arrays.asList(String.valueOf(this.currency).split("\n"))) + "\n"; 
		 result += "-> revenue: (Revenue)"
		     + StringUtils.join("\n  ", Arrays.asList(String.valueOf(this.revenue).split("\n"))) + "\n"; 
		 result += "-> quantity: (long)"
		     + StringUtils.join("\n  ", Arrays.asList(String.valueOf(this.quantity).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
	* Package, which is much more usable.
	* @return An instance of Package representing the input proto object
	**/
	public static Package fromProto(SalesOrdersProto.Package proto) {
		Package out = null;
		if (proto != null) {
			Package.Builder outBuilder = Package.newBuilder()
			.setPackageId(proto.getPackageId())
			.setCurrency(Currency.fromProto(proto.getCurrency()))
			.setRevenue(Revenue.fromProto(proto.getRevenue()))
			.setQuantity(proto.getQuantity())
			.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 Package instances representing the input proto objects
	**/
	public static List fromProtos(List protos) {
		List out = new ArrayList();
		for(SalesOrdersProto.Package proto : protos) {
			out.add(Package.fromProto(proto));
		}
		return out;
	}

	/**
	 * Allows for simple conversion of an object to the low-level generated protobuf object.
	 * @return An instance of SalesOrdersProto.Package which is a proto object ready for wire transmission
	 **/
	 public SalesOrdersProto.Package toProto() {
		 Package obj = this;
		 SalesOrdersProto.Package.Builder outBuilder = SalesOrdersProto.Package.newBuilder();
		 outBuilder.setPackageId(obj.getPackageId());
		 outBuilder.setCurrency(obj.getCurrency() != null?obj.getCurrency().toProto():null);
		 if(obj.getRevenue() != null){outBuilder.setRevenue(obj.getRevenue().toProto());}
		 outBuilder.setQuantity(obj.getQuantity());
		 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.Package instances representing the input objects.
	  */
	public static List toProtos(List objects) {
		List out = new ArrayList();
		if(objects != null) {
			for (Package obj : objects) {
				out.add(obj!=null?obj.toProto():null);
			}
		}
		return out;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy