/FileExtraction/Java_unseen/IMS-MAXIMS_openMAXIMS/Source Library/openmaxims_workspace/ValueObjects/src/ims/core/vo/BedSpaceVo.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.layout.BedSpace business object (ID: 1095100003).
 */
public class BedSpaceVo extends ims.core.vo.BedSpaceLiteVo implements ims.vo.ImsCloneable, Comparable
{
	private static final long serialVersionUID = 1L;

	public BedSpaceVo()
	{
	}
	public BedSpaceVo(Integer id, int version)
	{
		super(id, version);
	}
	public BedSpaceVo(ims.core.vo.beans.BedSpaceVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.bedspacetype = bean.getBedSpaceType() == null ? null : ims.core.vo.lookups.BedSpaceType.buildLookup(bean.getBedSpaceType());
		this.description = bean.getDescription();
		this.wardtype = bean.getWardType() == null ? null : ims.core.vo.lookups.WardType.buildLookup(bean.getWardType());
		this.bednumber = bean.getBedNumber();
		this.privatebed = bean.getPrivateBed();
		this.vml = bean.getVml();
		this.textposition = bean.getTextPosition();
		this.imageposition = bean.getImagePosition();
		this.dependency = bean.getDependency() == null ? null : ims.core.vo.lookups.BayDependencyLevel.buildLookup(bean.getDependency());
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.core.vo.beans.BedSpaceVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.bedspacetype = bean.getBedSpaceType() == null ? null : ims.core.vo.lookups.BedSpaceType.buildLookup(bean.getBedSpaceType());
		this.description = bean.getDescription();
		this.wardtype = bean.getWardType() == null ? null : ims.core.vo.lookups.WardType.buildLookup(bean.getWardType());
		this.bednumber = bean.getBedNumber();
		this.privatebed = bean.getPrivateBed();
		this.vml = bean.getVml();
		this.textposition = bean.getTextPosition();
		this.imageposition = bean.getImagePosition();
		this.dependency = bean.getDependency() == null ? null : ims.core.vo.lookups.BayDependencyLevel.buildLookup(bean.getDependency());
	}
	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.BedSpaceVoBean bean = null;
		if(map != null)
			bean = (ims.core.vo.beans.BedSpaceVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.core.vo.beans.BedSpaceVoBean();
			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("VML"))
			return getVml();
		if(fieldName.equals("TEXTPOSITION"))
			return getTextPosition();
		if(fieldName.equals("IMAGEPOSITION"))
			return getImagePosition();
		if(fieldName.equals("DEPENDENCY"))
			return getDependency();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getVmlIsNotNull()
	{
		return this.vml != null;
	}
	public String getVml()
	{
		return this.vml;
	}
	public static int getVmlMaxLength()
	{
		return 2000;
	}
	public void setVml(String value)
	{
		this.isValidated = false;
		this.vml = value;
	}
	public boolean getTextPositionIsNotNull()
	{
		return this.textposition != null;
	}
	public String getTextPosition()
	{
		return this.textposition;
	}
	public static int getTextPositionMaxLength()
	{
		return 1;
	}
	public void setTextPosition(String value)
	{
		this.isValidated = false;
		this.textposition = value;
	}
	public boolean getImagePositionIsNotNull()
	{
		return this.imageposition != null;
	}
	public String getImagePosition()
	{
		return this.imageposition;
	}
	public static int getImagePositionMaxLength()
	{
		return 1;
	}
	public void setImagePosition(String value)
	{
		this.isValidated = false;
		this.imageposition = value;
	}
	public boolean getDependencyIsNotNull()
	{
		return this.dependency != null;
	}
	public ims.core.vo.lookups.BayDependencyLevel getDependency()
	{
		return this.dependency;
	}
	public void setDependency(ims.core.vo.lookups.BayDependencyLevel value)
	{
		this.isValidated = false;
		this.dependency = value;
	}
	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.bedspacetype == null)
			listOfErrors.add("Bed Space Type is mandatory");
		if(this.description != null)
			if(this.description.length() > 255)
				listOfErrors.add("The length of the field [description] in the value object [ims.core.vo.BedSpaceVo] is too big. It should be less or equal to 255");
		if(this.wardtype == null)
			listOfErrors.add("Ward Type - Main/Side is mandatory");
		if(this.bednumber != null)
			if(this.bednumber.length() > 255)
				listOfErrors.add("The length of the field [bednumber] in the value object [ims.core.vo.BedSpaceVo] is too big. It should be less or equal to 255");
		if(this.vml == null || this.vml.length() == 0)
			listOfErrors.add("Vml is mandatory");
		else if(this.vml.length() > 2000)
			listOfErrors.add("The length of the field [vml] in the value object [ims.core.vo.BedSpaceVo] is too big. It should be less or equal to 2000");
		if(this.textposition == null || this.textposition.length() == 0)
			listOfErrors.add("TextPosition is mandatory");
		else if(this.textposition.length() > 1)
			listOfErrors.add("The length of the field [textposition] in the value object [ims.core.vo.BedSpaceVo] is too big. It should be less or equal to 1");
		if(this.imageposition == null || this.imageposition.length() == 0)
			listOfErrors.add("ImagePosition is mandatory");
		else if(this.imageposition.length() > 1)
			listOfErrors.add("The length of the field [imageposition] in the value object [ims.core.vo.BedSpaceVo] is too big. It should be less or equal to 1");
		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;
	
		BedSpaceVo clone = new BedSpaceVo(this.id, this.version);
		
		if(this.bedspacetype == null)
			clone.bedspacetype = null;
		else
			clone.bedspacetype = (ims.core.vo.lookups.BedSpaceType)this.bedspacetype.clone();
		clone.description = this.description;
		if(this.wardtype == null)
			clone.wardtype = null;
		else
			clone.wardtype = (ims.core.vo.lookups.WardType)this.wardtype.clone();
		clone.bednumber = this.bednumber;
		clone.privatebed = this.privatebed;
		clone.vml = this.vml;
		clone.textposition = this.textposition;
		clone.imageposition = this.imageposition;
		if(this.dependency == null)
			clone.dependency = null;
		else
			clone.dependency = (ims.core.vo.lookups.BayDependencyLevel)this.dependency.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 (!(BedSpaceVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A BedSpaceVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		if (this.id == null)
			return 1;
		if (((BedSpaceVo)obj).getBoId() == null)
			return -1;
		return this.id.compareTo(((BedSpaceVo)obj).getBoId());
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = super.countFieldsWithValue();
		if(this.vml != null)
			count++;
		if(this.textposition != null)
			count++;
		if(this.imageposition != null)
			count++;
		if(this.dependency != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return super.countValueObjectFields() + 4;
	}
	protected String vml;
	protected String textposition;
	protected String imageposition;
	protected ims.core.vo.lookups.BayDependencyLevel dependency;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
