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

import java.lang.reflect.InvocationTargetException;

import java.util.Collection;

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

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

/**
 * <!-- 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#getInternalValueFrom <em>Internal Value From</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 #getInternalValueFrom() <em>Internal Value From</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getInternalValueFrom()
	 * @generated
	 * @ordered
	 */
	protected EList<InputPortInstance> internalValueFrom;

	/**
	 * <!-- 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 EList<InputPortInstance> getInternalValueFrom() {
		if (internalValueFrom == null) {
			internalValueFrom = new EObjectWithInverseResolvingEList.ManyInverse<InputPortInstance>(InputPortInstance.class, this, HintcoPackage.OUTPUT_PORT_INSTANCE__INTERNAL_VALUE_FROM, HintcoPackage.INPUT_PORT_INSTANCE__INTERNAL_VALUE_TO);
		}
		return internalValueFrom;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isInput() {
		return false;
	}

	/**
	 * <!-- 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);
			case HintcoPackage.OUTPUT_PORT_INSTANCE__INTERNAL_VALUE_FROM:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getInternalValueFrom()).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);
			case HintcoPackage.OUTPUT_PORT_INSTANCE__INTERNAL_VALUE_FROM:
				return ((InternalEList<?>)getInternalValueFrom()).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__INTERNAL_VALUE_FROM:
				return getInternalValueFrom();
		}
		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__INTERNAL_VALUE_FROM:
				getInternalValueFrom().clear();
				getInternalValueFrom().addAll((Collection<? extends InputPortInstance>)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__INTERNAL_VALUE_FROM:
				getInternalValueFrom().clear();
				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__INTERNAL_VALUE_FROM:
				return internalValueFrom != null && !internalValueFrom.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public int eDerivedOperationID(int baseOperationID, Class<?> baseClass) {
		if (baseClass == PortInstance.class) {
			switch (baseOperationID) {
				case HintcoPackage.PORT_INSTANCE___IS_INPUT: return HintcoPackage.OUTPUT_PORT_INSTANCE___IS_INPUT;
				default: return super.eDerivedOperationID(baseOperationID, baseClass);
			}
		}
		return super.eDerivedOperationID(baseOperationID, baseClass);
	}

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

} //OutputPortInstanceImpl
