/**
 */
package org.etsi.mts.tdl.structuredobjectives.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.etsi.mts.tdl.structuredobjectives.EntityReference;
import org.etsi.mts.tdl.structuredobjectives.EventOccurrenceSpecification;
import org.etsi.mts.tdl.structuredobjectives.EventReference;
import org.etsi.mts.tdl.structuredobjectives.StructuredObjectivesPackage;
import org.etsi.mts.tdl.structuredobjectives.Value;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Event Occurrence Specification</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link org.etsi.mts.tdl.structuredobjectives.impl.EventOccurrenceSpecificationImpl#getEntityReference <em>Entity Reference</em>}</li>
 *   <li>{@link org.etsi.mts.tdl.structuredobjectives.impl.EventOccurrenceSpecificationImpl#getEventReference <em>Event Reference</em>}</li>
 *   <li>{@link org.etsi.mts.tdl.structuredobjectives.impl.EventOccurrenceSpecificationImpl#getOppositeEntityReference <em>Opposite Entity Reference</em>}</li>
 *   <li>{@link org.etsi.mts.tdl.structuredobjectives.impl.EventOccurrenceSpecificationImpl#getEventArgument <em>Event Argument</em>}</li>
 * </ul>
 *
 * @generated
 */
public class EventOccurrenceSpecificationImpl extends EventOccurrenceImpl implements EventOccurrenceSpecification
{
	/**
	 * The cached value of the '{@link #getEntityReference() <em>Entity Reference</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEntityReference()
	 * @generated
	 * @ordered
	 */
	protected EntityReference entityReference;

	/**
	 * The cached value of the '{@link #getEventReference() <em>Event Reference</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEventReference()
	 * @generated
	 * @ordered
	 */
	protected EventReference eventReference;

	/**
	 * The cached value of the '{@link #getOppositeEntityReference() <em>Opposite Entity Reference</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getOppositeEntityReference()
	 * @generated
	 * @ordered
	 */
	protected EList<EntityReference> oppositeEntityReference;

	/**
	 * The cached value of the '{@link #getEventArgument() <em>Event Argument</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEventArgument()
	 * @generated
	 * @ordered
	 */
	protected Value eventArgument;

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public EntityReference getEntityReference()
	{
		return entityReference;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetEntityReference(EntityReference newEntityReference, NotificationChain msgs)
	{
		EntityReference oldEntityReference = entityReference;
		entityReference = newEntityReference;
		if (eNotificationRequired())
		{
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__ENTITY_REFERENCE, oldEntityReference, newEntityReference);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void setEntityReference(EntityReference newEntityReference)
	{
		if (newEntityReference != entityReference)
		{
			NotificationChain msgs = null;
			if (entityReference != null)
				msgs = ((InternalEObject)entityReference).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__ENTITY_REFERENCE, null, msgs);
			if (newEntityReference != null)
				msgs = ((InternalEObject)newEntityReference).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__ENTITY_REFERENCE, null, msgs);
			msgs = basicSetEntityReference(newEntityReference, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__ENTITY_REFERENCE, newEntityReference, newEntityReference));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public EventReference getEventReference()
	{
		return eventReference;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetEventReference(EventReference newEventReference, NotificationChain msgs)
	{
		EventReference oldEventReference = eventReference;
		eventReference = newEventReference;
		if (eNotificationRequired())
		{
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__EVENT_REFERENCE, oldEventReference, newEventReference);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void setEventReference(EventReference newEventReference)
	{
		if (newEventReference != eventReference)
		{
			NotificationChain msgs = null;
			if (eventReference != null)
				msgs = ((InternalEObject)eventReference).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__EVENT_REFERENCE, null, msgs);
			if (newEventReference != null)
				msgs = ((InternalEObject)newEventReference).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__EVENT_REFERENCE, null, msgs);
			msgs = basicSetEventReference(newEventReference, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__EVENT_REFERENCE, newEventReference, newEventReference));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public EList<EntityReference> getOppositeEntityReference()
	{
		if (oppositeEntityReference == null)
		{
			oppositeEntityReference = new EObjectContainmentEList<EntityReference>(EntityReference.class, this, StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__OPPOSITE_ENTITY_REFERENCE);
		}
		return oppositeEntityReference;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Value getEventArgument()
	{
		return eventArgument;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetEventArgument(Value newEventArgument, NotificationChain msgs)
	{
		Value oldEventArgument = eventArgument;
		eventArgument = newEventArgument;
		if (eNotificationRequired())
		{
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__EVENT_ARGUMENT, oldEventArgument, newEventArgument);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void setEventArgument(Value newEventArgument)
	{
		if (newEventArgument != eventArgument)
		{
			NotificationChain msgs = null;
			if (eventArgument != null)
				msgs = ((InternalEObject)eventArgument).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__EVENT_ARGUMENT, null, msgs);
			if (newEventArgument != null)
				msgs = ((InternalEObject)newEventArgument).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__EVENT_ARGUMENT, null, msgs);
			msgs = basicSetEventArgument(newEventArgument, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__EVENT_ARGUMENT, newEventArgument, newEventArgument));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
	{
		switch (featureID)
		{
			case StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__ENTITY_REFERENCE:
				return basicSetEntityReference(null, msgs);
			case StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__EVENT_REFERENCE:
				return basicSetEventReference(null, msgs);
			case StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__OPPOSITE_ENTITY_REFERENCE:
				return ((InternalEList<?>)getOppositeEntityReference()).basicRemove(otherEnd, msgs);
			case StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__EVENT_ARGUMENT:
				return basicSetEventArgument(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 StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__ENTITY_REFERENCE:
				return getEntityReference();
			case StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__EVENT_REFERENCE:
				return getEventReference();
			case StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__OPPOSITE_ENTITY_REFERENCE:
				return getOppositeEntityReference();
			case StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__EVENT_ARGUMENT:
				return getEventArgument();
		}
		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 StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__ENTITY_REFERENCE:
				setEntityReference((EntityReference)newValue);
				return;
			case StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__EVENT_REFERENCE:
				setEventReference((EventReference)newValue);
				return;
			case StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__OPPOSITE_ENTITY_REFERENCE:
				getOppositeEntityReference().clear();
				getOppositeEntityReference().addAll((Collection<? extends EntityReference>)newValue);
				return;
			case StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__EVENT_ARGUMENT:
				setEventArgument((Value)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID)
	{
		switch (featureID)
		{
			case StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__ENTITY_REFERENCE:
				setEntityReference((EntityReference)null);
				return;
			case StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__EVENT_REFERENCE:
				setEventReference((EventReference)null);
				return;
			case StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__OPPOSITE_ENTITY_REFERENCE:
				getOppositeEntityReference().clear();
				return;
			case StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__EVENT_ARGUMENT:
				setEventArgument((Value)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID)
	{
		switch (featureID)
		{
			case StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__ENTITY_REFERENCE:
				return entityReference != null;
			case StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__EVENT_REFERENCE:
				return eventReference != null;
			case StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__OPPOSITE_ENTITY_REFERENCE:
				return oppositeEntityReference != null && !oppositeEntityReference.isEmpty();
			case StructuredObjectivesPackage.EVENT_OCCURRENCE_SPECIFICATION__EVENT_ARGUMENT:
				return eventArgument != null;
		}
		return super.eIsSet(featureID);
	}

} //EventOccurrenceSpecificationImpl
