/FileExtraction/Java_unseen/IMS-MAXIMS_openMAXIMS/Source Library/openmaxims_workspace/ValueObjects/src/ims/admin/vo/DateExpressionVo.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.admin.vo;

/**
 * Linked to core.admin.DateExpressionBo business object (ID: 1004100000).
 */
public class DateExpressionVo extends ims.core.admin.vo.DateExpressionBoRefVo implements ims.vo.ImsCloneable, Comparable
{
	private static final long serialVersionUID = 1L;

	public DateExpressionVo()
	{
	}
	public DateExpressionVo(Integer id, int version)
	{
		super(id, version);
	}
	public DateExpressionVo(ims.admin.vo.beans.DateExpressionVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.numberofunits = bean.getNumberofUnits();
		this.menuid = bean.getMenuId();
		this.name = bean.getName();
		this.startexprdate = bean.getStartExprDate();
		this.addoperator = bean.getAddOperator();
		this.rangeunit = bean.getRangeUnit();
		this.forms = ims.admin.vo.DateFormVoCollection.buildFromBeanCollection(bean.getForms());
		this.active = bean.getActive();
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.admin.vo.beans.DateExpressionVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.numberofunits = bean.getNumberofUnits();
		this.menuid = bean.getMenuId();
		this.name = bean.getName();
		this.startexprdate = bean.getStartExprDate();
		this.addoperator = bean.getAddOperator();
		this.rangeunit = bean.getRangeUnit();
		this.forms = ims.admin.vo.DateFormVoCollection.buildFromBeanCollection(bean.getForms());
		this.active = bean.getActive();
	}
	public ims.vo.ValueObjectBean getBean()
	{
		return this.getBean(new ims.vo.ValueObjectBeanMap());
	}
	public ims.vo.ValueObjectBean getBean(ims.vo.ValueObjectBeanMap map)
	{
		ims.admin.vo.beans.DateExpressionVoBean bean = null;
		if(map != null)
			bean = (ims.admin.vo.beans.DateExpressionVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.admin.vo.beans.DateExpressionVoBean();
			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("NUMBEROFUNITS"))
			return getNumberofUnits();
		if(fieldName.equals("MENUID"))
			return getMenuId();
		if(fieldName.equals("NAME"))
			return getName();
		if(fieldName.equals("STARTEXPRDATE"))
			return getStartExprDate();
		if(fieldName.equals("ADDOPERATOR"))
			return getAddOperator();
		if(fieldName.equals("RANGEUNIT"))
			return getRangeUnit();
		if(fieldName.equals("FORMS"))
			return getForms();
		if(fieldName.equals("ACTIVE"))
			return getActive();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getNumberofUnitsIsNotNull()
	{
		return this.numberofunits != null;
	}
	public Integer getNumberofUnits()
	{
		return this.numberofunits;
	}
	public void setNumberofUnits(Integer value)
	{
		this.isValidated = false;
		this.numberofunits = value;
	}
	public boolean getMenuIdIsNotNull()
	{
		return this.menuid != null;
	}
	public Integer getMenuId()
	{
		return this.menuid;
	}
	public void setMenuId(Integer value)
	{
		this.isValidated = false;
		this.menuid = value;
	}
	public boolean getNameIsNotNull()
	{
		return this.name != null;
	}
	public String getName()
	{
		return this.name;
	}
	public static int getNameMaxLength()
	{
		return 255;
	}
	public void setName(String value)
	{
		this.isValidated = false;
		this.name = value;
	}
	public boolean getStartExprDateIsNotNull()
	{
		return this.startexprdate != null;
	}
	public Integer getStartExprDate()
	{
		return this.startexprdate;
	}
	public void setStartExprDate(Integer value)
	{
		this.isValidated = false;
		this.startexprdate = value;
	}
	public boolean getAddOperatorIsNotNull()
	{
		return this.addoperator != null;
	}
	public Boolean getAddOperator()
	{
		return this.addoperator;
	}
	public void setAddOperator(Boolean value)
	{
		this.isValidated = false;
		this.addoperator = value;
	}
	public boolean getRangeUnitIsNotNull()
	{
		return this.rangeunit != null;
	}
	public Integer getRangeUnit()
	{
		return this.rangeunit;
	}
	public void setRangeUnit(Integer value)
	{
		this.isValidated = false;
		this.rangeunit = value;
	}
	public boolean getFormsIsNotNull()
	{
		return this.forms != null;
	}
	public ims.admin.vo.DateFormVoCollection getForms()
	{
		return this.forms;
	}
	public void setForms(ims.admin.vo.DateFormVoCollection value)
	{
		this.isValidated = false;
		this.forms = value;
	}
	public boolean getActiveIsNotNull()
	{
		return this.active != null;
	}
	public Boolean getActive()
	{
		return this.active;
	}
	public void setActive(Boolean value)
	{
		this.isValidated = false;
		this.active = value;
	}
	/**
	* getSartExprDateType
	*/
	public ims.framework.utils.DateReference getSartExprDateType()
	{
		if (this.startexprdate == null)
			return null;
		
		return ims.framework.utils.DateReference.getInstance(this.startexprdate.intValue());
	}
	/**
	* setSartExprDateType
	*/
	public void setSartExprDateType(ims.framework.utils.DateReference value)
	{
		if (value == null)
			this.startexprdate = null;
		else
			this.startexprdate = new Integer(value.getID());	
	}
		
	/**
	* getRangeUnitType
	*/
	public ims.framework.utils.DateUnit getRangeUnitType()
	{
		if (this.rangeunit == null)
			return null;
		
		return ims.framework.utils.DateUnit.getInstance(this.rangeunit.intValue());
	}
	/**
	* setRangeUnitType
	*/
	public void setRangeUnitType(ims.framework.utils.DateUnit value)
	{
		if (value == null)
			this.rangeunit = null;
		else
			this.rangeunit = new Integer(value.getID());
	}
	/**
	* toString
	*/
	public String toString()
	{
		StringBuffer sb = new StringBuffer();
	
		ims.framework.utils.DateReference startExpr = getSartExprDateType();
		
		if(startExpr != null)
		{
			sb.append(startExpr.toString());
			sb.append(" ");
		}
		
		if (this.addoperator.booleanValue())
			sb.append("+");
		else
			sb.append("-");
		
		sb.append(" ");
		
		if (this.numberofunits != null)
		{
			sb.append(this.numberofunits.toString());
			sb.append(" ");
		}
			
		ims.framework.utils.DateUnit dateUnit = getRangeUnitType();
		
		if(dateUnit != null)
		{
			sb.append(dateUnit.toString());
			sb.append(" ");
		}
		
		return sb.toString();
	}
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.forms != null)
		{
			if(!this.forms.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.menuid == null)
			listOfErrors.add("MenuId is mandatory");
		if(this.name == null || this.name.length() == 0)
			listOfErrors.add("Name is mandatory");
		if(this.startexprdate == null)
			listOfErrors.add("StartExprDate is mandatory");
		if(this.forms != null)
		{
			String[] listOfOtherErrors = this.forms.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;
	
		DateExpressionVo clone = new DateExpressionVo(this.id, this.version);
		
		clone.numberofunits = this.numberofunits;
		clone.menuid = this.menuid;
		clone.name = this.name;
		clone.startexprdate = this.startexprdate;
		clone.addoperator = this.addoperator;
		clone.rangeunit = this.rangeunit;
		if(this.forms == null)
			clone.forms = null;
		else
			clone.forms = (ims.admin.vo.DateFormVoCollection)this.forms.clone();
		clone.active = this.active;
		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 (!(DateExpressionVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A DateExpressionVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		DateExpressionVo compareObj = (DateExpressionVo)obj;
		int retVal = 0;
		if (retVal == 0)
		{
			if(this.getID_DateExpressionBo() == null && compareObj.getID_DateExpressionBo() != null)
				return -1;
			if(this.getID_DateExpressionBo() != null && compareObj.getID_DateExpressionBo() == null)
				return 1;
			if(this.getID_DateExpressionBo() != null && compareObj.getID_DateExpressionBo() != null)
				retVal = this.getID_DateExpressionBo().compareTo(compareObj.getID_DateExpressionBo());
		}
		return retVal;
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = 0;
		if(this.numberofunits != null)
			count++;
		if(this.menuid != null)
			count++;
		if(this.name != null)
			count++;
		if(this.startexprdate != null)
			count++;
		if(this.addoperator != null)
			count++;
		if(this.rangeunit != null)
			count++;
		if(this.forms != null)
			count++;
		if(this.active != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return 8;
	}
	protected Integer numberofunits;
	protected Integer menuid;
	protected String name;
	protected Integer startexprdate;
	protected Boolean addoperator;
	protected Integer rangeunit;
	protected ims.admin.vo.DateFormVoCollection forms;
	protected Boolean active;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
