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

import com.irtsaintexupery.pseim.mapping.CardinalityValue;
import com.irtsaintexupery.pseim.mapping.GraphElementMapping;
import com.irtsaintexupery.pseim.mapping.MappingPackage;
import com.irtsaintexupery.pseim.mapping.PatternApplication;
import com.irtsaintexupery.pseim.mapping.PortMapping;

import com.irtsaintexupery.pseim.pseim.Pattern;

import com.irtsaintexupery.pseim.seim.Model;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

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.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Pattern Application</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link com.irtsaintexupery.pseim.mapping.impl.PatternApplicationImpl#getCardinalityValues <em>Cardinality Values</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.mapping.impl.PatternApplicationImpl#getPortMapping <em>Port Mapping</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.mapping.impl.PatternApplicationImpl#getPattern <em>Pattern</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.mapping.impl.PatternApplicationImpl#getModelElement <em>Model Element</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.mapping.impl.PatternApplicationImpl#getModel <em>Model</em>}</li>
 * </ul>
 *
 * @generated
 */
public class PatternApplicationImpl extends MinimalEObjectImpl.Container implements PatternApplication {
	/**
	 * The cached value of the '{@link #getCardinalityValues() <em>Cardinality Values</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCardinalityValues()
	 * @generated
	 * @ordered
	 */
	protected EList<CardinalityValue> cardinalityValues;

	/**
	 * The cached value of the '{@link #getPortMapping() <em>Port Mapping</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPortMapping()
	 * @generated
	 * @ordered
	 */
	protected EList<PortMapping> portMapping;

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

	/**
	 * The cached value of the '{@link #getModelElement() <em>Model Element</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getModelElement()
	 * @generated
	 * @ordered
	 */
	protected EList<GraphElementMapping> modelElement;

	/**
	 * The cached value of the '{@link #getModel() <em>Model</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getModel()
	 * @generated
	 * @ordered
	 */
	protected Model model;

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<CardinalityValue> getCardinalityValues() {
		if (cardinalityValues == null) {
			cardinalityValues = new EObjectContainmentEList<CardinalityValue>(CardinalityValue.class, this, MappingPackage.PATTERN_APPLICATION__CARDINALITY_VALUES);
		}
		return cardinalityValues;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<PortMapping> getPortMapping() {
		if (portMapping == null) {
			portMapping = new EObjectContainmentEList<PortMapping>(PortMapping.class, this, MappingPackage.PATTERN_APPLICATION__PORT_MAPPING);
		}
		return portMapping;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Pattern getPattern() {
		if (pattern != null && pattern.eIsProxy()) {
			InternalEObject oldPattern = (InternalEObject)pattern;
			pattern = (Pattern)eResolveProxy(oldPattern);
			if (pattern != oldPattern) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, MappingPackage.PATTERN_APPLICATION__PATTERN, oldPattern, pattern));
			}
		}
		return pattern;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Pattern basicGetPattern() {
		return pattern;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPattern(Pattern newPattern) {
		Pattern oldPattern = pattern;
		pattern = newPattern;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, MappingPackage.PATTERN_APPLICATION__PATTERN, oldPattern, pattern));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<GraphElementMapping> getModelElement() {
		if (modelElement == null) {
			modelElement = new EObjectContainmentEList<GraphElementMapping>(GraphElementMapping.class, this, MappingPackage.PATTERN_APPLICATION__MODEL_ELEMENT);
		}
		return modelElement;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Model getModel() {
		if (model != null && model.eIsProxy()) {
			InternalEObject oldModel = (InternalEObject)model;
			model = (Model)eResolveProxy(oldModel);
			if (model != oldModel) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, MappingPackage.PATTERN_APPLICATION__MODEL, oldModel, model));
			}
		}
		return model;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Model basicGetModel() {
		return model;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setModel(Model newModel) {
		Model oldModel = model;
		model = newModel;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, MappingPackage.PATTERN_APPLICATION__MODEL, oldModel, model));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case MappingPackage.PATTERN_APPLICATION__CARDINALITY_VALUES:
				return ((InternalEList<?>)getCardinalityValues()).basicRemove(otherEnd, msgs);
			case MappingPackage.PATTERN_APPLICATION__PORT_MAPPING:
				return ((InternalEList<?>)getPortMapping()).basicRemove(otherEnd, msgs);
			case MappingPackage.PATTERN_APPLICATION__MODEL_ELEMENT:
				return ((InternalEList<?>)getModelElement()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case MappingPackage.PATTERN_APPLICATION__CARDINALITY_VALUES:
				return getCardinalityValues();
			case MappingPackage.PATTERN_APPLICATION__PORT_MAPPING:
				return getPortMapping();
			case MappingPackage.PATTERN_APPLICATION__PATTERN:
				if (resolve) return getPattern();
				return basicGetPattern();
			case MappingPackage.PATTERN_APPLICATION__MODEL_ELEMENT:
				return getModelElement();
			case MappingPackage.PATTERN_APPLICATION__MODEL:
				if (resolve) return getModel();
				return basicGetModel();
		}
		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.PATTERN_APPLICATION__CARDINALITY_VALUES:
				getCardinalityValues().clear();
				getCardinalityValues().addAll((Collection<? extends CardinalityValue>)newValue);
				return;
			case MappingPackage.PATTERN_APPLICATION__PORT_MAPPING:
				getPortMapping().clear();
				getPortMapping().addAll((Collection<? extends PortMapping>)newValue);
				return;
			case MappingPackage.PATTERN_APPLICATION__PATTERN:
				setPattern((Pattern)newValue);
				return;
			case MappingPackage.PATTERN_APPLICATION__MODEL_ELEMENT:
				getModelElement().clear();
				getModelElement().addAll((Collection<? extends GraphElementMapping>)newValue);
				return;
			case MappingPackage.PATTERN_APPLICATION__MODEL:
				setModel((Model)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case MappingPackage.PATTERN_APPLICATION__CARDINALITY_VALUES:
				getCardinalityValues().clear();
				return;
			case MappingPackage.PATTERN_APPLICATION__PORT_MAPPING:
				getPortMapping().clear();
				return;
			case MappingPackage.PATTERN_APPLICATION__PATTERN:
				setPattern((Pattern)null);
				return;
			case MappingPackage.PATTERN_APPLICATION__MODEL_ELEMENT:
				getModelElement().clear();
				return;
			case MappingPackage.PATTERN_APPLICATION__MODEL:
				setModel((Model)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case MappingPackage.PATTERN_APPLICATION__CARDINALITY_VALUES:
				return cardinalityValues != null && !cardinalityValues.isEmpty();
			case MappingPackage.PATTERN_APPLICATION__PORT_MAPPING:
				return portMapping != null && !portMapping.isEmpty();
			case MappingPackage.PATTERN_APPLICATION__PATTERN:
				return pattern != null;
			case MappingPackage.PATTERN_APPLICATION__MODEL_ELEMENT:
				return modelElement != null && !modelElement.isEmpty();
			case MappingPackage.PATTERN_APPLICATION__MODEL:
				return model != null;
		}
		return super.eIsSet(featureID);
	}

} //PatternApplicationImpl
