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

com.vendasta.salesorders.v1.internal.Field 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;

/**
 * Represents an information field pertaining to a product
 **/
public final class Field {




	private final String fieldId;
	private final String answer;
	private final FieldType fieldType;
	private final String label;
	private final String description;
	private final String prefix;
	private final String suffix;
	private final String regexValidator;
	private final String regexErrorMessage;
	

	private Field (
		final String fieldId,
		final String answer,
		final FieldType fieldType,
		final String label,
		final String description,
		final String prefix,
		final String suffix,
		final String regexValidator,
		final String regexErrorMessage)
		
	{
		this.fieldId = fieldId;
		this.answer = answer;
		this.fieldType = fieldType;
		this.label = label;
		this.description = description;
		this.prefix = prefix;
		this.suffix = suffix;
		this.regexValidator = regexValidator;
		this.regexErrorMessage = regexErrorMessage;
		
	}
	
	/**
	 * Unique identifier of a custom or common field
      * @return The final value of fieldId on the object
	 **/
	public String getFieldId() {
		return this.fieldId;
	}
	
	/**
	 * Response related to the question of the field_id
      * @return The final value of answer on the object
	 **/
	public String getAnswer() {
		return this.answer;
	}
	
	/**
	 * The type of field
      * @return The final value of fieldType on the object
	 **/
	public FieldType getFieldType() {
		return this.fieldType;
	}
	
	/**
	 * The question for the custom or common field
      * @return The final value of label on the object
	 **/
	public String getLabel() {
		return this.label;
	}
	
	/**
	 * The description of the field
      * @return The final value of description on the object
	 **/
	public String getDescription() {
		return this.description;
	}
	
	/**
	 * For textbox fields, this string will be displayed in front of the textbox
      * @return The final value of prefix on the object
	 **/
	public String getPrefix() {
		return this.prefix;
	}
	
	/**
	 * For textbox fields, this string will be displayed behind the textbox
      * @return The final value of suffix on the object
	 **/
	public String getSuffix() {
		return this.suffix;
	}
	
	/**
	 * A regex string used to validate a fields answer
      * @return The final value of regexValidator on the object
	 **/
	public String getRegexValidator() {
		return this.regexValidator;
	}
	
	/**
	 * The error message displayed if the regex_validator does not match the answer
      * @return The final value of regexErrorMessage on the object
	 **/
	public String getRegexErrorMessage() {
		return this.regexErrorMessage;
	}
	

	public static class Builder {
		private String fieldId;
		private String answer;
		private FieldType fieldType;
		private String label;
		private String description;
		private String prefix;
		private String suffix;
		private String regexValidator;
		private String regexErrorMessage;
		
		public Builder() {
			this.fieldId = "";
			this.answer = "";
			this.fieldType = null;
			this.label = "";
			this.description = "";
			this.prefix = "";
			this.suffix = "";
			this.regexValidator = "";
			this.regexErrorMessage = "";
			
		}
		
		/**
		  * Adds a value to the builder for fieldId
		  * @param fieldId Value to assign to the mutable Builder
		  * @return The Builder instance so that call chaining works
		 **/
		public Builder setFieldId(String fieldId) {
			this.fieldId = fieldId;
			return this;
		}
		
		/**
		  * Adds a value to the builder for answer
		  * @param answer Value to assign to the mutable Builder
		  * @return The Builder instance so that call chaining works
		 **/
		public Builder setAnswer(String answer) {
			this.answer = answer;
			return this;
		}
		
		/**
		  * Adds a value to the builder for fieldType
		  * @param fieldType Value to assign to the mutable Builder
		  * @return The Builder instance so that call chaining works
		 **/
		public Builder setFieldType(FieldType fieldType) {
			this.fieldType = fieldType;
			return this;
		}
		
		/**
		  * Adds a value to the builder for label
		  * @param label Value to assign to the mutable Builder
		  * @return The Builder instance so that call chaining works
		 **/
		public Builder setLabel(String label) {
			this.label = label;
			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;
		}
		
		/**
		  * Adds a value to the builder for prefix
		  * @param prefix Value to assign to the mutable Builder
		  * @return The Builder instance so that call chaining works
		 **/
		public Builder setPrefix(String prefix) {
			this.prefix = prefix;
			return this;
		}
		
		/**
		  * Adds a value to the builder for suffix
		  * @param suffix Value to assign to the mutable Builder
		  * @return The Builder instance so that call chaining works
		 **/
		public Builder setSuffix(String suffix) {
			this.suffix = suffix;
			return this;
		}
		
		/**
		  * Adds a value to the builder for regexValidator
		  * @param regexValidator Value to assign to the mutable Builder
		  * @return The Builder instance so that call chaining works
		 **/
		public Builder setRegexValidator(String regexValidator) {
			this.regexValidator = regexValidator;
			return this;
		}
		
