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

com.vendasta.sales.v1.internal.UserAction Maven / Gradle / Ivy

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.UserActionsProto;

/**
 * 
 **/
public final class UserAction {




	private final Date created;
	private final ActionCategory category;
	private final String description;
	

	private UserAction (
		final Date created,
		final ActionCategory category,
		final String description)
		
	{
		this.created = created;
		this.category = category;
		this.description = description;
		
	}
	
	/**
	 * The account group that the action is associated with
      * @return The final value of created on the object
	 **/
	public Date getCreated() {
		return this.created;
	}
	
	/**
	 * The category that the action is included in
      * @return The final value of category on the object
	 **/
	public ActionCategory getCategory() {
		return this.category;
	}
	
	/**
	 * The description of the event that occurred
      * @return The final value of description on the object
	 **/
	public String getDescription() {
		return this.description;
	}
	

	public static class Builder {
		private Date created;
		private ActionCategory category;
		private String description;
		
		public Builder() {
			this.created = null;
			this.category = null;
			this.description = "";
			
		}
		
		/**
		  * Adds a value to the builder for created
		  * @param created Value to assign to the mutable Builder
		  * @return The Builder instance so that call chaining works
		 **/
		public Builder setCreated(Date created) {
			this.created = created;
			return this;
		}
		
		/**
		  * Adds a value to the builder for category
		  * @param category Value to assign to the mutable Builder
		  * @return The Builder instance so that call chaining works
		 **/
		public Builder setCategory(ActionCategory category) {
			this.category = category;
			return this;
		}
		
		/**
		  * Adds a value to the builder for description
		  * @param description Value to assign to the mutable Builder
		  * @return The Builder instance so that call chaining works
		 **/
		public Builder setDescription(String description) {
			this.description = description;
			return this;
		}
		
		/**
		  * Takes the configuration in the mutable Builder and uses it to instantiate a final instance
		  * of the UserAction class
		  * @return The instantiated final UserAction
		 **/
		public UserAction build() {
			return new UserAction(
				this.created,
				this.category,
				this.description);
		}
	}

	/**
	 * Returns a Builder for UserAction, which is a mutable representation of the object.  Once the
	 * client has built up an object they can then create an immutable UserAction 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 UserAction instance
	 **/
	 public String toString() {
		 String result = "UserAction\n";
		 result += "-> created: (Date)"
		     + StringUtils.join("\n  ", Arrays.asList(String.valueOf(this.created).split("\n"))) + "\n"; 
		 result += "-> category: (ActionCategory)"
		     + StringUtils.join("\n  ", Arrays.asList(String.valueOf(this.category).split("\n"))) + "\n"; 
		 result += "-> description: (String)"
		     + StringUtils.join("\n  ", Arrays.asList(String.valueOf(this.description).split("\n"))) + "\n"; 
		 
		 return result;
	 }
	/**
	* Allows for simple conversion between the low-level generated protobuf object to
	* UserAction, which is much more usable.
	* @return An instance of UserAction representing the input proto object
	**/
	public static UserAction fromProto(UserActionsProto.UserAction proto) {
		UserAction out = null;
		if (proto != null) {
			UserAction.Builder outBuilder = UserAction.newBuilder()
			.setCreated(proto.hasCreated()?new Date(proto.getCreated().getSeconds() * 1000):null)
			.setCategory(ActionCategory.fromProto(proto.getCategory()))
			.setDescription(proto.getDescription());
			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 UserAction instances representing the input proto objects
	**/
	public static List fromProtos(List protos) {
		List out = new ArrayList();
		for(UserActionsProto.UserAction proto : protos) {
			out.add(UserAction.fromProto(proto));
		}
		return out;
	}

	/**
	 * Allows for simple conversion of an object to the low-level generated protobuf object.
	 * @return An instance of UserActionsProto.UserAction which is a proto object ready for wire transmission
	 **/
	 public UserActionsProto.UserAction toProto() {
		 UserAction obj = this;
		 UserActionsProto.UserAction.Builder outBuilder = UserActionsProto.UserAction.newBuilder();
		 if(obj.getCreated()!=null){outBuilder.setCreated(com.google.protobuf.Timestamp.newBuilder().setSeconds(obj.getCreated().getTime() / 1000).build());}
		 outBuilder.setCategory(obj.getCategory() != null?obj.getCategory().toProto():null);
		 outBuilder.setDescription(obj.getDescription());
		 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 UserActionsProto.UserAction instances representing the input objects.
	  */
	public static List toProtos(List objects) {
		List out = new ArrayList();
		if(objects != null) {
			for (UserAction obj : objects) {
				out.add(obj!=null?obj.toProto():null);
			}
		}
		return out;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy