/**
 */
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.DecompositionUnitAdaptation;
import ua.ansymo.hintco.HintcoPackage;
import ua.ansymo.hintco.UnitAdaptation;
import ua.ansymo.hintco.UnitInstance;

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

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

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetUnit(UnitInstance newUnit, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newUnit, HintcoPackage.UNIT_ADAPTATION__UNIT, msgs);
		return msgs;
	}

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

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

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setParent(DecompositionUnitAdaptation newParent) {
		if (newParent != eInternalContainer() || (eContainerFeatureID() != HintcoPackage.UNIT_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_UNIT_ADAPTATION__CHILDREN, DecompositionUnitAdaptation.class, msgs);
			msgs = basicSetParent(newParent, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, HintcoPackage.UNIT_ADAPTATION__PARENT, newParent, newParent));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public UnitInstance adapted() {
		UnitInstance _unit = this.getUnit();
		boolean _tripleNotEquals = (_unit != null);
		if (_tripleNotEquals) {
			return this.getUnit();
		}
		DecompositionUnitAdaptation _parent = this.getParent();
		boolean _tripleEquals = (_parent == null);
		if (_tripleEquals) {
			return null;
		}
		return this.getParent().adapted();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case HintcoPackage.UNIT_ADAPTATION__UNIT:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetUnit((UnitInstance)otherEnd, msgs);
			case HintcoPackage.UNIT_ADAPTATION__PARENT:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetParent((DecompositionUnitAdaptation)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.UNIT_ADAPTATION__UNIT:
				return basicSetUnit(null, msgs);
			case HintcoPackage.UNIT_ADAPTATION__PARENT:
				return basicSetParent(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.UNIT_ADAPTATION__UNIT:
				return eInternalContainer().eInverseRemove(this, HintcoPackage.UNIT_INSTANCE__ADAPTATION, UnitInstance.class, msgs);
			case HintcoPackage.UNIT_ADAPTATION__PARENT:
				return eInternalContainer().eInverseRemove(this, HintcoPackage.DECOMPOSITION_UNIT_ADAPTATION__CHILDREN, DecompositionUnitAdaptation.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.UNIT_ADAPTATION__UNIT:
				if (resolve) return getUnit();
				return basicGetUnit();
			case HintcoPackage.UNIT_ADAPTATION__PARENT:
				if (resolve) return getParent();
				return basicGetParent();
		}
		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.UNIT_ADAPTATION__UNIT:
				setUnit((UnitInstance)newValue);
				return;
			case HintcoPackage.UNIT_ADAPTATION__PARENT:
				setParent((DecompositionUnitAdaptation)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case HintcoPackage.UNIT_ADAPTATION__UNIT:
				setUnit((UnitInstance)null);
				return;
			case HintcoPackage.UNIT_ADAPTATION__PARENT:
				setParent((DecompositionUnitAdaptation)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case HintcoPackage.UNIT_ADAPTATION__UNIT:
				return basicGetUnit() != null;
			case HintcoPackage.UNIT_ADAPTATION__PARENT:
				return basicGetParent() != 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.UNIT_ADAPTATION___ADAPTED:
				return adapted();
		}
		return super.eInvoke(operationID, arguments);
	}

} //UnitAdaptationImpl
