/*******************************************************************************
 *  Copyright 2017 Centre for Development of Advanced Computing(C-DAC), Pune
 *  
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  
 *    http://www.apache.org/licenses/LICENSE-2.0
 *  
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *******************************************************************************/
package cdac.medinfo.sdk.hl7282.baselibs;

import cdac.medinfo.sdk.hl7282.baselibs.segmentfactory.DataElementFactory;
import cdac.medinfo.sdk.hl7282.commoninterface.IDataType;
import cdac.medinfo.sdk.hl7282.commoninterface.ISingleCollection;
import cdac.medinfo.sdk.hl7282.exceptions.InvalidComponentTypeException;
import cdac.medinfo.sdk.hl7282.utils.EnumDataType;
import cdac.medinfo.sdk.hl7282.utils.IDataTypeMap;

/**
 * MA - Multiplexed Array<p>
 * This data type This data type is used to represent channel-multiplexed waveform data, (e.g., the digitized
 *  values from an analog-to-digital converter or other digital data source). 
 * <p>Represents an HL7 MA data type. 
 * This data type has the following attributes:</p><p>
 *  1. Sample 1 From Channel 1 (NM)<b>Optional</b><br>
 *  2. Sample 1 From Channel 2 (NM)<b>Optional</b><br>
 *  3. Sample 1 From Channel N (NM)<b>Optional</b><br>
 *  4. Sample 2 From Channel 1 (NM)<b>Optional</b><br>
 *  5. Sample 2 From Channel N (NM)<b>Optional</b><br>
 *  6. Sample N From Channel N (NM)<b>Optional</b><br><p>
 * This class provides accessors & mutators for the elements mentioned above.
 * This class override the equal method, to check whether some other object is "equal to" this one.
 * 
 * <p>User can also create Data Type through {@link DataElementFactory} 
 */
public class MA extends CompositeDataType    
{
	

	/**
	 * Default Constructor for MA
	 */
	public MA()
	{
		super(EnumDataType.HL7_DT_MA);
		 
	}

	/**
	 * Constructor  for MA class which takes four arguments and 
	 * sets the value in the respective member variable.
	 * @param iMinLength The Minimum length the DataType can have.
	 * @param iMaxLength The Maximum length the DataType can have.
	 * @param iCLength The Conformance length the DataType can have.
	 * @param iComponentType The Type of the component i.e Component or a subcomponent.
	 * @throws InvalidComponentTypeException - if Component Type is not specified or valid. 
	 */ 
	public MA(int iMinLength, int iMaxLength, String strCLength,int iComponentType) throws InvalidComponentTypeException
	{
		super(EnumDataType.HL7_DT_MA);
		this.iMinLength = iMinLength;
		this.iMaxLength = iMaxLength;
		this.iConformanceLength = strCLength;
		this.iComponentType = iComponentType;
		if(!isValidComponentType())
		{
			throw new InvalidComponentTypeException(this.getClass().getSimpleName());
		}
	}

