/*******************************************************************************
 *  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.segments;

import cdac.medinfo.sdk.hl7282.commoninterface.ICollectionIterator;
import cdac.medinfo.sdk.hl7282.commoninterface.ISegment;
import cdac.medinfo.sdk.hl7282.commoninterface.ISegmentSet;
import cdac.medinfo.sdk.hl7282.commoninterface.ISingleCollection;
import cdac.medinfo.sdk.hl7282.unrecognized.UnRecognizedSegment;
import cdac.medinfo.sdk.hl7282.utils.SingleCollection;

/**
 * SegmentSet represents a list of Segments.
 * It provides required method to operate upon different segments which collectively represents a HL7 Message.
 */
public class SegmentSet implements ISegmentSet
{
	
	private ISingleCollection<ISegment> objSegmentList = null;
	private ISingleCollection<UnRecognizedSegment>  ObjUnRecognizedSegment = null;

	public SegmentSet()
	{
		objSegmentList = new SingleCollection<ISegment>();
		ObjUnRecognizedSegment = new SingleCollection<UnRecognizedSegment>();
	}

	/**
	 * Adds a segment in list.
	 * @param objSegment instance of segment
	 */
	public void addSegment(ISegment objSegment)
	{
		objSegmentList.add(objSegment);
	}

	/**
	 * Add UnRecodnizedSegment in list
	 * @param objUnRecognizedSegment object of unrecognizedSegment.
	 */
	public void addUnRecognizedSegment(UnRecognizedSegment objUnRecognizedSegment) {
		ObjUnRecognizedSegment.add(objUnRecognizedSegment);
	}
	/**
	 * Retrieves list of Unrecognized segments.
	 * @return Isinglecollection<UnRecognizedSegment> - list of UnRecognized Segment.
	 */
	public ISingleCollection<UnRecognizedSegment> getUnRecognizedSegments() {
		
		return ObjUnRecognizedSegment;
	} 
	/**
	 * Retrieves list of segments
	 * @return ISingleCollection<ISegment> - list of segments.
	 */
	public ISingleCollection<ISegment> getList()
	{
		return objSegmentList;
	}

	/**
	 * Retrieves a Segment from a given index position.
	 * @param iIndex value of index
	 * @return ISegment - instance of Segment
	 */
	public ISegment getSegment(int iIndex)
	{
		if(iIndex >= objSegmentList.size())
			return null;

		return objSegmentList.elementAt(iIndex);
	}

	/**
	 * Provides iterator over the collection of Segments
	 * @return ICollectionIterator<ISegment> - custom iterator over the collection of Segments
	 */
	public ICollectionIterator<ISegment> iterator()
	{
		return objSegmentList.iterator();
	}

	/**
	 * Retrieves size of SegmentSet
	 * @return int - size of set
	 */
	public int size()
	{
		return objSegmentList.size();
	}
}
