/**
 */
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.TimeConstraint;
import org.etsi.mts.tdl.TimeLabel;

import org.etsi.mts.tdl.structuredobjectives.EventOccurrence;
import org.etsi.mts.tdl.structuredobjectives.StructuredObjectivesPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Event Occurrence</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link org.etsi.mts.tdl.structuredobjectives.impl.EventOccurrenceImpl#getTimeConstraint <em>Time Constraint</em>}</li>
 *   <li>{@link org.etsi.mts.tdl.structuredobjectives.impl.EventOccurrenceImpl#getTimeLabel <em>Time Label</em>}</li>
 * </ul>
 *
 * @generated
 */
public class EventOccurrenceImpl extends ElementImpl implements EventOccurrence
{
	/**
	 * The cached value of the '{@link #getTimeConstraint() <em>Time Constraint</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTimeConstraint()
	 * @generated
	 * @ordered
	 */
	protected EList<TimeConstraint> timeConstraint;

	/**
	 * The cached value of the '{@link #getTimeLabel() <em>Time Label</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTimeLabel()
	 * @generated
	 * @ordered
	 */
	protected TimeLabel timeLabel;

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public EList<TimeConstraint> getTimeConstraint()
	{
		if (timeConstraint == null)
		{
			timeConstraint = new EObjectContainmentEList<TimeConstraint>(TimeConstraint.class, this, StructuredObjectivesPackage.EVENT_OCCURRENCE__TIME_CONSTRAINT);
		}
		return timeConstraint;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public TimeLabel getTimeLabel()
	{
		return timeLabel;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetTimeLabel(TimeLabel newTimeLabel, NotificationChain msgs)
	{
		TimeLabel oldTimeLabel = timeLabel;
		timeLabel = newTimeLabel;
		if (eNotificationRequired())
		{
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, StructuredObjectivesPackage.EVENT_OCCURRENCE__TIME_LABEL, oldTimeLabel, newTimeLabel);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void setTimeLabel(TimeLabel newTimeLabel)
	{
		if (newTimeLabel != timeLabel)
		{
			NotificationChain msgs = null;
			if (timeLabel != null)
				msgs = ((InternalEObject)timeLabel).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - StructuredObjectivesPackage.EVENT_OCCURRENCE__TIME_LABEL, null, msgs);
			if (newTimeLabel != null)
				msgs = ((InternalEObject)newTimeLabel).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - StructuredObjectivesPackage.EVENT_OCCURRENCE__TIME_LABEL, null, msgs);
			msgs = basicSetTimeLabel(newTimeLabel, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, StructuredObjectivesPackage.EVENT_OCCURRENCE__TIME_LABEL, newTimeLabel, newTimeLabel));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
	{
		switch (featureID)
		{
			case StructuredObjectivesPackage.EVENT_OCCURRENCE__TIME_CONSTRAINT:
				return ((InternalEList<?>)getTimeConstraint()).basicRemove(otherEnd, msgs);
			case StructuredObjectivesPackage.EVENT_OCCURRENCE__TIME_LABEL:
				return basicSetTimeLabel(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__TIME_CONSTRAINT:
				return getTimeConstraint();
			case StructuredObjectivesPackage.EVENT_OCCURRENCE__TIME_LABEL:
				return getTimeLabel();
		}
		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__TIME_CONSTRAINT:
				getTimeConstraint().clear();
				getTimeConstraint().addAll((Collection<? extends TimeConstraint>)newValue);
				return;
			case StructuredObjectivesPackage.EVENT_OCCURRENCE__TIME_LABEL:
				setTimeLabel((TimeLabel)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__TIME_CONSTRAINT:
				getTimeConstraint().clear();
				return;
			case StructuredObjectivesPackage.EVENT_OCCURRENCE__TIME_LABEL:
				setTimeLabel((TimeLabel)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID)
	{
		switch (featureID)
		{
			case StructuredObjectivesPackage.EVENT_OCCURRENCE__TIME_CONSTRAINT:
				return timeConstraint != null && !timeConstraint.isEmpty();
			case StructuredObjectivesPackage.EVENT_OCCURRENCE__TIME_LABEL:
				return timeLabel != null;
		}
		return super.eIsSet(featureID);
	}

} //EventOccurrenceImpl
