/**
 */
package org.etsi.mts.tdl.impl;

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

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.etsi.mts.tdl.DataUse;
import org.etsi.mts.tdl.Member;
import org.etsi.mts.tdl.MemberReference;
import org.etsi.mts.tdl.tdlPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Member Reference</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link org.etsi.mts.tdl.impl.MemberReferenceImpl#getMember <em>Member</em>}</li>
 *   <li>{@link org.etsi.mts.tdl.impl.MemberReferenceImpl#getCollectionIndex <em>Collection Index</em>}</li>
 * </ul>
 *
 * @generated
 */
public class MemberReferenceImpl extends ElementImpl implements MemberReference
{
	/**
	 * The cached value of the '{@link #getMember() <em>Member</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMember()
	 * @generated
	 * @ordered
	 */
	protected Member member;

	/**
	 * The cached value of the '{@link #getCollectionIndex() <em>Collection Index</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCollectionIndex()
	 * @generated
	 * @ordered
	 */
	protected DataUse collectionIndex;

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Member getMember()
	{
		if (member != null && member.eIsProxy()) {
			InternalEObject oldMember = (InternalEObject)member;
			member = (Member)eResolveProxy(oldMember);
			if (member != oldMember) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, tdlPackage.MEMBER_REFERENCE__MEMBER, oldMember, member));
			}
		}
		return member;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Member basicGetMember()
	{
		return member;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void setMember(Member newMember)
	{
		Member oldMember = member;
		member = newMember;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, tdlPackage.MEMBER_REFERENCE__MEMBER, oldMember, member));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public DataUse getCollectionIndex()
	{
		return collectionIndex;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetCollectionIndex(DataUse newCollectionIndex, NotificationChain msgs)
	{
		DataUse oldCollectionIndex = collectionIndex;
		collectionIndex = newCollectionIndex;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, tdlPackage.MEMBER_REFERENCE__COLLECTION_INDEX, oldCollectionIndex, newCollectionIndex);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void setCollectionIndex(DataUse newCollectionIndex)
	{
		if (newCollectionIndex != collectionIndex) {
			NotificationChain msgs = null;
			if (collectionIndex != null)
				msgs = ((InternalEObject)collectionIndex).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - tdlPackage.MEMBER_REFERENCE__COLLECTION_INDEX, null, msgs);
			if (newCollectionIndex != null)
				msgs = ((InternalEObject)newCollectionIndex).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - tdlPackage.MEMBER_REFERENCE__COLLECTION_INDEX, null, msgs);
			msgs = basicSetCollectionIndex(newCollectionIndex, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, tdlPackage.MEMBER_REFERENCE__COLLECTION_INDEX, newCollectionIndex, newCollectionIndex));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
	{
		switch (featureID) {
			case tdlPackage.MEMBER_REFERENCE__COLLECTION_INDEX:
				return basicSetCollectionIndex(null, 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 tdlPackage.MEMBER_REFERENCE__MEMBER:
				if (resolve) return getMember();
				return basicGetMember();
			case tdlPackage.MEMBER_REFERENCE__COLLECTION_INDEX:
				return getCollectionIndex();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue)
	{
		switch (featureID) {
			case tdlPackage.MEMBER_REFERENCE__MEMBER:
				setMember((Member)newValue);
				return;
			case tdlPackage.MEMBER_REFERENCE__COLLECTION_INDEX:
				setCollectionIndex((DataUse)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID)
	{
		switch (featureID) {
			case tdlPackage.MEMBER_REFERENCE__MEMBER:
				setMember((Member)null);
				return;
			case tdlPackage.MEMBER_REFERENCE__COLLECTION_INDEX:
				setCollectionIndex((DataUse)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID)
	{
		switch (featureID) {
			case tdlPackage.MEMBER_REFERENCE__MEMBER:
				return member != null;
			case tdlPackage.MEMBER_REFERENCE__COLLECTION_INDEX:
				return collectionIndex != null;
		}
		return super.eIsSet(featureID);
	}

} //MemberReferenceImpl
