/**
 */
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.RepeatedSequence;

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

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>Repeated Sequence</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link de.ugoe.cs.swe.bnftools.ebnf.impl.RepeatedSequenceImpl#getDefinitions <em>Definitions</em>}</li>
 *   <li>{@link de.ugoe.cs.swe.bnftools.ebnf.impl.RepeatedSequenceImpl#isMorethanonce <em>Morethanonce</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class RepeatedSequenceImpl extends MinimalEObjectImpl.Container implements RepeatedSequence
{
  /**
   * The cached value of the '{@link #getDefinitions() <em>Definitions</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getDefinitions()
   * @generated
   * @ordered
   */
  protected EList<DefinitionList> definitions;

  /**
   * The default value of the '{@link #isMorethanonce() <em>Morethanonce</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isMorethanonce()
   * @generated
   * @ordered
   */
  protected static final boolean MORETHANONCE_EDEFAULT = false;

  /**
   * The cached value of the '{@link #isMorethanonce() <em>Morethanonce</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isMorethanonce()
   * @generated
   * @ordered
   */
  protected boolean morethanonce = MORETHANONCE_EDEFAULT;

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

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

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<DefinitionList> getDefinitions()
  {
    if (definitions == null)
    {
      definitions = new EObjectContainmentEList<DefinitionList>(DefinitionList.class, this, EbnfPackage.REPEATED_SEQUENCE__DEFINITIONS);
    }
    return definitions;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public boolean isMorethanonce()
  {
    return morethanonce;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setMorethanonce(boolean newMorethanonce)
  {
    boolean oldMorethanonce = morethanonce;
    morethanonce = newMorethanonce;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, EbnfPackage.REPEATED_SEQUENCE__MORETHANONCE, oldMorethanonce, morethanonce));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case EbnfPackage.REPEATED_SEQUENCE__DEFINITIONS:
        return ((InternalEList<?>)getDefinitions()).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 EbnfPackage.REPEATED_SEQUENCE__DEFINITIONS:
        return getDefinitions();
      case EbnfPackage.REPEATED_SEQUENCE__MORETHANONCE:
        return isMorethanonce();
    }
    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 EbnfPackage.REPEATED_SEQUENCE__DEFINITIONS:
        getDefinitions().clear();
        getDefinitions().addAll((Collection<? extends DefinitionList>)newValue);
        return;
      case EbnfPackage.REPEATED_SEQUENCE__MORETHANONCE:
        setMorethanonce((Boolean)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case EbnfPackage.REPEATED_SEQUENCE__DEFINITIONS:
        getDefinitions().clear();
        return;
      case EbnfPackage.REPEATED_SEQUENCE__MORETHANONCE:
        setMorethanonce(MORETHANONCE_EDEFAULT);
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case EbnfPackage.REPEATED_SEQUENCE__DEFINITIONS:
        return definitions != null && !definitions.isEmpty();
      case EbnfPackage.REPEATED_SEQUENCE__MORETHANONCE:
        return morethanonce != MORETHANONCE_EDEFAULT;
    }
    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(" (morethanonce: ");
    result.append(morethanonce);
    result.append(')');
    return result.toString();
  }

} //RepeatedSequenceImpl
