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

import cdac.medinfo.sdk.hl7282.utils.IDataTypeMap;
import cdac.medinfo.sdk.hl7282.utils.IPairedCollection;
import cdac.medinfo.sdk.hl7282.utils.PairedCollection;

/**
 * This class implements a dictionary which contains entry for all the Composite DataType.
 * This is a singleton class means only single instance can be created of this class.
 */
class DataTypeDictionary
{
	/* 
	 * We have provided a PairedCollection which will encapsulate the Hashmap
	 * The key of the HashMap is an Integer.
	 */
	IPairedCollection<String, IDataTypeMap> objDataTypeMapList = null;

	private static DataTypeDictionary objDataTypeDictionary = null;

	/**
	 * Default private constructor for this class.
	 * It's a singleton class.
	 */
	private DataTypeDictionary()
	{
		objDataTypeMapList = new PairedCollection<String, IDataTypeMap>();
	}

	/**
	 * Creates instane of singleton class.
	 * @return DataDictionary - object of DataDictionary.
	 */
	static DataTypeDictionary createInstance()
	{
		if(objDataTypeDictionary == null)
			objDataTypeDictionary = new DataTypeDictionary();
		return objDataTypeDictionary;
	}

	/**
	 * Adds entry for new element in data dictionary.
	 * @param strDataTypeName Name of Data Type name.
	 * @param objDataTypeMap Object of DataType Map
	 * @return boolean - Shows success of addition process.
	 */
	boolean addDataTypeMap(String strDataTypeName,IDataTypeMap objDataTypeMap)
	{
		objDataTypeMap.setLock(true);
		objDataTypeMapList.put(strDataTypeName,objDataTypeMap);
		
		return true;
	}

	/**
	 * Retrieves Item list for the specified DataType.
	 * @param strDataTypeKey String value of DataType.
	 * @return ISingleCollection<ItemRowDescriptor> - Item list for the specified DataType.
	 */
	IDataTypeMap getDataTypeMap(String strDataTypeKey)
	{
		return objDataTypeMapList.get(strDataTypeKey);
	}

	/**
	 * Returns the status of Data Dictionary that it is populated or not.
	 * @param strDataTypeName Name of DataType.
	 * @return boolean - true, if Data Dictionary is populated.
	 */
	boolean isDataTypePopulated(String strDataTypeName)
	{
		if(objDataTypeMapList.contains(strDataTypeName))
			return true;
		return false;
	}
}
