/**
 * generated by Xtext 2.9.0
 */
package org.xtext.datavault.datavaultDsl.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.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import org.xtext.datavault.datavaultDsl.DatavaultDslPackage;
import org.xtext.datavault.datavaultDsl.Link;
import org.xtext.datavault.datavaultDsl.NodeReference;
import org.xtext.datavault.datavaultDsl.SatelliteReference;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Link</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link org.xtext.datavault.datavaultDsl.impl.LinkImpl#getName <em>Name</em>}</li>
 *   <li>{@link org.xtext.datavault.datavaultDsl.impl.LinkImpl#getNodeReferenceA <em>Node Reference A</em>}</li>
 *   <li>{@link org.xtext.datavault.datavaultDsl.impl.LinkImpl#getNodeReferenceB <em>Node Reference B</em>}</li>
 *   <li>{@link org.xtext.datavault.datavaultDsl.impl.LinkImpl#getSatelliteReferences <em>Satellite References</em>}</li>
 * </ul>
 *
 * @generated
 */
public class LinkImpl extends EntityImpl implements Link {
	/**
	 * 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;

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

	/**
	 * The cached value of the '{@link #getNodeReferenceA() <em>Node Reference A</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getNodeReferenceA()
	 * @generated
	 * @ordered
	 */
	protected NodeReference nodeReferenceA;

	/**
	 * The cached value of the '{@link #getNodeReferenceB() <em>Node Reference B</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getNodeReferenceB()
	 * @generated
	 * @ordered
	 */
	protected NodeReference nodeReferenceB;

	/**
	 * The cached value of the '{@link #getSatelliteReferences() <em>Satellite References</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSatelliteReferences()
	 * @generated
	 * @ordered
	 */
	protected EList<SatelliteReference> satelliteReferences;

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, DatavaultDslPackage.LINK__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NodeReference getNodeReferenceA() {
		return nodeReferenceA;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetNodeReferenceA(NodeReference newNodeReferenceA, NotificationChain msgs) {
		NodeReference oldNodeReferenceA = nodeReferenceA;
		nodeReferenceA = newNodeReferenceA;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, DatavaultDslPackage.LINK__NODE_REFERENCE_A, oldNodeReferenceA, newNodeReferenceA);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setNodeReferenceA(NodeReference newNodeReferenceA) {
		if (newNodeReferenceA != nodeReferenceA) {
			NotificationChain msgs = null;
			if (nodeReferenceA != null)
				msgs = ((InternalEObject)nodeReferenceA).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - DatavaultDslPackage.LINK__NODE_REFERENCE_A, null, msgs);
			if (newNodeReferenceA != null)
				msgs = ((InternalEObject)newNodeReferenceA).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - DatavaultDslPackage.LINK__NODE_REFERENCE_A, null, msgs);
			msgs = basicSetNodeReferenceA(newNodeReferenceA, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, DatavaultDslPackage.LINK__NODE_REFERENCE_A, newNodeReferenceA, newNodeReferenceA));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NodeReference getNodeReferenceB() {
		return nodeReferenceB;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetNodeReferenceB(NodeReference newNodeReferenceB, NotificationChain msgs) {
		NodeReference oldNodeReferenceB = nodeReferenceB;
		nodeReferenceB = newNodeReferenceB;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, DatavaultDslPackage.LINK__NODE_REFERENCE_B, oldNodeReferenceB, newNodeReferenceB);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setNodeReferenceB(NodeReference newNodeReferenceB) {
		if (newNodeReferenceB != nodeReferenceB) {
			NotificationChain msgs = null;
			if (nodeReferenceB != null)
				msgs = ((InternalEObject)nodeReferenceB).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - DatavaultDslPackage.LINK__NODE_REFERENCE_B, null, msgs);
			if (newNodeReferenceB != null)
				msgs = ((InternalEObject)newNodeReferenceB).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - DatavaultDslPackage.LINK__NODE_REFERENCE_B, null, msgs);
			msgs = basicSetNodeReferenceB(newNodeReferenceB, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, DatavaultDslPackage.LINK__NODE_REFERENCE_B, newNodeReferenceB, newNodeReferenceB));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<SatelliteReference> getSatelliteReferences() {
		if (satelliteReferences == null) {
			satelliteReferences = new EObjectContainmentEList<SatelliteReference>(SatelliteReference.class, this, DatavaultDslPackage.LINK__SATELLITE_REFERENCES);
		}
		return satelliteReferences;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case DatavaultDslPackage.LINK__NODE_REFERENCE_A:
				return basicSetNodeReferenceA(null, msgs);
			case DatavaultDslPackage.LINK__NODE_REFERENCE_B:
				return basicSetNodeReferenceB(null, msgs);
			case DatavaultDslPackage.LINK__SATELLITE_REFERENCES:
				return ((InternalEList<?>)getSatelliteReferences()).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 DatavaultDslPackage.LINK__NAME:
				return getName();
			case DatavaultDslPackage.LINK__NODE_REFERENCE_A:
				return getNodeReferenceA();
			case DatavaultDslPackage.LINK__NODE_REFERENCE_B:
				return getNodeReferenceB();
			case DatavaultDslPackage.LINK__SATELLITE_REFERENCES:
				return getSatelliteReferences();
		}
		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 DatavaultDslPackage.LINK__NAME:
				setName((String)newValue);
				return;
			case DatavaultDslPackage.LINK__NODE_REFERENCE_A:
				setNodeReferenceA((NodeReference)newValue);
				return;
			case DatavaultDslPackage.LINK__NODE_REFERENCE_B:
				setNodeReferenceB((NodeReference)newValue);
				return;
			case DatavaultDslPackage.LINK__SATELLITE_REFERENCES:
				getSatelliteReferences().clear();
				getSatelliteReferences().addAll((Collection<? extends SatelliteReference>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case DatavaultDslPackage.LINK__NAME:
				setName(NAME_EDEFAULT);
				return;
			case DatavaultDslPackage.LINK__NODE_REFERENCE_A:
				setNodeReferenceA((NodeReference)null);
				return;
			case DatavaultDslPackage.LINK__NODE_REFERENCE_B:
				setNodeReferenceB((NodeReference)null);
				return;
			case DatavaultDslPackage.LINK__SATELLITE_REFERENCES:
				getSatelliteReferences().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case DatavaultDslPackage.LINK__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case DatavaultDslPackage.LINK__NODE_REFERENCE_A:
				return nodeReferenceA != null;
			case DatavaultDslPackage.LINK__NODE_REFERENCE_B:
				return nodeReferenceB != null;
			case DatavaultDslPackage.LINK__SATELLITE_REFERENCES:
				return satelliteReferences != null && !satelliteReferences.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(')');
		return result.toString();
	}

} //LinkImpl
