/FileExtraction/Java_unseen/IMS-MAXIMS_openMAXIMS/Source Library/openmaxims_workspace/ValueObjects/src/ims/core/vo/AddressVo.java
//#############################################################################
//#                                                                           #
//#  Copyright (C) <2015>  <IMS MAXIMS>                                       #
//#                                                                           #
//#  This program is free software: you can redistribute it and/or modify     #
//#  it under the terms of the GNU Affero General Public License as           #
//#  published by the Free Software Foundation, either version 3 of the       #
//#  License, or (at your option) any later version.                          # 
//#                                                                           #
//#  This program is distributed in the hope that it will be useful,          #
//#  but WITHOUT ANY WARRANTY; without even the implied warranty of           #
//#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            #
//#  GNU Affero General Public License for more details.                      #
//#                                                                           #
//#  You should have received a copy of the GNU Affero General Public License #
//#  along with this program.  If not, see <http://www.gnu.org/licenses/>.    #
//#                                                                           #
//#  IMS MAXIMS provides absolutely NO GUARANTEE OF THE CLINICAL SAFTEY of    #
//#  this program.  Users of this software do so entirely at their own risk.  #
//#  IMS MAXIMS only ensures the Clinical Safety of unaltered run-time        #
//#  software that it builds, deploys and maintains.                          #
//#                                                                           #
//#############################################################################
//#EOH
// This code was generated by Barbara Worwood using IMS Development Environment (version 1.80 build 5589.25814)
// Copyright (C) 1995-2015 IMS MAXIMS. All rights reserved.
// WARNING: DO NOT MODIFY the content of this file

package ims.core.vo;

/**
 * Linked to core.generic.Address business object (ID: 1002100000).
 */
public class AddressVo extends ims.core.generic.vo.AddressRefVo implements ims.vo.ImsCloneable, Comparable
{
	private static final long serialVersionUID = 1L;

