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

import com.google.common.collect.Iterables;

import java.lang.reflect.InvocationTargetException;

import java.util.Collection;

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

import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.ECollections;
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.EObjectContainmentWithInverseEList;
import org.eclipse.emf.ecore.util.EObjectWithInverseResolvingEList;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.InternalEList;

import org.eclipse.xtext.xbase.lib.Functions.Function1;

import org.eclipse.xtext.xbase.lib.IterableExtensions;

import ua.ansymo.hintco.DecompositionUnitAdaptation;
import ua.ansymo.hintco.HintcoPackage;
import ua.ansymo.hintco.InputPortInstance;
import ua.ansymo.hintco.OutputPortInstance;
import ua.ansymo.hintco.PortInstance;
import ua.ansymo.hintco.PrecedenceNode;
import ua.ansymo.hintco.Scenario;
import ua.ansymo.hintco.UnitAdaptation;
import ua.ansymo.hintco.UnitInstance;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Unit Instance</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link ua.ansymo.hintco.impl.UnitInstanceImpl#getPrecedes <em>Precedes</em>}</li>
 *   <li>{@link ua.ansymo.hintco.impl.UnitInstanceImpl#getSucceeds <em>Succeeds</em>}</li>
 *   <li>{@link ua.ansymo.hintco.impl.UnitInstanceImpl#getBefore <em>Before</em>}</li>
 *   <li>{@link ua.ansymo.hintco.impl.UnitInstanceImpl#getAfter <em>After</em>}</li>
 *   <li>{@link ua.ansymo.hintco.impl.UnitInstanceImpl#getScenario <em>Scenario</em>}</li>
 *   <li>{@link ua.ansymo.hintco.impl.UnitInstanceImpl#getAdaptation <em>Adaptation</em>}</li>
 *   <li>{@link ua.ansymo.hintco.impl.UnitInstanceImpl#getPorts <em>Ports</em>}</li>
 * </ul>
 *
 * @generated
 */
public abstract class UnitInstanceImpl extends IDedImpl implements UnitInstance {
	/**
	 * The cached value of the '{@link #getPrecedes() <em>Precedes</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPrecedes()
	 * @generated
	 * @ordered
	 */
	protected EList<PrecedenceNode> precedes;

	/**
	 * The cached value of the '{@link #getSucceeds() <em>Succeeds</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSucceeds()
	 * @generated
	 * @ordered
	 */
	protected EList<PrecedenceNode> succeeds;

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

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

	/**
	 * The cached value of the '{@link #getAdaptation() <em>Adaptation</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAdaptation()
	 * @generated
	 * @ordered
	 */
	protected UnitAdaptation adaptation;

	/**
	 * The cached value of the '{@link #getPorts() <em>Ports</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPorts()
	 * @generated
	 * @ordered
	 */
	protected EList<PortInstance> ports;

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<PrecedenceNode> getPrecedes() {
		if (precedes == null) {
			precedes = new EObjectWithInverseResolvingEList.ManyInverse<PrecedenceNode>(PrecedenceNode.class, this, HintcoPackage.UNIT_INSTANCE__PRECEDES, HintcoPackage.PRECEDENCE_NODE__SUCCEEDS);
		}
		return precedes;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<PrecedenceNode> getSucceeds() {
		if (succeeds == null) {
			succeeds = new EObjectWithInverseResolvingEList.ManyInverse<PrecedenceNode>(PrecedenceNode.class, this, HintcoPackage.UNIT_INSTANCE__SUCCEEDS, HintcoPackage.PRECEDENCE_NODE__PRECEDES);
		}
		return succeeds;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PrecedenceNode getBefore() {
		if (before != null && before.eIsProxy()) {
			InternalEObject oldBefore = (InternalEObject)before;
			before = (PrecedenceNode)eResolveProxy(oldBefore);
			if (before != oldBefore) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, HintcoPackage.UNIT_INSTANCE__BEFORE, oldBefore, before));
			}
		}
		return before;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PrecedenceNode basicGetBefore() {
		return before;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetBefore(PrecedenceNode newBefore, NotificationChain msgs) {
		PrecedenceNode oldBefore = before;
		before = newBefore;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, HintcoPackage.UNIT_INSTANCE__BEFORE, oldBefore, newBefore);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setBefore(PrecedenceNode newBefore) {
		if (newBefore != before) {
			NotificationChain msgs = null;
			if (before != null)
				msgs = ((InternalEObject)before).eInverseRemove(this, HintcoPackage.PRECEDENCE_NODE__AFTER, PrecedenceNode.class, msgs);
			if (newBefore != null)
				msgs = ((InternalEObject)newBefore).eInverseAdd(this, HintcoPackage.PRECEDENCE_NODE__AFTER, PrecedenceNode.class, msgs);
			msgs = basicSetBefore(newBefore, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, HintcoPackage.UNIT_INSTANCE__BEFORE, newBefore, newBefore));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PrecedenceNode getAfter() {
		if (after != null && after.eIsProxy()) {
			InternalEObject oldAfter = (InternalEObject)after;
			after = (PrecedenceNode)eResolveProxy(oldAfter);
			if (after != oldAfter) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, HintcoPackage.UNIT_INSTANCE__AFTER, oldAfter, after));
			}
		}
		return after;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PrecedenceNode basicGetAfter() {
		return after;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetAfter(PrecedenceNode newAfter, NotificationChain msgs) {
		PrecedenceNode oldAfter = after;
		after = newAfter;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, HintcoPackage.UNIT_INSTANCE__AFTER, oldAfter, newAfter);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setAfter(PrecedenceNode newAfter) {
		if (newAfter != after) {
			NotificationChain msgs = null;
			if (after != null)
				msgs = ((InternalEObject)after).eInverseRemove(this, HintcoPackage.PRECEDENCE_NODE__BEFORE, PrecedenceNode.class, msgs);
			if (newAfter != null)
				msgs = ((InternalEObject)newAfter).eInverseAdd(this, HintcoPackage.PRECEDENCE_NODE__BEFORE, PrecedenceNode.class, msgs);
			msgs = basicSetAfter(newAfter, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, HintcoPackage.UNIT_INSTANCE__AFTER, newAfter, newAfter));
	}

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetScenario(Scenario newScenario, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newScenario, HintcoPackage.UNIT_INSTANCE__SCENARIO, msgs);
		return msgs;
	}

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public UnitAdaptation getAdaptation() {
		return adaptation;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetAdaptation(UnitAdaptation newAdaptation, NotificationChain msgs) {
		UnitAdaptation oldAdaptation = adaptation;
		adaptation = newAdaptation;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, HintcoPackage.UNIT_INSTANCE__ADAPTATION, oldAdaptation, newAdaptation);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setAdaptation(UnitAdaptation newAdaptation) {
		if (newAdaptation != adaptation) {
			NotificationChain msgs = null;
			if (adaptation != null)
				msgs = ((InternalEObject)adaptation).eInverseRemove(this, HintcoPackage.UNIT_ADAPTATION__UNIT, UnitAdaptation.class, msgs);
			if (newAdaptation != null)
				msgs = ((InternalEObject)newAdaptation).eInverseAdd(this, HintcoPackage.UNIT_ADAPTATION__UNIT, UnitAdaptation.class, msgs);
			msgs = basicSetAdaptation(newAdaptation, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, HintcoPackage.UNIT_INSTANCE__ADAPTATION, newAdaptation, newAdaptation));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<PortInstance> getPorts() {
		if (ports == null) {
			ports = new EObjectContainmentWithInverseEList<PortInstance>(PortInstance.class, this, HintcoPackage.UNIT_INSTANCE__PORTS, HintcoPackage.PORT_INSTANCE__UNIT);
		}
		return ports;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<UnitAdaptation> selectedAdaptations() {
		UnitAdaptation _adaptation = this.getAdaptation();
		boolean _tripleEquals = (_adaptation == null);
		if (_tripleEquals) {
			return new BasicEList<UnitAdaptation>(java.util.Collections.<UnitAdaptation>unmodifiableList(org.eclipse.xtext.xbase.lib.CollectionLiterals.<UnitAdaptation>newArrayList()));
		}
		boolean _isSelected = this.getAdaptation().isSelected();
		if (_isSelected) {
			UnitAdaptation _adaptation_1 = this.getAdaptation();
			if ((_adaptation_1 instanceof DecompositionUnitAdaptation)) {
				UnitAdaptation _adaptation_2 = this.getAdaptation();
				return ((DecompositionUnitAdaptation) _adaptation_2).selectedAdaptations();
			}
			UnitAdaptation _adaptation_3 = this.getAdaptation();
			return new BasicEList<UnitAdaptation>(java.util.Collections.<UnitAdaptation>unmodifiableList(org.eclipse.xtext.xbase.lib.CollectionLiterals.<UnitAdaptation>newArrayList(_adaptation_3)));
		}
		return new BasicEList<UnitAdaptation>(java.util.Collections.<UnitAdaptation>unmodifiableList(org.eclipse.xtext.xbase.lib.CollectionLiterals.<UnitAdaptation>newArrayList()));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<OutputPortInstance> getOutputPorts() {
		final Function1<OutputPortInstance, Boolean> _function = new Function1<OutputPortInstance, Boolean>() {
			public Boolean apply(final OutputPortInstance it) {
				boolean _isInput = it.isInput();
				return Boolean.valueOf((!_isInput));
			}
		};
		return ECollections.<OutputPortInstance>toEList(IterableExtensions.<OutputPortInstance>filter(Iterables.<OutputPortInstance>filter(this.getPorts(), OutputPortInstance.class), _function));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<InputPortInstance> getInputPorts() {
		final Function1<InputPortInstance, Boolean> _function = new Function1<InputPortInstance, Boolean>() {
			public Boolean apply(final InputPortInstance it) {
				return Boolean.valueOf(it.isInput());
			}
		};
		return ECollections.<InputPortInstance>toEList(IterableExtensions.<InputPortInstance>filter(Iterables.<InputPortInstance>filter(this.getPorts(), InputPortInstance.class), _function));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String toString() {
		return this.getIdentifier();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case HintcoPackage.UNIT_INSTANCE__PRECEDES:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getPrecedes()).basicAdd(otherEnd, msgs);
			case HintcoPackage.UNIT_INSTANCE__SUCCEEDS:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getSucceeds()).basicAdd(otherEnd, msgs);
			case HintcoPackage.UNIT_INSTANCE__BEFORE:
				if (before != null)
					msgs = ((InternalEObject)before).eInverseRemove(this, HintcoPackage.PRECEDENCE_NODE__AFTER, PrecedenceNode.class, msgs);
				return basicSetBefore((PrecedenceNode)otherEnd, msgs);
			case HintcoPackage.UNIT_INSTANCE__AFTER:
				if (after != null)
					msgs = ((InternalEObject)after).eInverseRemove(this, HintcoPackage.PRECEDENCE_NODE__BEFORE, PrecedenceNode.class, msgs);
				return basicSetAfter((PrecedenceNode)otherEnd, msgs);
			case HintcoPackage.UNIT_INSTANCE__SCENARIO:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetScenario((Scenario)otherEnd, msgs);
			case HintcoPackage.UNIT_INSTANCE__ADAPTATION:
				if (adaptation != null)
					msgs = ((InternalEObject)adaptation).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - HintcoPackage.UNIT_INSTANCE__ADAPTATION, null, msgs);
				return basicSetAdaptation((UnitAdaptation)otherEnd, msgs);
			case HintcoPackage.UNIT_INSTANCE__PORTS:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getPorts()).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.UNIT_INSTANCE__PRECEDES:
				return ((InternalEList<?>)getPrecedes()).basicRemove(otherEnd, msgs);
			case HintcoPackage.UNIT_INSTANCE__SUCCEEDS:
				return ((InternalEList<?>)getSucceeds()).basicRemove(otherEnd, msgs);
			case HintcoPackage.UNIT_INSTANCE__BEFORE:
				return basicSetBefore(null, msgs);
			case HintcoPackage.UNIT_INSTANCE__AFTER:
				return basicSetAfter(null, msgs);
			case HintcoPackage.UNIT_INSTANCE__SCENARIO:
				return basicSetScenario(null, msgs);
			case HintcoPackage.UNIT_INSTANCE__ADAPTATION:
				return basicSetAdaptation(null, msgs);
			case HintcoPackage.UNIT_INSTANCE__PORTS:
				return ((InternalEList<?>)getPorts()).basicRemove(otherEnd, 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_INSTANCE__SCENARIO:
				return eInternalContainer().eInverseRemove(this, HintcoPackage.SCENARIO__COSIMUNITS, Scenario.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_INSTANCE__PRECEDES:
				return getPrecedes();
			case HintcoPackage.UNIT_INSTANCE__SUCCEEDS:
				return getSucceeds();
			case HintcoPackage.UNIT_INSTANCE__BEFORE:
				if (resolve) return getBefore();
				return basicGetBefore();
			case HintcoPackage.UNIT_INSTANCE__AFTER:
				if (resolve) return getAfter();
				return basicGetAfter();
			case HintcoPackage.UNIT_INSTANCE__SCENARIO:
				if (resolve) return getScenario();
				return basicGetScenario();
			case HintcoPackage.UNIT_INSTANCE__ADAPTATION:
				return getAdaptation();
			case HintcoPackage.UNIT_INSTANCE__PORTS:
				return getPorts();
		}
		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.UNIT_INSTANCE__PRECEDES:
				getPrecedes().clear();
				getPrecedes().addAll((Collection<? extends PrecedenceNode>)newValue);
				return;
			case HintcoPackage.UNIT_INSTANCE__SUCCEEDS:
				getSucceeds().clear();
				getSucceeds().addAll((Collection<? extends PrecedenceNode>)newValue);
				return;
			case HintcoPackage.UNIT_INSTANCE__BEFORE:
				setBefore((PrecedenceNode)newValue);
				return;
			case HintcoPackage.UNIT_INSTANCE__AFTER:
				setAfter((PrecedenceNode)newValue);
				return;
			case HintcoPackage.UNIT_INSTANCE__SCENARIO:
				setScenario((Scenario)newValue);
				return;
			case HintcoPackage.UNIT_INSTANCE__ADAPTATION:
				setAdaptation((UnitAdaptation)newValue);
				return;
			case HintcoPackage.UNIT_INSTANCE__PORTS:
				getPorts().clear();
				getPorts().addAll((Collection<? extends PortInstance>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case HintcoPackage.UNIT_INSTANCE__PRECEDES:
				getPrecedes().clear();
				return;
			case HintcoPackage.UNIT_INSTANCE__SUCCEEDS:
				getSucceeds().clear();
				return;
			case HintcoPackage.UNIT_INSTANCE__BEFORE:
				setBefore((PrecedenceNode)null);
				return;
			case HintcoPackage.UNIT_INSTANCE__AFTER:
				setAfter((PrecedenceNode)null);
				return;
			case HintcoPackage.UNIT_INSTANCE__SCENARIO:
				setScenario((Scenario)null);
				return;
			case HintcoPackage.UNIT_INSTANCE__ADAPTATION:
				setAdaptation((UnitAdaptation)null);
				return;
			case HintcoPackage.UNIT_INSTANCE__PORTS:
				getPorts().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case HintcoPackage.UNIT_INSTANCE__PRECEDES:
				return precedes != null && !precedes.isEmpty();
			case HintcoPackage.UNIT_INSTANCE__SUCCEEDS:
				return succeeds != null && !succeeds.isEmpty();
			case HintcoPackage.UNIT_INSTANCE__BEFORE:
				return before != null;
			case HintcoPackage.UNIT_INSTANCE__AFTER:
				return after != null;
			case HintcoPackage.UNIT_INSTANCE__SCENARIO:
				return basicGetScenario() != null;
			case HintcoPackage.UNIT_INSTANCE__ADAPTATION:
				return adaptation != null;
			case HintcoPackage.UNIT_INSTANCE__PORTS:
				return ports != null && !ports.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public int eBaseStructuralFeatureID(int derivedFeatureID, Class<?> baseClass) {
		if (baseClass == PrecedenceNode.class) {
			switch (derivedFeatureID) {
				case HintcoPackage.UNIT_INSTANCE__PRECEDES: return HintcoPackage.PRECEDENCE_NODE__PRECEDES;
				case HintcoPackage.UNIT_INSTANCE__SUCCEEDS: return HintcoPackage.PRECEDENCE_NODE__SUCCEEDS;
				case HintcoPackage.UNIT_INSTANCE__BEFORE: return HintcoPackage.PRECEDENCE_NODE__BEFORE;
				case HintcoPackage.UNIT_INSTANCE__AFTER: return HintcoPackage.PRECEDENCE_NODE__AFTER;
				default: return -1;
			}
		}
		return super.eBaseStructuralFeatureID(derivedFeatureID, baseClass);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public int eDerivedStructuralFeatureID(int baseFeatureID, Class<?> baseClass) {
		if (baseClass == PrecedenceNode.class) {
			switch (baseFeatureID) {
				case HintcoPackage.PRECEDENCE_NODE__PRECEDES: return HintcoPackage.UNIT_INSTANCE__PRECEDES;
				case HintcoPackage.PRECEDENCE_NODE__SUCCEEDS: return HintcoPackage.UNIT_INSTANCE__SUCCEEDS;
				case HintcoPackage.PRECEDENCE_NODE__BEFORE: return HintcoPackage.UNIT_INSTANCE__BEFORE;
				case HintcoPackage.PRECEDENCE_NODE__AFTER: return HintcoPackage.UNIT_INSTANCE__AFTER;
				default: return -1;
			}
		}
		return super.eDerivedStructuralFeatureID(baseFeatureID, baseClass);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eInvoke(int operationID, EList<?> arguments) throws InvocationTargetException {
		switch (operationID) {
			case HintcoPackage.UNIT_INSTANCE___SELECTED_ADAPTATIONS:
				return selectedAdaptations();
			case HintcoPackage.UNIT_INSTANCE___GET_OUTPUT_PORTS:
				return getOutputPorts();
			case HintcoPackage.UNIT_INSTANCE___GET_INPUT_PORTS:
				return getInputPorts();
			case HintcoPackage.UNIT_INSTANCE___TO_STRING:
				return toString();
		}
		return super.eInvoke(operationID, arguments);
	}

} //UnitInstanceImpl
