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

	public HCPLocationLiteVo()
	{
	}
	public HCPLocationLiteVo(Integer id, int version)
	{
		super(id, version);
	}
	public HCPLocationLiteVo(ims.core.vo.beans.HCPLocationLiteVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.location = bean.getLocation() == null ? null : bean.getLocation().buildVo();
		this.isprimary = bean.getIsPrimary();
		this.accreditationstatus = bean.getAccreditationStatus() == null ? null : ims.core.vo.lookups.AccreditationLocationStatus.buildLookup(bean.getAccreditationStatus());
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.core.vo.beans.HCPLocationLiteVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.location = bean.getLocation() == null ? null : bean.getLocation().buildVo(map);
		this.isprimary = bean.getIsPrimary();
		this.accreditationstatus = bean.getAccreditationStatus() == null ? null : ims.core.vo.lookups.AccreditationLocationStatus.buildLookup(bean.getAccreditationStatus());
	}
	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.HCPLocationLiteVoBean bean = null;
		if(map != null)
			bean = (ims.core.vo.beans.HCPLocationLiteVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.core.vo.beans.HCPLocationLiteVoBean();
			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("LOCATION"))
			return getLocation();
		if(fieldName.equals("ISPRIMARY"))
			return getIsPrimary();
		if(fieldName.equals("ACCREDITATIONSTATUS"))
			return getAccreditationStatus();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getLocationIsNotNull()
	{
		return this.location != null;
	}
	public ims.core.vo.LocShortVo getLocation()
	{
		return this.location;
	}
	public void setLocation(ims.core.vo.LocShortVo value)
	{
		this.isValidated = false;
		this.location = value;
	}
	public boolean getIsPrimaryIsNotNull()
	{
		return this.isprimary != null;
	}
	public Boolean getIsPrimary()
	{
		return this.isprimary;
	}
	public void setIsPrimary(Boolean value)
	{
		this.isValidated = false;
		this.isprimary = value;
	}
	public boolean getAccreditationStatusIsNotNull()
	{
		return this.accreditationstatus != null;
	}
	public ims.core.vo.lookups.AccreditationLocationStatus getAccreditationStatus()
	{
		return this.accreditationstatus;
	}
	public void setAccreditationStatus(ims.core.vo.lookups.AccreditationLocationStatus value)
	{
		this.isValidated = false;
		this.accreditationstatus = value;
	}
	/**
	* MixedSort
	*/
	public static HCPLocationLiteVoCollection mixedSort(HCPLocationLiteVoCollection coll)
	{
		return mixedSort(coll, ims.framework.enumerations.SortOrder.ASCENDING);
	}
	public static HCPLocationLiteVoCollection mixedSort(HCPLocationLiteVoCollection coll, ims.framework.enumerations.SortOrder order)
	{		
		return coll.sort(new HCPLocationLiteMixedVoComparator(order));
	}
	private static class HCPLocationLiteMixedVoComparator implements java.util.Comparator
	{
		private int direction = 1;
		public HCPLocationLiteMixedVoComparator()
		{
			this(ims.framework.enumerations.SortOrder.ASCENDING);
		}
		public HCPLocationLiteMixedVoComparator(ims.framework.enumerations.SortOrder order)
		{
			if (order == ims.framework.enumerations.SortOrder.DESCENDING)
			{
				direction = -1;
			}
		}
		public int compare(Object obj1, Object obj2)
		{
			HCPLocationLiteVo voObj1 = (HCPLocationLiteVo)obj1;
			HCPLocationLiteVo voObj2 = (HCPLocationLiteVo)obj2;
			return direction*(voObj1.getLocation().getName().compareTo(voObj2.getLocation().getName()));
		}
		public boolean equals(Object obj)
		{
			return false;
		}
	}
	/**
	* ILocation Implementation
	*/
	public int getID()
	{
		return getID_HcpLocation() == null ? 0 : getID_HcpLocation().intValue();
	}
	
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.location != null)
		{
			if(!this.location.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.location == null)
			listOfErrors.add("Location is mandatory");
		if(this.location != null)
		{
			String[] listOfOtherErrors = this.location.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		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;
	
		HCPLocationLiteVo clone = new HCPLocationLiteVo(this.id, this.version);
		
		if(this.location == null)
			clone.location = null;
		else
			clone.location = (ims.core.vo.LocShortVo)this.location.clone();
		clone.isprimary = this.isprimary;
		if(this.accreditationstatus == null)
			clone.accreditationstatus = null;
		else
			clone.accreditationstatus = (ims.core.vo.lookups.AccreditationLocationStatus)this.accreditationstatus.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 (!(HCPLocationLiteVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A HCPLocationLiteVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		if (this.id == null)
			return 1;
		if (((HCPLocationLiteVo)obj).getBoId() == null)
			return -1;
		return this.id.compareTo(((HCPLocationLiteVo)obj).getBoId());
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = 0;
		if(this.location != null)
			count++;
		if(this.isprimary != null)
			count++;
		if(this.accreditationstatus != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return 3;
	}
	protected ims.core.vo.LocShortVo location;
	protected Boolean isprimary;
	protected ims.core.vo.lookups.AccreditationLocationStatus accreditationstatus;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