	public AddressVo()
	{
	}
	public AddressVo(Integer id, int version)
	{
		super(id, version);
	}
	public AddressVo(ims.core.vo.beans.AddressVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.line1 = bean.getLine1();
		this.line2 = bean.getLine2();
		this.line3 = bean.getLine3();
		this.line4 = bean.getLine4();
		this.line5 = bean.getLine5();
		this.postcode = bean.getPostCode();
		this.addresstype = bean.getAddressType() == null ? null : ims.core.vo.lookups.AddressType.buildLookup(bean.getAddressType());
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.core.vo.beans.AddressVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.line1 = bean.getLine1();
		this.line2 = bean.getLine2();
		this.line3 = bean.getLine3();
		this.line4 = bean.getLine4();
		this.line5 = bean.getLine5();
		this.postcode = bean.getPostCode();
		this.addresstype = bean.getAddressType() == null ? null : ims.core.vo.lookups.AddressType.buildLookup(bean.getAddressType());
	}
	public ims.vo.ValueObjectBean getBean()
	{
		return this.getBean(new ims.vo.ValueObjectBeanMap());
	}
	public ims.vo.ValueObjectBean getBean(ims.vo.ValueObjectBeanMap map)
	{
		ims.core.vo.beans.AddressVoBean bean = null;
		if(map != null)
			bean = (ims.core.vo.beans.AddressVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.core.vo.beans.AddressVoBean();
			map.addValueObjectBean(this, bean);
			bean.populate(map, this);
		}
		return bean;
	}
	public Object getFieldValueByFieldName(String fieldName)
	{
		if(fieldName == null)
			throw new ims.framework.exceptions.CodingRuntimeException("Invalid field name");
		fieldName = fieldName.toUpperCase();
		if(fieldName.equals("LINE1"))
			return getLine1();
		if(fieldName.equals("LINE2"))
			return getLine2();
		if(fieldName.equals("LINE3"))
			return getLine3();
		if(fieldName.equals("LINE4"))
			return getLine4();
		if(fieldName.equals("LINE5"))
			return getLine5();
		if(fieldName.equals("POSTCODE"))
			return getPostCode();
		if(fieldName.equals("ADDRESSTYPE"))
			return getAddressType();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getLine1IsNotNull()
	{
		return this.line1 != null;
	}
	public String getLine1()
	{
		return this.line1;
	}
	public static int getLine1MaxLength()
	{
		return 40;
	}
	public void setLine1(String value)
	{
		this.isValidated = false;
		this.line1 = value;
	}
	public boolean getLine2IsNotNull()
	{
		return this.line2 != null;
	}
	public String getLine2()
	{
		return this.line2;
	}
	public static int getLine2MaxLength()
	{
		return 40;
	}
	public void setLine2(String value)
	{
		this.isValidated = false;
		this.line2 = value;
	}
	public boolean getLine3IsNotNull()
	{
		return this.line3 != null;
	}
	public String getLine3()
	{
		return this.line3;
	}
	public static int getLine3MaxLength()
	{
		return 40;
	}
	public void setLine3(String value)
	{
		this.isValidated = false;
		this.line3 = value;
	}
	public boolean getLine4IsNotNull()
	{
		return this.line4 != null;
	}
	public String getLine4()
	{
		return this.line4;
	}
	public static int getLine4MaxLength()
	{
		return 40;
	}
	public void setLine4(String value)
	{
		this.isValidated = false;
		this.line4 = value;
	}
	public boolean getLine5IsNotNull()
	{
		return this.line5 != null;
	}
	public String getLine5()
	{
		return this.line5;
	}
	public static int getLine5MaxLength()
	{
		return 40;
	}
	public void setLine5(String value)
	{
		this.isValidated = false;
		this.line5 = value;
	}
	public boolean getPostCodeIsNotNull()
	{
		return this.postcode != null;
	}
	public String getPostCode()
	{
		return this.postcode;
	}
	public static int getPostCodeMaxLength()
	{
		return 10;
	}
	public void setPostCode(String value)
	{
		this.isValidated = false;
		this.postcode = value;
	}
	public boolean getAddressTypeIsNotNull()
	{
		return this.addresstype != null;
	}
	public ims.core.vo.lookups.AddressType getAddressType()
	{
		return this.addresstype;
	}
	public void setAddressType(ims.core.vo.lookups.AddressType value)
	{
		this.isValidated = false;
		this.addresstype = value;
	}
	/**
	* toString
	*/
	public String toString()
	{
		StringBuffer str = new StringBuffer();
		if(this.line1 != null)
			str.append(this.line1 );
			
		if(this.line2!= null)
		{
			str.append(", ");
			str.append(this.line2);
		}
		if(this.line3!= null)
		{
			str.append(", ");
			str.append(this.line3);
		}
		if(this.line4!= null)
		{
			str.append(", ");
			str.append(this.line4);
		}
		if(this.line5!= null)
		{
			str.append(", ");
			str.append(this.line5);
		}
	
		return str.toString();
	}
	
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		this.isBusy = false;
		return true;
	}
	public String[] validate()
	{
		return validate(null);
	}
	public String[] validate(String[] existingErrors)
	{
		if(this.isBusy)
			return null;
		this.isBusy = true;
	
		java.util.ArrayList<String> listOfErrors = new java.util.ArrayList<String>();
		if(existingErrors != null)
		{
			for(int x = 0; x < existingErrors.length; x++)
			{
				listOfErrors.add(existingErrors[x]);
			}
		}
		if(this.line1 != null)
			if(this.line1.length() > 40)
				listOfErrors.add("The length of the field [line1] in the value object [ims.core.vo.AddressVo] is too big. It should be less or equal to 40");
		if(this.line2 != null)
			if(this.line2.length() > 40)
				listOfErrors.add("The length of the field [line2] in the value object [ims.core.vo.AddressVo] is too big. It should be less or equal to 40");
		if(this.line3 != null)
			if(this.line3.length() > 40)
				listOfErrors.add("The length of the field [line3] in the value object [ims.core.vo.AddressVo] is too big. It should be less or equal to 40");
		if(this.line4 != null)
			if(this.line4.length() > 40)
				listOfErrors.add("The length of the field [line4] in the value object [ims.core.vo.AddressVo] is too big. It should be less or equal to 40");
		if(this.line5 != null)
			if(this.line5.length() > 40)
				listOfErrors.add("The length of the field [line5] in the value object [ims.core.vo.AddressVo] is too big. It should be less or equal to 40");
		if(this.postcode != null)
			if(this.postcode.length() > 10)
				listOfErrors.add("The length of the field [postcode] in the value object [ims.core.vo.AddressVo] is too big. It should be less or equal to 10");
		int errorCount = listOfErrors.size();
		if(errorCount == 0)
		{
			this.isBusy = false;
			this.isValidated = true;
			return null;
		}
		String[] result = new String[errorCount];
		for(int x = 0; x < errorCount; x++)
			result[x] = (String)listOfErrors.get(x);
		this.isBusy = false;
		this.isValidated = false;
		return result;
	}
	public void clearIDAndVersion()
	{
		this.id = null;
		this.version = 0;
	}
	public Object clone()
	{
		if(this.isBusy)
			return this;
		this.isBusy = true;
	
		AddressVo clone = new AddressVo(this.id, this.version);
		
		clone.line1 = this.line1;
		clone.line2 = this.line2;
		clone.line3 = this.line3;
		clone.line4 = this.line4;
		clone.line5 = this.line5;
		clone.postcode = this.postcode;
		if(this.addresstype == null)
			clone.addresstype = null;
		else
			clone.addresstype = (ims.core.vo.lookups.AddressType)this.addresstype.clone();
		clone.isValidated = this.isValidated;
		
		this.isBusy = false;
		return clone;
	}
	public int compareTo(Object obj)
	{
		return compareTo(obj, true);
	}
	public int compareTo(Object obj, boolean caseInsensitive)
	{
		if (obj == null)
		{
			return -1;
		}
		if(caseInsensitive); // this is to avoid eclipse warning only.
		if (!(AddressVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A AddressVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		if (this.id == null)
			return 1;
		if (((AddressVo)obj).getBoId() == null)
			return -1;
		return this.id.compareTo(((AddressVo)obj).getBoId());
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = 0;
		if(this.line1 != null)
			count++;
		if(this.line2 != null)
			count++;
		if(this.line3 != null)
			count++;
		if(this.line4 != null)
			count++;
		if(this.line5 != null)
			count++;
		if(this.postcode != null)
			count++;
		if(this.addresstype != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return 7;
	}
	protected String line1;
	protected String line2;
	protected String line3;
	protected String line4;
	protected String line5;
	protected String postcode;
	protected ims.core.vo.lookups.AddressType addresstype;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
