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

import java.util.Collection;

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

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.EObjectResolvingEList;

import ua.ansymo.hintco.Alternative;
import ua.ansymo.hintco.CandidateScenario;
import ua.ansymo.hintco.ExtrapolationAdaptation;
import ua.ansymo.hintco.HintcoPackage;
import ua.ansymo.hintco.InterpolationAdaptation;
import ua.ansymo.hintco.VariantDiagram;
import ua.ansymo.hintco.XorAdaptation;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Variant Diagram</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link ua.ansymo.hintco.impl.VariantDiagramImpl#getChildren <em>Children</em>}</li>
 *   <li>{@link ua.ansymo.hintco.impl.VariantDiagramImpl#getAlternative <em>Alternative</em>}</li>
 *   <li>{@link ua.ansymo.hintco.impl.VariantDiagramImpl#getName <em>Name</em>}</li>
 * </ul>
 *
 * @generated
 */
public class VariantDiagramImpl extends IDedImpl implements VariantDiagram {
	/**
	 * The cached value of the '{@link #getChildren() <em>Children</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getChildren()
	 * @generated
	 * @ordered
	 */
	protected EList<VariantDiagram> children;

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

	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<VariantDiagram> getChildren() {
		if (children == null) {
			children = new EObjectResolvingEList<VariantDiagram>(VariantDiagram.class, this, HintcoPackage.VARIANT_DIAGRAM__CHILDREN);
		}
		return children;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Alternative getAlternative() {
		if (alternative != null && alternative.eIsProxy()) {
			InternalEObject oldAlternative = (InternalEObject)alternative;
			alternative = (Alternative)eResolveProxy(oldAlternative);
			if (alternative != oldAlternative) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, HintcoPackage.VARIANT_DIAGRAM__ALTERNATIVE, oldAlternative, alternative));
			}
		}
		return alternative;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Alternative basicGetAlternative() {
		return alternative;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setAlternative(Alternative newAlternative) {
		Alternative oldAlternative = alternative;
		alternative = newAlternative;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, HintcoPackage.VARIANT_DIAGRAM__ALTERNATIVE, oldAlternative, alternative));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		String _xblockexpression = null;
		{
			String _identifier = this.getIdentifier();
			final String prefix = (_identifier + "_");
			String _xifexpression = null;
			Alternative _alternative = this.getAlternative();
			boolean _tripleNotEquals = (_alternative != null);
			if (_tripleNotEquals) {
				String _xifexpression_1 = null;
				Alternative _alternative_1 = this.getAlternative();
				if ((_alternative_1 instanceof CandidateScenario)) {
					Alternative _alternative_2 = this.getAlternative();
					String _name = ((CandidateScenario) _alternative_2).getName();
					_xifexpression_1 = ((prefix + "sce ") + _name);
				}
				else {
					String _xifexpression_2 = null;
					Alternative _alternative_3 = this.getAlternative();
					if ((_alternative_3 instanceof XorAdaptation)) {
						Alternative _alternative_4 = this.getAlternative();
						String _name_1 = ((XorAdaptation) _alternative_4).getName();
						_xifexpression_2 = ((prefix + "xor ") + _name_1);
					}
					else {
						String _xifexpression_3 = null;
						Alternative _alternative_5 = this.getAlternative();
						if ((_alternative_5 instanceof ExtrapolationAdaptation)) {
							Alternative _alternative_6 = this.getAlternative();
							String _name_2 = ((ExtrapolationAdaptation) _alternative_6).getName();
							_xifexpression_3 = ((prefix + "extra ") + _name_2);
						}
						else {
							String _xifexpression_4 = null;
							Alternative _alternative_7 = this.getAlternative();
							if ((_alternative_7 instanceof InterpolationAdaptation)) {
								Alternative _alternative_8 = this.getAlternative();
								String _name_3 = ((InterpolationAdaptation) _alternative_8).getName();
								_xifexpression_4 = ((prefix + "intra ") + _name_3);
							}
							else {
								_xifexpression_4 = (prefix + "implement");
							}
							_xifexpression_3 = _xifexpression_4;
						}
						_xifexpression_2 = _xifexpression_3;
					}
					_xifexpression_1 = _xifexpression_2;
				}
				_xifexpression = _xifexpression_1;
			}
			else {
				_xifexpression = (prefix + "root");
			}
			_xblockexpression = _xifexpression;
		}
		return _xblockexpression;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case HintcoPackage.VARIANT_DIAGRAM__CHILDREN:
				return getChildren();
			case HintcoPackage.VARIANT_DIAGRAM__ALTERNATIVE:
				if (resolve) return getAlternative();
				return basicGetAlternative();
			case HintcoPackage.VARIANT_DIAGRAM__NAME:
				return getName();
		}
		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.VARIANT_DIAGRAM__CHILDREN:
				getChildren().clear();
				getChildren().addAll((Collection<? extends VariantDiagram>)newValue);
				return;
			case HintcoPackage.VARIANT_DIAGRAM__ALTERNATIVE:
				setAlternative((Alternative)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case HintcoPackage.VARIANT_DIAGRAM__CHILDREN:
				getChildren().clear();
				return;
			case HintcoPackage.VARIANT_DIAGRAM__ALTERNATIVE:
				setAlternative((Alternative)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case HintcoPackage.VARIANT_DIAGRAM__CHILDREN:
				return children != null && !children.isEmpty();
			case HintcoPackage.VARIANT_DIAGRAM__ALTERNATIVE:
				return alternative != null;
			case HintcoPackage.VARIANT_DIAGRAM__NAME:
				return NAME_EDEFAULT == null ? getName() != null : !NAME_EDEFAULT.equals(getName());
		}
		return super.eIsSet(featureID);
	}

} //VariantDiagramImpl
