/**
 */
package com.irtsaintexupery.pseim.mapping.impl;

import com.irtsaintexupery.pseim.mapping.MappingPackage;
import com.irtsaintexupery.pseim.mapping.PortMapping;

import com.irtsaintexupery.pseim.seim.BorderElement;

import java.util.Collection;
import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Port Mapping</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link com.irtsaintexupery.pseim.mapping.impl.PortMappingImpl#getModelPort <em>Model Port</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.mapping.impl.PortMappingImpl#getPatternPort <em>Pattern Port</em>}</li>
 * </ul>
 *
 * @generated
 */
public class PortMappingImpl extends MinimalEObjectImpl.Container implements PortMapping {
	/**
	 * The cached value of the '{@link #getModelPort() <em>Model Port</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getModelPort()
	 * @generated
	 * @ordered
	 */
	protected EList<BorderElement> modelPort;

	/**
	 * The cached value of the '{@link #getPatternPort() <em>Pattern Port</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPatternPort()
	 * @generated
	 * @ordered
	 */
	protected BorderElement patternPort;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected PortMappingImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return MappingPackage.Literals.PORT_MAPPING;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<BorderElement> getModelPort() {
		if (modelPort == null) {
			modelPort = new EObjectResolvingEList<BorderElement>(BorderElement.class, this, MappingPackage.PORT_MAPPING__MODEL_PORT);
		}
		return modelPort;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public BorderElement getPatternPort() {
		if (patternPort != null && patternPort.eIsProxy()) {
			InternalEObject oldPatternPort = (InternalEObject)patternPort;
			patternPort = (BorderElement)eResolveProxy(oldPatternPort);
			if (patternPort != oldPatternPort) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, MappingPackage.PORT_MAPPING__PATTERN_PORT, oldPatternPort, patternPort));
			}
		}
		return patternPort;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public BorderElement basicGetPatternPort() {
		return patternPort;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPatternPort(BorderElement newPatternPort) {
		BorderElement oldPatternPort = patternPort;
		patternPort = newPatternPort;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, MappingPackage.PORT_MAPPING__PATTERN_PORT, oldPatternPort, patternPort));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case MappingPackage.PORT_MAPPING__MODEL_PORT:
				return getModelPort();
			case MappingPackage.PORT_MAPPING__PATTERN_PORT:
				if (resolve) return getPatternPort();
				return basicGetPatternPort();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case MappingPackage.PORT_MAPPING__MODEL_PORT:
				getModelPort().clear();
				getModelPort().addAll((Collection<? extends BorderElement>)newValue);
				return;
			case MappingPackage.PORT_MAPPING__PATTERN_PORT:
				setPatternPort((BorderElement)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case MappingPackage.PORT_MAPPING__MODEL_PORT:
				getModelPort().clear();
				return;
			case MappingPackage.PORT_MAPPING__PATTERN_PORT:
				setPatternPort((BorderElement)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case MappingPackage.PORT_MAPPING__MODEL_PORT:
				return modelPort != null && !modelPort.isEmpty();
			case MappingPackage.PORT_MAPPING__PATTERN_PORT:
				return patternPort != null;
		}
		return super.eIsSet(featureID);
	}

} //PortMappingImpl