	/**
	 * Constructor for MA class which takes five arguments and 
	 * sets the value in the respective member variable.
	 * @param iMinLength The Minimum length the DataType can have.
	 * @param iMaxLength The Maximum length the DataType can have.
	 * @param iCLength The Conformance length the DataType can have.
	 * @param iTableNo The Table number to which the value for the component is specified. 
	 * @param iComponentType The Type of the component i.e Component or a subcomponent.
	 * @throws InvalidComponentTypeException - if Component Type is not specified or valid. 
	 */
	public MA(int iMinLength, int iMaxLength, String strCLength,int iTableNo,int iComponentType) throws InvalidComponentTypeException
	{
		super(EnumDataType.HL7_DT_MA);
		this.iMinLength = iMinLength;
		this.iMaxLength = iMaxLength;
		this.iConformanceLength = strCLength;
		this.iTableNo = iTableNo;
		this.iComponentType = iComponentType;
		if(!isValidComponentType())
		{
			throw new InvalidComponentTypeException(this.getClass().getSimpleName());		
		}
	}
	/**
	 * Constructor for MA class which takes two arguments and 
	 * sets the value in the respective member variable.
	 * @param objIDataTypeMap object of Data Type Map.
	 * @param iComponentType The Type of the component i.e Component or a subcomponent.
	 * @throws InvalidComponentTypeException - if Component Type is not specified or valid. 
	 */
	public MA(int iComponentType,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_MA);
		this.objIDataTypeMap = objIDataTypeMap;
		this.iComponentType = iComponentType;
		if(!isValidComponentType())
		{
			throw new InvalidComponentTypeException(this.getClass().getSimpleName());
		}
	}
	/**
	 * Constructor for MA class which takes five arguments and 
	 * sets the value in the respective member variable.
	 * @param objIDataTypeMap object of Data Type Map.
	 * @param iComponentType The Type of the component i.e Component or a subcomponent.
	 * @param iMinLength The Minimum length the DataType can have.
	 * @param iMaxLength The Maximum length the DataType can have.
	 * @param iCLength The Conformance length the DataType can have.
	 * @throws InvalidComponentTypeException - if Component Type is not specified or valid. 
	 */
	public MA(int iComponentType,int iMinLength, int iMaxLength, String strCLength,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_MA);
		this.objIDataTypeMap = objIDataTypeMap;
		this.iComponentType = iComponentType;
		this.iMinLength = iMinLength;
		this.iMaxLength = iMaxLength;
		this.iConformanceLength = strCLength;

		if(!isValidComponentType())
		{
			throw new InvalidComponentTypeException(this.getClass().getSimpleName());
		}
	}
	/**
	 * Constructor for MA class which takes six arguments and 
	 * sets the value in the respective member variable.
	 * @param objIDataTypeMap object of Data Type Map.
	 * @param iComponentType The Type of the component i.e Component or a subcomponent.
	 * @param iMinLength The Minimum length the DataType can have.
	 * @param iMaxLength The Maximum length the DataType can have.
	 * @param iCLength The Conformance length the DataType can have.
	 * @param iTableNo The Table number to which the value for the component is specified. 
	 * @throws InvalidComponentTypeException - if Component Type is not specified or valid. 
	 */
	public MA(int iComponentType,int iMinLength, int iMaxLength, String strCLength,int ITableNo,IDataTypeMap objIDataTypeMap)
	{
		super(EnumDataType.HL7_DT_MA);
		this.objIDataTypeMap = objIDataTypeMap;
		this.iComponentType = iComponentType;
		this.iTableNo = ITableNo;
		this.iMinLength = iMinLength;
		this.iMaxLength = iMaxLength;
		this.iConformanceLength = strCLength;

		if(!isValidComponentType())
		{
			throw new InvalidComponentTypeException(this.getClass().getSimpleName());
		}
	}


	/**
	 *Sets the Sample1FromChannel1.
	 *@param strSample1FromChannel1 Sample1 From Channel1 
	 */
	public void setSample1FromChannel1(String strSample1FromChannel1)
	{
		if(strSample1FromChannel1!=null)
			setComponentType(1, strSample1FromChannel1);
		else
			setSample1FromChannel1((NM)null);
	}


	/**
	 *Sets the Sample1FromChannel1.
	 *@param objNM Sample1 From Channel1
	 */
	public void setSample1FromChannel1(NM objNM)
	{
		setComponentType(1,objNM);
	}

	/**
	 *Sets the Sample1FromChannel2.
	 *@param strSample1FromChannel2 Sample1 From Channel2 
	 */
	public void setSample1FromChannel2(String strSample1FromChannel2)
	{
		if(strSample1FromChannel2!=null)
			setComponentType(2, strSample1FromChannel2);
		else
			setSample1FromChannel2((NM)null);
	}

	/**
	 *Sets the Sample1FromChannel2.
	 *@param objNM Sample1 From Channel2
	 */
	public void setSample1FromChannel2(NM objNM)
	{
		setComponentType(2,objNM);
	}

	/**
	 *Sets the Sample1FromChannelN.
	 *@param strSample1FromChannelN Sample1 From ChannelN 
	 */
	public void setSample1FromChannelN(String strSample1FromChannelN)
	{
		if(strSample1FromChannelN!=null)
			setComponentType(3, strSample1FromChannelN);
		else
			setSample1FromChannelN((NM)null);
	}

	/**
	 *Sets the Sample1FromChannelN.
	 *@param objNM Sample1 From ChannelN
	 */
	public void setSample1FromChannelN(NM objNM)
	{
		setComponentType(3,objNM);
	}

	/**
	 *Sets the Sample2FromChannel1.
	 *@param strSample2FromChannel1 Sample2 From Channel1 
	 */
	public void setSample2FromChannel1(String strSample2FromChannel1)
	{
		if(strSample2FromChannel1!=null)
			setComponentType(3, strSample2FromChannel1);
		else
			setSample2FromChannel1((NM)null);
	}

	/**
	 *Sets the Sample2FromChannel1.
	 *@param objNM Sample2 From Channel1
	 */
	public void setSample2FromChannel1(NM objNM)
	{
		setComponentType(4,objNM);
	}

	/**
	 *Sets the Sample2FromChannelN.
	 *@param strSample2FromChannelN Sample2 From ChannelN 
	 */
	public void setSample2FromChannelN(String strSample2FromChannelN)
	{
		if(strSample2FromChannelN!=null)
			setComponentType(5, strSample2FromChannelN);
		else
			setSample2FromChannelN((NM)null);
	}

	/**
	 *Sets the Sample2FromChannelN.
	 *@param objNM Sample2 From ChannelN
	 */
	public void setSample2FromChannelN(NM objNM)
	{
		setComponentType(5,objNM);
	}

	/**
	 *Sets the SampleNFromChannelN.
	 *@param strSampleNFromChannelN SampleN From ChannelN 
	 */
	public void setSampleNFromChannelN(String strSampleNFromChannelN)
	{
		if(strSampleNFromChannelN!=null)
			setComponentType(6, strSampleNFromChannelN);
		else
			setSampleNFromChannelN((NM)null);
	}

	/**
	 *Sets the SampleNFromChannelN.
	 *@param objNM SampleN From ChannelN
	 */
	public void setSampleNFromChannelN(NM objNM)
	{
		setComponentType(6,objNM);
	}

	/**
	 * Returns Sample 1 From Channel 1
	 * @return NM - data type.
	 */
	public NM getSample1FromChannel1()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(1);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (NM)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Sample 1 From Channel 2
	 * @return NM - data type.
	 */
	public NM getSample1FromChannel2()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(2);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (NM)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Sample 1 From Channel N 
	 * @return NM - data type.
	 */
	public NM getSample1FromChannelN()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(3);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (NM)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Sample 2 From Channel 1
	 * @return NM - data type.
	 */
	public NM getSample2FromChannel1()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(4);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (NM)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Sample 2 From Channel N
	 * @return NM - data type.
	 */
	public NM getSample2FromChannelN()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(5);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (NM)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Returns Sample N From Channel N
	 * @return NM - data type.
	 */
	public NM getSampleNFromChannelN()
	{
		ISingleCollection<IDataType> objDataCollection =getComponentType(6);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (NM)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * This method checks the equality of Object.
	 * @param objObject object of Object class.
	 * @return boolean - shows success or failure of the comparison.
	 */
	public boolean equals(Object objObject)
	{
		if((objObject == null ) || (!(objObject instanceof MA)))
			return false;

		if(this.getSample1FromChannel1() == null)
		{
			if(((MA)objObject).getSample1FromChannel1() != null)
				return false;
		}
		else if(false == (this.getSample1FromChannel1().equals(((MA)objObject).getSample1FromChannel1())))
			return false;

		if(this.getSample1FromChannel2() == null)
		{
			if(((MA)objObject).getSample1FromChannel2() != null)
				return false;
		}
		else if(false == (this.getSample1FromChannel2().equals(((MA)objObject).getSample1FromChannel2())))
			return false;

		if(this.getSample1FromChannelN() == null)
		{
			if(((MA)objObject).getSample1FromChannelN() != null)
				return false;
		}
		else if(false == (this.getSample1FromChannelN().equals(((MA)objObject).getSample1FromChannelN())))
			return false;

		if(this.getSample2FromChannel1() == null)
		{
			if(((MA)objObject).getSample2FromChannel1() != null)
				return false;
		}
		else if(false == (this.getSample2FromChannel1().equals(((MA)objObject).getSample2FromChannel1())))
			return false;

		if(this.getSample2FromChannelN() == null)
		{
			if(((MA)objObject).getSample2FromChannelN() != null)
				return false;
		}
		else if(false == (this.getSample2FromChannelN().equals(((MA)objObject).getSample2FromChannelN())))
			return false;

		if(this.getSampleNFromChannelN() == null)
		{
			if(((MA)objObject).getSampleNFromChannelN() != null)
				return false;
		}
		else if(false == (this.getSampleNFromChannelN().equals(((MA)objObject).getSampleNFromChannelN())))
			return false;

		return true;
	}
}
