/**
 */
package ua.ansymo.hintco.impl;

import java.lang.reflect.InvocationTargetException;

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.util.EcoreUtil;

import ua.ansymo.hintco.Adaptation;
import ua.ansymo.hintco.DecompositionAdaptation;
import ua.ansymo.hintco.HintcoPackage;
import ua.ansymo.hintco.PortInstance;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Adaptation</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link ua.ansymo.hintco.impl.AdaptationImpl#getParent <em>Parent</em>}</li>
 *   <li>{@link ua.ansymo.hintco.impl.AdaptationImpl#getPort <em>Port</em>}</li>
 * </ul>
 *
 * @generated
 */
public abstract class AdaptationImpl extends AlternativeImpl implements Adaptation {
	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected AdaptationImpl() {
		super();
	}

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DecompositionAdaptation getParent() {
		if (eContainerFeatureID() != HintcoPackage.ADAPTATION__PARENT) return null;
		return (DecompositionAdaptation)eContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DecompositionAdaptation basicGetParent() {
		if (eContainerFeatureID() != HintcoPackage.ADAPTATION__PARENT) return null;
		return (DecompositionAdaptation)eInternalContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetParent(DecompositionAdaptation newParent, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newParent, HintcoPackage.ADAPTATION__PARENT, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setParent(DecompositionAdaptation newParent) {
		if (newParent != eInternalContainer() || (eContainerFeatureID() != HintcoPackage.ADAPTATION__PARENT && newParent != null)) {
			if (EcoreUtil.isAncestor(this, newParent))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newParent != null)
				msgs = ((InternalEObject)newParent).eInverseAdd(this, HintcoPackage.DECOMPOSITION_ADAPTATION__CHILDREN, DecompositionAdaptation.class, msgs);
			msgs = basicSetParent(newParent, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, HintcoPackage.ADAPTATION__PARENT, newParent, newParent));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PortInstance getPort() {
		if (eContainerFeatureID() != HintcoPackage.ADAPTATION__PORT) return null;
		return (PortInstance)eContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PortInstance basicGetPort() {
		if (eContainerFeatureID() != HintcoPackage.ADAPTATION__PORT) return null;
		return (PortInstance)eInternalContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetPort(PortInstance newPort, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newPort, HintcoPackage.ADAPTATION__PORT, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPort(PortInstance newPort) {
		if (newPort != eInternalContainer() || (eContainerFeatureID() != HintcoPackage.ADAPTATION__PORT && newPort != null)) {
			if (EcoreUtil.isAncestor(this, newPort))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newPort != null)
				msgs = ((InternalEObject)newPort).eInverseAdd(this, HintcoPackage.PORT_INSTANCE__ADAPTATION, PortInstance.class, msgs);
			msgs = basicSetPort(newPort, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, HintcoPackage.ADAPTATION__PORT, newPort, newPort));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PortInstance adaptedPort() {
		PortInstance _port = this.getPort();
		boolean _tripleNotEquals = (_port != null);
		if (_tripleNotEquals) {
			return this.getPort();
		}
		DecompositionAdaptation _parent = this.getParent();
		boolean _tripleEquals = (_parent == null);
		if (_tripleEquals) {
			return null;
		}
		return this.getParent().adaptedPort();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case HintcoPackage.ADAPTATION__PARENT:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetParent((DecompositionAdaptation)otherEnd, msgs);
			case HintcoPackage.ADAPTATION__PORT:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetPort((PortInstance)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case HintcoPackage.ADAPTATION__PARENT:
				return basicSetParent(null, msgs);
			case HintcoPackage.ADAPTATION__PORT:
				return basicSetPort(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID()) {
			case HintcoPackage.ADAPTATION__PARENT:
				return eInternalContainer().eInverseRemove(this, HintcoPackage.DECOMPOSITION_ADAPTATION__CHILDREN, DecompositionAdaptation.class, msgs);
			case HintcoPackage.ADAPTATION__PORT:
				return eInternalContainer().eInverseRemove(this, HintcoPackage.PORT_INSTANCE__ADAPTATION, PortInstance.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case HintcoPackage.ADAPTATION__PARENT:
				if (resolve) return getParent();
				return basicGetParent();
			case HintcoPackage.ADAPTATION__PORT:
				if (resolve) return getPort();
				return basicGetPort();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case HintcoPackage.ADAPTATION__PARENT:
				setParent((DecompositionAdaptation)newValue);
				return;
			case HintcoPackage.ADAPTATION__PORT:
				setPort((PortInstance)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case HintcoPackage.ADAPTATION__PARENT:
				setParent((DecompositionAdaptation)null);
				return;
			case HintcoPackage.ADAPTATION__PORT:
				setPort((PortInstance)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case HintcoPackage.ADAPTATION__PARENT:
				return basicGetParent() != null;
			case HintcoPackage.ADAPTATION__PORT:
				return basicGetPort() != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eInvoke(int operationID, EList<?> arguments) throws InvocationTargetException {
		switch (operationID) {
			case HintcoPackage.ADAPTATION___ADAPTED_PORT:
				return adaptedPort();
		}
		return super.eInvoke(operationID, arguments);
	}

} //AdaptationImpl
