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

import be.uantwerpen.cosys.contractLang.Contract;
import be.uantwerpen.cosys.contractLang.ContractLangPackage;
import be.uantwerpen.cosys.contractLang.ContractSet;
import be.uantwerpen.cosys.contractLang.Root;

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.eclipse.emf.ecore.impl.MinimalEObjectImpl;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Root</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link be.uantwerpen.cosys.contractLang.impl.RootImpl#getContract <em>Contract</em>}</li>
 *   <li>{@link be.uantwerpen.cosys.contractLang.impl.RootImpl#getContractSet <em>Contract Set</em>}</li>
 * </ul>
 *
 * @generated
 */
public class RootImpl extends MinimalEObjectImpl.Container implements Root
{
  /**
   * The cached value of the '{@link #getContract() <em>Contract</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getContract()
   * @generated
   * @ordered
   */
  protected Contract contract;

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

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

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

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Contract getContract()
  {
    return contract;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetContract(Contract newContract, NotificationChain msgs)
  {
    Contract oldContract = contract;
    contract = newContract;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ContractLangPackage.ROOT__CONTRACT, oldContract, newContract);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void setContract(Contract newContract)
  {
    if (newContract != contract)
    {
      NotificationChain msgs = null;
      if (contract != null)
        msgs = ((InternalEObject)contract).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - ContractLangPackage.ROOT__CONTRACT, null, msgs);
      if (newContract != null)
        msgs = ((InternalEObject)newContract).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - ContractLangPackage.ROOT__CONTRACT, null, msgs);
      msgs = basicSetContract(newContract, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, ContractLangPackage.ROOT__CONTRACT, newContract, newContract));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public ContractSet getContractSet()
  {
    return contractSet;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetContractSet(ContractSet newContractSet, NotificationChain msgs)
  {
    ContractSet oldContractSet = contractSet;
    contractSet = newContractSet;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ContractLangPackage.ROOT__CONTRACT_SET, oldContractSet, newContractSet);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void setContractSet(ContractSet newContractSet)
  {
    if (newContractSet != contractSet)
    {
      NotificationChain msgs = null;
      if (contractSet != null)
        msgs = ((InternalEObject)contractSet).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - ContractLangPackage.ROOT__CONTRACT_SET, null, msgs);
      if (newContractSet != null)
        msgs = ((InternalEObject)newContractSet).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - ContractLangPackage.ROOT__CONTRACT_SET, null, msgs);
      msgs = basicSetContractSet(newContractSet, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, ContractLangPackage.ROOT__CONTRACT_SET, newContractSet, newContractSet));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case ContractLangPackage.ROOT__CONTRACT:
        return basicSetContract(null, msgs);
      case ContractLangPackage.ROOT__CONTRACT_SET:
        return basicSetContractSet(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.ROOT__CONTRACT:
        return getContract();
      case ContractLangPackage.ROOT__CONTRACT_SET:
        return getContractSet();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case ContractLangPackage.ROOT__CONTRACT:
        setContract((Contract)newValue);
        return;
      case ContractLangPackage.ROOT__CONTRACT_SET:
        setContractSet((ContractSet)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case ContractLangPackage.ROOT__CONTRACT:
        setContract((Contract)null);
        return;
      case ContractLangPackage.ROOT__CONTRACT_SET:
        setContractSet((ContractSet)null);
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case ContractLangPackage.ROOT__CONTRACT:
        return contract != null;
      case ContractLangPackage.ROOT__CONTRACT_SET:
        return contractSet != null;
    }
    return super.eIsSet(featureID);
  }

} //RootImpl
