/**
 */
package de.ugoe.cs.swe.bnftools.ebnf.impl;

import de.ugoe.cs.swe.bnftools.ebnf.DefinitionList;
import de.ugoe.cs.swe.bnftools.ebnf.EbnfPackage;
import de.ugoe.cs.swe.bnftools.ebnf.Rule;

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>Rule</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link de.ugoe.cs.swe.bnftools.ebnf.impl.RuleImpl#getRulenumber <em>Rulenumber</em>}</li>
 *   <li>{@link de.ugoe.cs.swe.bnftools.ebnf.impl.RuleImpl#getRulevariant <em>Rulevariant</em>}</li>
 *   <li>{@link de.ugoe.cs.swe.bnftools.ebnf.impl.RuleImpl#getName <em>Name</em>}</li>
 *   <li>{@link de.ugoe.cs.swe.bnftools.ebnf.impl.RuleImpl#getDefinitionList <em>Definition List</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class RuleImpl extends MinimalEObjectImpl.Container implements Rule
{
  /**
   * The default value of the '{@link #getRulenumber() <em>Rulenumber</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getRulenumber()
   * @generated
   * @ordered
   */
  protected static final int RULENUMBER_EDEFAULT = 0;

  /**
   * The cached value of the '{@link #getRulenumber() <em>Rulenumber</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getRulenumber()
   * @generated
   * @ordered
   */
  protected int rulenumber = RULENUMBER_EDEFAULT;

  /**
   * The default value of the '{@link #getRulevariant() <em>Rulevariant</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getRulevariant()
   * @generated
   * @ordered
   */
  protected static final String RULEVARIANT_EDEFAULT = null;

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

  /**
   * 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 #getDefinitionList() <em>Definition List</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getDefinitionList()
   * @generated
   * @ordered
   */
  protected DefinitionList definitionList;

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

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

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public int getRulenumber()
  {
    return rulenumber;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setRulenumber(int newRulenumber)
  {
    int oldRulenumber = rulenumber;
    rulenumber = newRulenumber;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, EbnfPackage.RULE__RULENUMBER, oldRulenumber, rulenumber));
  }

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

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setRulevariant(String newRulevariant)
  {
    String oldRulevariant = rulevariant;
    rulevariant = newRulevariant;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, EbnfPackage.RULE__RULEVARIANT, oldRulevariant, rulevariant));
  }

  /**
   * <!-- 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, EbnfPackage.RULE__NAME, oldName, name));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public DefinitionList getDefinitionList()
  {
    return definitionList;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetDefinitionList(DefinitionList newDefinitionList, NotificationChain msgs)
  {
    DefinitionList oldDefinitionList = definitionList;
    definitionList = newDefinitionList;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, EbnfPackage.RULE__DEFINITION_LIST, oldDefinitionList, newDefinitionList);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setDefinitionList(DefinitionList newDefinitionList)
  {
    if (newDefinitionList != definitionList)
    {
      NotificationChain msgs = null;
      if (definitionList != null)
        msgs = ((InternalEObject)definitionList).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - EbnfPackage.RULE__DEFINITION_LIST, null, msgs);
      if (newDefinitionList != null)
        msgs = ((InternalEObject)newDefinitionList).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - EbnfPackage.RULE__DEFINITION_LIST, null, msgs);
      msgs = basicSetDefinitionList(newDefinitionList, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, EbnfPackage.RULE__DEFINITION_LIST, newDefinitionList, newDefinitionList));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case EbnfPackage.RULE__DEFINITION_LIST:
        return basicSetDefinitionList(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 EbnfPackage.RULE__RULENUMBER:
        return getRulenumber();
      case EbnfPackage.RULE__RULEVARIANT:
        return getRulevariant();
      case EbnfPackage.RULE__NAME:
        return getName();
      case EbnfPackage.RULE__DEFINITION_LIST:
        return getDefinitionList();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case EbnfPackage.RULE__RULENUMBER:
        setRulenumber((Integer)newValue);
        return;
      case EbnfPackage.RULE__RULEVARIANT:
        setRulevariant((String)newValue);
        return;
      case EbnfPackage.RULE__NAME:
        setName((String)newValue);
        return;
      case EbnfPackage.RULE__DEFINITION_LIST:
        setDefinitionList((DefinitionList)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case EbnfPackage.RULE__RULENUMBER:
        setRulenumber(RULENUMBER_EDEFAULT);
        return;
      case EbnfPackage.RULE__RULEVARIANT:
        setRulevariant(RULEVARIANT_EDEFAULT);
        return;
      case EbnfPackage.RULE__NAME:
        setName(NAME_EDEFAULT);
        return;
      case EbnfPackage.RULE__DEFINITION_LIST:
        setDefinitionList((DefinitionList)null);
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case EbnfPackage.RULE__RULENUMBER:
        return rulenumber != RULENUMBER_EDEFAULT;
      case EbnfPackage.RULE__RULEVARIANT:
        return RULEVARIANT_EDEFAULT == null ? rulevariant != null : !RULEVARIANT_EDEFAULT.equals(rulevariant);
      case EbnfPackage.RULE__NAME:
        return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
      case EbnfPackage.RULE__DEFINITION_LIST:
        return definitionList != null;
    }
    return super.eIsSet(featureID);
  }

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

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

} //RuleImpl
