/**
 * generated by Xtext 2.16.0
 */
package be.uantwerpen.cosys.contractLang.impl;

import be.uantwerpen.cosys.contractLang.Constraint;
import be.uantwerpen.cosys.contractLang.ContractLangPackage;
import be.uantwerpen.cosys.contractLang.Interval;
import be.uantwerpen.cosys.contractLang.MetaStatement;
import be.uantwerpen.cosys.contractLang.PrecStatement;
import be.uantwerpen.cosys.contractLang.PrecedenceChain1NPattern;

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

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Precedence Chain1 NPattern</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link be.uantwerpen.cosys.contractLang.impl.PrecedenceChain1NPatternImpl#getSecond <em>Second</em>}</li>
 *   <li>{@link be.uantwerpen.cosys.contractLang.impl.PrecedenceChain1NPatternImpl#getStatements <em>Statements</em>}</li>
 *   <li>{@link be.uantwerpen.cosys.contractLang.impl.PrecedenceChain1NPatternImpl#getFirst <em>First</em>}</li>
 *   <li>{@link be.uantwerpen.cosys.contractLang.impl.PrecedenceChain1NPatternImpl#getInterval <em>Interval</em>}</li>
 *   <li>{@link be.uantwerpen.cosys.contractLang.impl.PrecedenceChain1NPatternImpl#getConstraint <em>Constraint</em>}</li>
 * </ul>
 *
 * @generated
 */
public class PrecedenceChain1NPatternImpl extends OrderImpl implements PrecedenceChain1NPattern
{
  /**
   * The cached value of the '{@link #getSecond() <em>Second</em>}' reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getSecond()
   * @generated
   * @ordered
   */
  protected MetaStatement second;

  /**
   * The cached value of the '{@link #getStatements() <em>Statements</em>}' reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getStatements()
   * @generated
   * @ordered
   */
  protected EList<PrecStatement> statements;

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

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

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

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

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

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public MetaStatement getSecond()
  {
    if (second != null && second.eIsProxy())
    {
      InternalEObject oldSecond = (InternalEObject)second;
      second = (MetaStatement)eResolveProxy(oldSecond);
      if (second != oldSecond)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__SECOND, oldSecond, second));
      }
    }
    return second;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public MetaStatement basicGetSecond()
  {
    return second;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void setSecond(MetaStatement newSecond)
  {
    MetaStatement oldSecond = second;
    second = newSecond;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__SECOND, oldSecond, second));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public EList<PrecStatement> getStatements()
  {
    if (statements == null)
    {
      statements = new EObjectResolvingEList<PrecStatement>(PrecStatement.class, this, ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__STATEMENTS);
    }
    return statements;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public MetaStatement getFirst()
  {
    if (first != null && first.eIsProxy())
    {
      InternalEObject oldFirst = (InternalEObject)first;
      first = (MetaStatement)eResolveProxy(oldFirst);
      if (first != oldFirst)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__FIRST, oldFirst, first));
      }
    }
    return first;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public MetaStatement basicGetFirst()
  {
    return first;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void setFirst(MetaStatement newFirst)
  {
    MetaStatement oldFirst = first;
    first = newFirst;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__FIRST, oldFirst, first));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Interval getInterval()
  {
    return interval;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetInterval(Interval newInterval, NotificationChain msgs)
  {
    Interval oldInterval = interval;
    interval = newInterval;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__INTERVAL, oldInterval, newInterval);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void setInterval(Interval newInterval)
  {
    if (newInterval != interval)
    {
      NotificationChain msgs = null;
      if (interval != null)
        msgs = ((InternalEObject)interval).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__INTERVAL, null, msgs);
      if (newInterval != null)
        msgs = ((InternalEObject)newInterval).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__INTERVAL, null, msgs);
      msgs = basicSetInterval(newInterval, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__INTERVAL, newInterval, newInterval));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Constraint getConstraint()
  {
    return constraint;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetConstraint(Constraint newConstraint, NotificationChain msgs)
  {
    Constraint oldConstraint = constraint;
    constraint = newConstraint;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__CONSTRAINT, oldConstraint, newConstraint);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void setConstraint(Constraint newConstraint)
  {
    if (newConstraint != constraint)
    {
      NotificationChain msgs = null;
      if (constraint != null)
        msgs = ((InternalEObject)constraint).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__CONSTRAINT, null, msgs);
      if (newConstraint != null)
        msgs = ((InternalEObject)newConstraint).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__CONSTRAINT, null, msgs);
      msgs = basicSetConstraint(newConstraint, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__CONSTRAINT, newConstraint, newConstraint));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__INTERVAL:
        return basicSetInterval(null, msgs);
      case ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__CONSTRAINT:
        return basicSetConstraint(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 ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__SECOND:
        if (resolve) return getSecond();
        return basicGetSecond();
      case ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__STATEMENTS:
        return getStatements();
      case ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__FIRST:
        if (resolve) return getFirst();
        return basicGetFirst();
      case ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__INTERVAL:
        return getInterval();
      case ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__CONSTRAINT:
        return getConstraint();
    }
    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 ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__SECOND:
        setSecond((MetaStatement)newValue);
        return;
      case ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__STATEMENTS:
        getStatements().clear();
        getStatements().addAll((Collection<? extends PrecStatement>)newValue);
        return;
      case ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__FIRST:
        setFirst((MetaStatement)newValue);
        return;
      case ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__INTERVAL:
        setInterval((Interval)newValue);
        return;
      case ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__CONSTRAINT:
        setConstraint((Constraint)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__SECOND:
        setSecond((MetaStatement)null);
        return;
      case ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__STATEMENTS:
        getStatements().clear();
        return;
      case ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__FIRST:
        setFirst((MetaStatement)null);
        return;
      case ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__INTERVAL:
        setInterval((Interval)null);
        return;
      case ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__CONSTRAINT:
        setConstraint((Constraint)null);
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__SECOND:
        return second != null;
      case ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__STATEMENTS:
        return statements != null && !statements.isEmpty();
      case ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__FIRST:
        return first != null;
      case ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__INTERVAL:
        return interval != null;
      case ContractLangPackage.PRECEDENCE_CHAIN1_NPATTERN__CONSTRAINT:
        return constraint != null;
    }
    return super.eIsSet(featureID);
  }

} //PrecedenceChain1NPatternImpl
