package org.etsi.its.network;

import java.util.HashMap;
import java.util.LinkedHashMap;

/**
 * This class provides an implementation of <code>IUdpImpl</code> factory
 */
public class UdpFactory implements IUdpFactory {

	/**
	 * Unique instance of this factory
	 */
	private static IUdpFactory _instance = new UdpFactory();

	/**
	 * Map to associate UdpImpl instance with an identifier
	 * 
	 * @see IModuleEnum
	 */
	private HashMap<IModuleEnum, IUdpImpl> _impls;

	/**
	 * Internal constructor
	 */
	private UdpFactory() {
		_impls = new LinkedHashMap<IModuleEnum, IUdpImpl>();
	}

	/**
	 * This methods retrieve the unique instance of this factory
	 * @return The unique instance of this factory
	 */
	public static IUdpFactory getInstance() {
		return _instance;
	}

	/**
	 * This method creates a new instance of UdpImpl class and associate this instance to the provided identifier
	 * @param module An identifier to associate to the newly created instance
	 * @return A new instance of UdpImpl class
	 * 
	 * @see IModuleEnum
	 */
	@Override
	public IUdpImpl getUdpImpl(final IModuleEnum module) {
		if (!_impls.containsKey(module)) {
			_impls.put(module, new UdpImpl());
		}

		return _impls.get(module);
	} // End of method getUdpImpl

} // End of class UdpFactory