		/**
		  * Adds a value to the builder for regexErrorMessage
		  * @param regexErrorMessage Value to assign to the mutable Builder
		  * @return The Builder instance so that call chaining works
		 **/
		public Builder setRegexErrorMessage(String regexErrorMessage) {
			this.regexErrorMessage = regexErrorMessage;
			return this;
		}
		
		/**
		  * Takes the configuration in the mutable Builder and uses it to instantiate a final instance
		  * of the Field class
		  * @return The instantiated final Field
		 **/
		public Field build() {
			return new Field(
				this.fieldId,
				this.answer,
				this.fieldType,
				this.label,
				this.description,
				this.prefix,
				this.suffix,
				this.regexValidator,
				this.regexErrorMessage);
		}
	}

	/**
	 * Returns a Builder for Field, which is a mutable representation of the object.  Once the
	 * client has built up an object they can then create an immutable Field 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 Field instance
	 **/
	 public String toString() {
		 String result = "Field\n";
		 result += "-> fieldId: (String)"
		     + StringUtils.join("\n  ", Arrays.asList(String.valueOf(this.fieldId).split("\n"))) + "\n"; 
		 result += "-> answer: (String)"
		     + StringUtils.join("\n  ", Arrays.asList(String.valueOf(this.answer).split("\n"))) + "\n"; 
		 result += "-> fieldType: (FieldType)"
		     + StringUtils.join("\n  ", Arrays.asList(String.valueOf(this.fieldType).split("\n"))) + "\n"; 
		 result += "-> label: (String)"
		     + StringUtils.join("\n  ", Arrays.asList(String.valueOf(this.label).split("\n"))) + "\n"; 
		 result += "-> description: (String)"
		     + StringUtils.join("\n  ", Arrays.asList(String.valueOf(this.description).split("\n"))) + "\n"; 
		 result += "-> prefix: (String)"
		     + StringUtils.join("\n  ", Arrays.asList(String.valueOf(this.prefix).split("\n"))) + "\n"; 
		 result += "-> suffix: (String)"
		     + StringUtils.join("\n  ", Arrays.asList(String.valueOf(this.suffix).split("\n"))) + "\n"; 
		 result += "-> regexValidator: (String)"
		     + StringUtils.join("\n  ", Arrays.asList(String.valueOf(this.regexValidator).split("\n"))) + "\n"; 
		 result += "-> regexErrorMessage: (String)"
		     + StringUtils.join("\n  ", Arrays.asList(String.valueOf(this.regexErrorMessage).split("\n"))) + "\n"; 
		 
		 return result;
	 }
	/**
	* Allows for simple conversion between the low-level generated protobuf object to
	* Field, which is much more usable.
	* @return An instance of Field representing the input proto object
	**/
	public static Field fromProto(SalesOrdersProto.Field proto) {
		Field out = null;
		if (proto != null) {
			Field.Builder outBuilder = Field.newBuilder()
			.setFieldId(proto.getFieldId())
			.setAnswer(proto.getAnswer())
			.setFieldType(FieldType.fromProto(proto.getFieldType()))
			.setLabel(proto.getLabel())
			.setDescription(proto.getDescription())
			.setPrefix(proto.getPrefix())
			.setSuffix(proto.getSuffix())
			.setRegexValidator(proto.getRegexValidator())
			.setRegexErrorMessage(proto.getRegexErrorMessage());
			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 Field instances representing the input proto objects
	**/
	public static List fromProtos(List protos) {
		List out = new ArrayList();
		for(SalesOrdersProto.Field proto : protos) {
			out.add(Field.fromProto(proto));
		}
		return out;
	}

	/**
	 * Allows for simple conversion of an object to the low-level generated protobuf object.
	 * @return An instance of SalesOrdersProto.Field which is a proto object ready for wire transmission
	 **/
	 public SalesOrdersProto.Field toProto() {
		 Field obj = this;
		 SalesOrdersProto.Field.Builder outBuilder = SalesOrdersProto.Field.newBuilder();
		 outBuilder.setFieldId(obj.getFieldId());
		 outBuilder.setAnswer(obj.getAnswer());
		 outBuilder.setFieldType(obj.getFieldType() != null?obj.getFieldType().toProto():null);
		 outBuilder.setLabel(obj.getLabel());
		 outBuilder.setDescription(obj.getDescription());
		 outBuilder.setPrefix(obj.getPrefix());
		 outBuilder.setSuffix(obj.getSuffix());
		 outBuilder.setRegexValidator(obj.getRegexValidator());
		 outBuilder.setRegexErrorMessage(obj.getRegexErrorMessage());
		 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.Field instances representing the input objects.
	  */
	public static List toProtos(List objects) {
		List out = new ArrayList();
		if(objects != null) {
			for (Field obj : objects) {
				out.add(obj!=null?obj.toProto():null);
			}
		}
		return out;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy