/*******************************************************************************
 * Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the LGPL 3.0
 * which accompanies this distribution, and is available at
 * https://www.gnu.org/licenses/lgpl-3.0-standalone.html
 *
 * Contributors:
 *      Faiez Zalila - initial API and implementation and/or initial documentation
 *******************************************************************************/
/**
 * generated by Xtext 2.10.0
 */
package fr.irit.fiacre.xtext.fiacre.impl;

import fr.irit.fiacre.xtext.fiacre.Declaration;
import fr.irit.fiacre.xtext.fiacre.FiacrePackage;
import fr.irit.fiacre.xtext.fiacre.NamedElement;
import fr.irit.fiacre.xtext.fiacre.ParameterizedDeclaration;
import fr.irit.fiacre.xtext.fiacre.ParametersDeclaration;
import fr.irit.fiacre.xtext.fiacre.PathDeclarationUse;
import fr.irit.fiacre.xtext.fiacre.PortsDeclaration;
import fr.irit.fiacre.xtext.fiacre.PriorityDeclaration;
import fr.irit.fiacre.xtext.fiacre.ProcessDeclaration;
import fr.irit.fiacre.xtext.fiacre.StateDeclaration;
import fr.irit.fiacre.xtext.fiacre.Statement;
import fr.irit.fiacre.xtext.fiacre.Transition;
import fr.irit.fiacre.xtext.fiacre.VariablesDeclaration;

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;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Process Declaration</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link fr.irit.fiacre.xtext.fiacre.impl.ProcessDeclarationImpl#getName <em>Name</em>}</li>
 *   <li>{@link fr.irit.fiacre.xtext.fiacre.impl.ProcessDeclarationImpl#getParameters <em>Parameters</em>}</li>
 *   <li>{@link fr.irit.fiacre.xtext.fiacre.impl.ProcessDeclarationImpl#getVariables <em>Variables</em>}</li>
 *   <li>{@link fr.irit.fiacre.xtext.fiacre.impl.ProcessDeclarationImpl#getPorts <em>Ports</em>}</li>
 *   <li>{@link fr.irit.fiacre.xtext.fiacre.impl.ProcessDeclarationImpl#getLocalPorts <em>Local Ports</em>}</li>
 *   <li>{@link fr.irit.fiacre.xtext.fiacre.impl.ProcessDeclarationImpl#getPriorities <em>Priorities</em>}</li>
 *   <li>{@link fr.irit.fiacre.xtext.fiacre.impl.ProcessDeclarationImpl#getStates <em>States</em>}</li>
 *   <li>{@link fr.irit.fiacre.xtext.fiacre.impl.ProcessDeclarationImpl#getPrelude <em>Prelude</em>}</li>
 *   <li>{@link fr.irit.fiacre.xtext.fiacre.impl.ProcessDeclarationImpl#getTransitions <em>Transitions</em>}</li>
 * </ul>
 *
 * @generated
 */
public class ProcessDeclarationImpl extends RootDeclarationImpl implements ProcessDeclaration
{
  /**
   * The default value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
  protected static final String NAME_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
  protected String name = NAME_EDEFAULT;

  /**
   * The cached value of the '{@link #getParameters() <em>Parameters</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getParameters()
   * @generated
   * @ordered
   */
  protected EList<ParametersDeclaration> parameters;

  /**
   * The cached value of the '{@link #getVariables() <em>Variables</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getVariables()
   * @generated
   * @ordered
   */
  protected EList<VariablesDeclaration> variables;

  /**
   * The cached value of the '{@link #getPorts() <em>Ports</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getPorts()
   * @generated
   * @ordered
   */
  protected EList<PortsDeclaration> ports;

  /**
   * The cached value of the '{@link #getLocalPorts() <em>Local Ports</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getLocalPorts()
   * @generated
   * @ordered
   */
  protected EList<PortsDeclaration> localPorts;

  /**
   * The cached value of the '{@link #getPriorities() <em>Priorities</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getPriorities()
   * @generated
   * @ordered
   */
  protected EList<PriorityDeclaration> priorities;

  /**
   * The cached value of the '{@link #getStates() <em>States</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getStates()
   * @generated
   * @ordered
   */
  protected EList<StateDeclaration> states;

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

  /**
   * The cached value of the '{@link #getTransitions() <em>Transitions</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getTransitions()
   * @generated
   * @ordered
   */
  protected EList<Transition> transitions;

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

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return FiacrePackage.eINSTANCE.getProcessDeclaration();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getName()
  {
    return name;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setName(String newName)
  {
    String oldName = name;
    name = newName;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, FiacrePackage.PROCESS_DECLARATION__NAME, oldName, name));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<ParametersDeclaration> getParameters()
  {
    if (parameters == null)
    {
      parameters = new EObjectContainmentEList<ParametersDeclaration>(ParametersDeclaration.class, this, FiacrePackage.PROCESS_DECLARATION__PARAMETERS);
    }
    return parameters;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<VariablesDeclaration> getVariables()
  {
    if (variables == null)
    {
      variables = new EObjectContainmentEList<VariablesDeclaration>(VariablesDeclaration.class, this, FiacrePackage.PROCESS_DECLARATION__VARIABLES);
    }
    return variables;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<PortsDeclaration> getPorts()
  {
    if (ports == null)
    {
      ports = new EObjectContainmentEList<PortsDeclaration>(PortsDeclaration.class, this, FiacrePackage.PROCESS_DECLARATION__PORTS);
    }
    return ports;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<PortsDeclaration> getLocalPorts()
  {
    if (localPorts == null)
    {
      localPorts = new EObjectContainmentEList<PortsDeclaration>(PortsDeclaration.class, this, FiacrePackage.PROCESS_DECLARATION__LOCAL_PORTS);
    }
    return localPorts;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<PriorityDeclaration> getPriorities()
  {
    if (priorities == null)
    {
      priorities = new EObjectContainmentEList<PriorityDeclaration>(PriorityDeclaration.class, this, FiacrePackage.PROCESS_DECLARATION__PRIORITIES);
    }
    return priorities;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<StateDeclaration> getStates()
  {
    if (states == null)
    {
      states = new EObjectContainmentEList<StateDeclaration>(StateDeclaration.class, this, FiacrePackage.PROCESS_DECLARATION__STATES);
    }
    return states;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Statement getPrelude()
  {
    return prelude;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetPrelude(Statement newPrelude, NotificationChain msgs)
  {
    Statement oldPrelude = prelude;
    prelude = newPrelude;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, FiacrePackage.PROCESS_DECLARATION__PRELUDE, oldPrelude, newPrelude);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setPrelude(Statement newPrelude)
  {
    if (newPrelude != prelude)
    {
      NotificationChain msgs = null;
      if (prelude != null)
        msgs = ((InternalEObject)prelude).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - FiacrePackage.PROCESS_DECLARATION__PRELUDE, null, msgs);
      if (newPrelude != null)
        msgs = ((InternalEObject)newPrelude).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - FiacrePackage.PROCESS_DECLARATION__PRELUDE, null, msgs);
      msgs = basicSetPrelude(newPrelude, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, FiacrePackage.PROCESS_DECLARATION__PRELUDE, newPrelude, newPrelude));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Transition> getTransitions()
  {
    if (transitions == null)
    {
      transitions = new EObjectContainmentEList<Transition>(Transition.class, this, FiacrePackage.PROCESS_DECLARATION__TRANSITIONS);
    }
    return transitions;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case FiacrePackage.PROCESS_DECLARATION__PARAMETERS:
        return ((InternalEList<?>)getParameters()).basicRemove(otherEnd, msgs);
      case FiacrePackage.PROCESS_DECLARATION__VARIABLES:
        return ((InternalEList<?>)getVariables()).basicRemove(otherEnd, msgs);
      case FiacrePackage.PROCESS_DECLARATION__PORTS:
        return ((InternalEList<?>)getPorts()).basicRemove(otherEnd, msgs);
      case FiacrePackage.PROCESS_DECLARATION__LOCAL_PORTS:
        return ((InternalEList<?>)getLocalPorts()).basicRemove(otherEnd, msgs);
      case FiacrePackage.PROCESS_DECLARATION__PRIORITIES:
        return ((InternalEList<?>)getPriorities()).basicRemove(otherEnd, msgs);
      case FiacrePackage.PROCESS_DECLARATION__STATES:
        return ((InternalEList<?>)getStates()).basicRemove(otherEnd, msgs);
      case FiacrePackage.PROCESS_DECLARATION__PRELUDE:
        return basicSetPrelude(null, msgs);
      case FiacrePackage.PROCESS_DECLARATION__TRANSITIONS:
        return ((InternalEList<?>)getTransitions()).basicRemove(otherEnd, 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 FiacrePackage.PROCESS_DECLARATION__NAME:
        return getName();
      case FiacrePackage.PROCESS_DECLARATION__PARAMETERS:
        return getParameters();
      case FiacrePackage.PROCESS_DECLARATION__VARIABLES:
        return getVariables();
      case FiacrePackage.PROCESS_DECLARATION__PORTS:
        return getPorts();
      case FiacrePackage.PROCESS_DECLARATION__LOCAL_PORTS:
        return getLocalPorts();
      case FiacrePackage.PROCESS_DECLARATION__PRIORITIES:
        return getPriorities();
      case FiacrePackage.PROCESS_DECLARATION__STATES:
        return getStates();
      case FiacrePackage.PROCESS_DECLARATION__PRELUDE:
        return getPrelude();
      case FiacrePackage.PROCESS_DECLARATION__TRANSITIONS:
        return getTransitions();
    }
    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 FiacrePackage.PROCESS_DECLARATION__NAME:
        setName((String)newValue);
        return;
      case FiacrePackage.PROCESS_DECLARATION__PARAMETERS:
        getParameters().clear();
        getParameters().addAll((Collection<? extends ParametersDeclaration>)newValue);
        return;
      case FiacrePackage.PROCESS_DECLARATION__VARIABLES:
        getVariables().clear();
        getVariables().addAll((Collection<? extends VariablesDeclaration>)newValue);
        return;
      case FiacrePackage.PROCESS_DECLARATION__PORTS:
        getPorts().clear();
        getPorts().addAll((Collection<? extends PortsDeclaration>)newValue);
        return;
      case FiacrePackage.PROCESS_DECLARATION__LOCAL_PORTS:
        getLocalPorts().clear();
        getLocalPorts().addAll((Collection<? extends PortsDeclaration>)newValue);
        return;
      case FiacrePackage.PROCESS_DECLARATION__PRIORITIES:
        getPriorities().clear();
        getPriorities().addAll((Collection<? extends PriorityDeclaration>)newValue);
        return;
      case FiacrePackage.PROCESS_DECLARATION__STATES:
        getStates().clear();
        getStates().addAll((Collection<? extends StateDeclaration>)newValue);
        return;
      case FiacrePackage.PROCESS_DECLARATION__PRELUDE:
        setPrelude((Statement)newValue);
        return;
      case FiacrePackage.PROCESS_DECLARATION__TRANSITIONS:
        getTransitions().clear();
        getTransitions().addAll((Collection<? extends Transition>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case FiacrePackage.PROCESS_DECLARATION__NAME:
        setName(NAME_EDEFAULT);
        return;
      case FiacrePackage.PROCESS_DECLARATION__PARAMETERS:
        getParameters().clear();
        return;
      case FiacrePackage.PROCESS_DECLARATION__VARIABLES:
        getVariables().clear();
        return;
      case FiacrePackage.PROCESS_DECLARATION__PORTS:
        getPorts().clear();
        return;
      case FiacrePackage.PROCESS_DECLARATION__LOCAL_PORTS:
        getLocalPorts().clear();
        return;
      case FiacrePackage.PROCESS_DECLARATION__PRIORITIES:
        getPriorities().clear();
        return;
      case FiacrePackage.PROCESS_DECLARATION__STATES:
        getStates().clear();
        return;
      case FiacrePackage.PROCESS_DECLARATION__PRELUDE:
        setPrelude((Statement)null);
        return;
      case FiacrePackage.PROCESS_DECLARATION__TRANSITIONS:
        getTransitions().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case FiacrePackage.PROCESS_DECLARATION__NAME:
        return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
      case FiacrePackage.PROCESS_DECLARATION__PARAMETERS:
        return parameters != null && !parameters.isEmpty();
      case FiacrePackage.PROCESS_DECLARATION__VARIABLES:
        return variables != null && !variables.isEmpty();
      case FiacrePackage.PROCESS_DECLARATION__PORTS:
        return ports != null && !ports.isEmpty();
      case FiacrePackage.PROCESS_DECLARATION__LOCAL_PORTS:
        return localPorts != null && !localPorts.isEmpty();
      case FiacrePackage.PROCESS_DECLARATION__PRIORITIES:
        return priorities != null && !priorities.isEmpty();
      case FiacrePackage.PROCESS_DECLARATION__STATES:
        return states != null && !states.isEmpty();
      case FiacrePackage.PROCESS_DECLARATION__PRELUDE:
        return prelude != null;
      case FiacrePackage.PROCESS_DECLARATION__TRANSITIONS:
        return transitions != null && !transitions.isEmpty();
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public int eBaseStructuralFeatureID(int derivedFeatureID, Class<?> baseClass)
  {
    if (baseClass == PathDeclarationUse.class)
    {
      switch (derivedFeatureID)
      {
        default: return -1;
      }
    }
    if (baseClass == NamedElement.class)
    {
      switch (derivedFeatureID)
      {
        case FiacrePackage.PROCESS_DECLARATION__NAME: return FiacrePackage.NAMED_ELEMENT__NAME;
        default: return -1;
      }
    }
    if (baseClass == Declaration.class)
    {
      switch (derivedFeatureID)
      {
        default: return -1;
      }
    }
    if (baseClass == ParameterizedDeclaration.class)
    {
      switch (derivedFeatureID)
      {
        case FiacrePackage.PROCESS_DECLARATION__PARAMETERS: return FiacrePackage.PARAMETERIZED_DECLARATION__PARAMETERS;
        case FiacrePackage.PROCESS_DECLARATION__VARIABLES: return FiacrePackage.PARAMETERIZED_DECLARATION__VARIABLES;
        default: return -1;
      }
    }
    return super.eBaseStructuralFeatureID(derivedFeatureID, baseClass);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public int eDerivedStructuralFeatureID(int baseFeatureID, Class<?> baseClass)
  {
    if (baseClass == PathDeclarationUse.class)
    {
      switch (baseFeatureID)
      {
        default: return -1;
      }
    }
    if (baseClass == NamedElement.class)
    {
      switch (baseFeatureID)
      {
        case FiacrePackage.NAMED_ELEMENT__NAME: return FiacrePackage.PROCESS_DECLARATION__NAME;
        default: return -1;
      }
    }
    if (baseClass == Declaration.class)
    {
      switch (baseFeatureID)
      {
        default: return -1;
      }
    }
    if (baseClass == ParameterizedDeclaration.class)
    {
      switch (baseFeatureID)
      {
        case FiacrePackage.PARAMETERIZED_DECLARATION__PARAMETERS: return FiacrePackage.PROCESS_DECLARATION__PARAMETERS;
        case FiacrePackage.PARAMETERIZED_DECLARATION__VARIABLES: return FiacrePackage.PROCESS_DECLARATION__VARIABLES;
        default: return -1;
      }
    }
    return super.eDerivedStructuralFeatureID(baseFeatureID, baseClass);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString()
  {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (name: ");
    result.append(name);
    result.append(')');
    return result.toString();
  }

} //ProcessDeclarationImpl
