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

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

import ua.ansymo.hintco.HintcoPackage;
import ua.ansymo.hintco.InputPortInstance;
import ua.ansymo.hintco.OutputPortDeclaration;
import ua.ansymo.hintco.OutputPortInstance;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Output Port Instance</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link ua.ansymo.hintco.impl.OutputPortInstanceImpl#getValueTo <em>Value To</em>}</li>
 *   <li>{@link ua.ansymo.hintco.impl.OutputPortInstanceImpl#getDeclaration <em>Declaration</em>}</li>
 * </ul>
 *
 * @generated
 */
public class OutputPortInstanceImpl extends PortInstanceImpl implements OutputPortInstance {
	/**
	 * The cached value of the '{@link #getValueTo() <em>Value To</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getValueTo()
	 * @generated
	 * @ordered
	 */
	protected EList<InputPortInstance> valueTo;

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

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<InputPortInstance> getValueTo() {
		if (valueTo == null) {
			valueTo = new EObjectWithInverseResolvingEList<InputPortInstance>(InputPortInstance.class, this, HintcoPackage.OUTPUT_PORT_INSTANCE__VALUE_TO, HintcoPackage.INPUT_PORT_INSTANCE__VALUE_FROM);
		}
		return valueTo;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public OutputPortDeclaration getDeclaration() {
		if (declaration != null && declaration.eIsProxy()) {
			InternalEObject oldDeclaration = (InternalEObject)declaration;
			declaration = (OutputPortDeclaration)eResolveProxy(oldDeclaration);
			if (declaration != oldDeclaration) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, HintcoPackage.OUTPUT_PORT_INSTANCE__DECLARATION, oldDeclaration, declaration));
			}
		}
		return declaration;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public OutputPortDeclaration basicGetDeclaration() {
		return declaration;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDeclaration(OutputPortDeclaration newDeclaration) {
		OutputPortDeclaration oldDeclaration = declaration;
		declaration = newDeclaration;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, HintcoPackage.OUTPUT_PORT_INSTANCE__DECLARATION, oldDeclaration, declaration));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case HintcoPackage.OUTPUT_PORT_INSTANCE__VALUE_TO:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getValueTo()).basicAdd(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.OUTPUT_PORT_INSTANCE__VALUE_TO:
				return ((InternalEList<?>)getValueTo()).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 HintcoPackage.OUTPUT_PORT_INSTANCE__VALUE_TO:
				return getValueTo();
			case HintcoPackage.OUTPUT_PORT_INSTANCE__DECLARATION:
				if (resolve) return getDeclaration();
				return basicGetDeclaration();
		}
		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 HintcoPackage.OUTPUT_PORT_INSTANCE__VALUE_TO:
				getValueTo().clear();
				getValueTo().addAll((Collection<? extends InputPortInstance>)newValue);
				return;
			case HintcoPackage.OUTPUT_PORT_INSTANCE__DECLARATION:
				setDeclaration((OutputPortDeclaration)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case HintcoPackage.OUTPUT_PORT_INSTANCE__VALUE_TO:
				getValueTo().clear();
				return;
			case HintcoPackage.OUTPUT_PORT_INSTANCE__DECLARATION:
				setDeclaration((OutputPortDeclaration)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case HintcoPackage.OUTPUT_PORT_INSTANCE__VALUE_TO:
				return valueTo != null && !valueTo.isEmpty();
			case HintcoPackage.OUTPUT_PORT_INSTANCE__DECLARATION:
				return declaration != null;
		}
		return super.eIsSet(featureID);
	}

} //OutputPortInstanceImpl
