/**
 */
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.HierarchicalCosimUnit;
import ua.ansymo.hintco.HierarchicalUnitPort;
import ua.ansymo.hintco.HintcoPackage;
import ua.ansymo.hintco.InputPortInstance;
import ua.ansymo.hintco.OutputPortInstance;
import ua.ansymo.hintco.PortInstance;
import ua.ansymo.hintco.PrecendenceNode;
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>Hierarchical Cosim Unit</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link ua.ansymo.hintco.impl.HierarchicalCosimUnitImpl#getPrecedes <em>Precedes</em>}</li>
 *   <li>{@link ua.ansymo.hintco.impl.HierarchicalCosimUnitImpl#getSucceeds <em>Succeeds</em>}</li>
 *   <li>{@link ua.ansymo.hintco.impl.HierarchicalCosimUnitImpl#getBefore <em>Before</em>}</li>
 *   <li>{@link ua.ansymo.hintco.impl.HierarchicalCosimUnitImpl#getAfter <em>After</em>}</li>
 *   <li>{@link ua.ansymo.hintco.impl.HierarchicalCosimUnitImpl#getScenario <em>Scenario</em>}</li>
 *   <li>{@link ua.ansymo.hintco.impl.HierarchicalCosimUnitImpl#getAdaptation <em>Adaptation</em>}</li>
 *   <li>{@link ua.ansymo.hintco.impl.HierarchicalCosimUnitImpl#getPorts <em>Ports</em>}</li>
 * </ul>
 *
 * @generated
 */
public class HierarchicalCosimUnitImpl extends ScenarioImpl implements HierarchicalCosimUnit {
	/**
	 * The cached value of the '{@link #getPrecedes() <em>Precedes</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPrecedes()
	 * @generated
	 * @ordered
	 */
	protected EList<PrecendenceNode> 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<PrecendenceNode> succeeds;

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

	/**
	 * The cached value of the '{@link #getAfter() <em>After</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAfter()
	 * @generated
	 * @ordered
	 */
	protected PrecendenceNode 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 HierarchicalCosimUnitImpl() {
		super();
	}

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

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

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

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

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

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

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

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

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

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

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Scenario basicGetScenario() {
		if (eContainerFeatureID() != HintcoPackage.HIERARCHICAL_COSIM_UNIT__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.HIERARCHICAL_COSIM_UNIT__SCENARIO, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setScenario(Scenario newScenario) {
		if (newScenario != eInternalContainer() || (eContainerFeatureID() != HintcoPackage.HIERARCHICAL_COSIM_UNIT__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.HIERARCHICAL_COSIM_UNIT__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.HIERARCHICAL_COSIM_UNIT__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.HIERARCHICAL_COSIM_UNIT__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.HIERARCHICAL_COSIM_UNIT__PORTS, HintcoPackage.PORT_INSTANCE__UNIT);
		}
		return ports;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean valid() {
		final Function1<PortInstance, Boolean> _function = new Function1<PortInstance, Boolean>() {
			public Boolean apply(final PortInstance p) {
				return Boolean.valueOf((p instanceof HierarchicalUnitPort));
			}
		};
		return IterableExtensions.<PortInstance>forall(this.getPorts(), _function);
	}

	/**
	 * <!-- 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.HIERARCHICAL_COSIM_UNIT__PRECEDES:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getPrecedes()).basicAdd(otherEnd, msgs);
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__SUCCEEDS:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getSucceeds()).basicAdd(otherEnd, msgs);
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__BEFORE:
				if (before != null)
					msgs = ((InternalEObject)before).eInverseRemove(this, HintcoPackage.PRECENDENCE_NODE__AFTER, PrecendenceNode.class, msgs);
				return basicSetBefore((PrecendenceNode)otherEnd, msgs);
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__AFTER:
				if (after != null)
					msgs = ((InternalEObject)after).eInverseRemove(this, HintcoPackage.PRECENDENCE_NODE__BEFORE, PrecendenceNode.class, msgs);
				return basicSetAfter((PrecendenceNode)otherEnd, msgs);
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__SCENARIO:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetScenario((Scenario)otherEnd, msgs);
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__ADAPTATION:
				if (adaptation != null)
					msgs = ((InternalEObject)adaptation).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - HintcoPackage.HIERARCHICAL_COSIM_UNIT__ADAPTATION, null, msgs);
				return basicSetAdaptation((UnitAdaptation)otherEnd, msgs);
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__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.HIERARCHICAL_COSIM_UNIT__PRECEDES:
				return ((InternalEList<?>)getPrecedes()).basicRemove(otherEnd, msgs);
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__SUCCEEDS:
				return ((InternalEList<?>)getSucceeds()).basicRemove(otherEnd, msgs);
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__BEFORE:
				return basicSetBefore(null, msgs);
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__AFTER:
				return basicSetAfter(null, msgs);
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__SCENARIO:
				return basicSetScenario(null, msgs);
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__ADAPTATION:
				return basicSetAdaptation(null, msgs);
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__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.HIERARCHICAL_COSIM_UNIT__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.HIERARCHICAL_COSIM_UNIT__PRECEDES:
				return getPrecedes();
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__SUCCEEDS:
				return getSucceeds();
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__BEFORE:
				if (resolve) return getBefore();
				return basicGetBefore();
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__AFTER:
				if (resolve) return getAfter();
				return basicGetAfter();
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__SCENARIO:
				if (resolve) return getScenario();
				return basicGetScenario();
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__ADAPTATION:
				return getAdaptation();
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__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.HIERARCHICAL_COSIM_UNIT__PRECEDES:
				getPrecedes().clear();
				getPrecedes().addAll((Collection<? extends PrecendenceNode>)newValue);
				return;
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__SUCCEEDS:
				getSucceeds().clear();
				getSucceeds().addAll((Collection<? extends PrecendenceNode>)newValue);
				return;
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__BEFORE:
				setBefore((PrecendenceNode)newValue);
				return;
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__AFTER:
				setAfter((PrecendenceNode)newValue);
				return;
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__SCENARIO:
				setScenario((Scenario)newValue);
				return;
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__ADAPTATION:
				setAdaptation((UnitAdaptation)newValue);
				return;
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__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.HIERARCHICAL_COSIM_UNIT__PRECEDES:
				getPrecedes().clear();
				return;
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__SUCCEEDS:
				getSucceeds().clear();
				return;
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__BEFORE:
				setBefore((PrecendenceNode)null);
				return;
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__AFTER:
				setAfter((PrecendenceNode)null);
				return;
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__SCENARIO:
				setScenario((Scenario)null);
				return;
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__ADAPTATION:
				setAdaptation((UnitAdaptation)null);
				return;
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__PORTS:
				getPorts().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__PRECEDES:
				return precedes != null && !precedes.isEmpty();
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__SUCCEEDS:
				return succeeds != null && !succeeds.isEmpty();
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__BEFORE:
				return before != null;
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__AFTER:
				return after != null;
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__SCENARIO:
				return basicGetScenario() != null;
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__ADAPTATION:
				return adaptation != null;
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT__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 == PrecendenceNode.class) {
			switch (derivedFeatureID) {
				case HintcoPackage.HIERARCHICAL_COSIM_UNIT__PRECEDES: return HintcoPackage.PRECENDENCE_NODE__PRECEDES;
				case HintcoPackage.HIERARCHICAL_COSIM_UNIT__SUCCEEDS: return HintcoPackage.PRECENDENCE_NODE__SUCCEEDS;
				case HintcoPackage.HIERARCHICAL_COSIM_UNIT__BEFORE: return HintcoPackage.PRECENDENCE_NODE__BEFORE;
				case HintcoPackage.HIERARCHICAL_COSIM_UNIT__AFTER: return HintcoPackage.PRECENDENCE_NODE__AFTER;
				default: return -1;
			}
		}
		if (baseClass == UnitInstance.class) {
			switch (derivedFeatureID) {
				case HintcoPackage.HIERARCHICAL_COSIM_UNIT__SCENARIO: return HintcoPackage.UNIT_INSTANCE__SCENARIO;
				case HintcoPackage.HIERARCHICAL_COSIM_UNIT__ADAPTATION: return HintcoPackage.UNIT_INSTANCE__ADAPTATION;
				case HintcoPackage.HIERARCHICAL_COSIM_UNIT__PORTS: return HintcoPackage.UNIT_INSTANCE__PORTS;
				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 == PrecendenceNode.class) {
			switch (baseFeatureID) {
				case HintcoPackage.PRECENDENCE_NODE__PRECEDES: return HintcoPackage.HIERARCHICAL_COSIM_UNIT__PRECEDES;
				case HintcoPackage.PRECENDENCE_NODE__SUCCEEDS: return HintcoPackage.HIERARCHICAL_COSIM_UNIT__SUCCEEDS;
				case HintcoPackage.PRECENDENCE_NODE__BEFORE: return HintcoPackage.HIERARCHICAL_COSIM_UNIT__BEFORE;
				case HintcoPackage.PRECENDENCE_NODE__AFTER: return HintcoPackage.HIERARCHICAL_COSIM_UNIT__AFTER;
				default: return -1;
			}
		}
		if (baseClass == UnitInstance.class) {
			switch (baseFeatureID) {
				case HintcoPackage.UNIT_INSTANCE__SCENARIO: return HintcoPackage.HIERARCHICAL_COSIM_UNIT__SCENARIO;
				case HintcoPackage.UNIT_INSTANCE__ADAPTATION: return HintcoPackage.HIERARCHICAL_COSIM_UNIT__ADAPTATION;
				case HintcoPackage.UNIT_INSTANCE__PORTS: return HintcoPackage.HIERARCHICAL_COSIM_UNIT__PORTS;
				default: return -1;
			}
		}
		return super.eDerivedStructuralFeatureID(baseFeatureID, baseClass);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public int eDerivedOperationID(int baseOperationID, Class<?> baseClass) {
		if (baseClass == PrecendenceNode.class) {
			switch (baseOperationID) {
				default: return -1;
			}
		}
		if (baseClass == UnitInstance.class) {
			switch (baseOperationID) {
				case HintcoPackage.UNIT_INSTANCE___SELECTED_ADAPTATIONS: return HintcoPackage.HIERARCHICAL_COSIM_UNIT___SELECTED_ADAPTATIONS;
				case HintcoPackage.UNIT_INSTANCE___GET_OUTPUT_PORTS: return HintcoPackage.HIERARCHICAL_COSIM_UNIT___GET_OUTPUT_PORTS;
				case HintcoPackage.UNIT_INSTANCE___GET_INPUT_PORTS: return HintcoPackage.HIERARCHICAL_COSIM_UNIT___GET_INPUT_PORTS;
				case HintcoPackage.UNIT_INSTANCE___TO_STRING: return HintcoPackage.HIERARCHICAL_COSIM_UNIT___TO_STRING;
				default: return -1;
			}
		}
		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.HIERARCHICAL_COSIM_UNIT___VALID:
				return valid();
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT___SELECTED_ADAPTATIONS:
				return selectedAdaptations();
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT___GET_OUTPUT_PORTS:
				return getOutputPorts();
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT___GET_INPUT_PORTS:
				return getInputPorts();
			case HintcoPackage.HIERARCHICAL_COSIM_UNIT___TO_STRING:
				return toString();
		}
		return super.eInvoke(operationID, arguments);
	}

} //HierarchicalCosimUnitImpl
