/**
 */
package org.xtext.example.mydsl2.myDsl2.impl;

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;

import org.xtext.example.mydsl2.myDsl2.MyDsl2Package;
import org.xtext.example.mydsl2.myDsl2.SitePermission;
import org.xtext.example.mydsl2.myDsl2.User;
import org.xtext.example.mydsl2.myDsl2.UserModel;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>User Model</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.xtext.example.mydsl2.myDsl2.impl.UserModelImpl#getName <em>Name</em>}</li>
 *   <li>{@link org.xtext.example.mydsl2.myDsl2.impl.UserModelImpl#getUsers <em>Users</em>}</li>
 *   <li>{@link org.xtext.example.mydsl2.myDsl2.impl.UserModelImpl#getSitePermissions <em>Site Permissions</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class UserModelImpl extends MinimalEObjectImpl.Container implements UserModel
{
  /**
   * 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 #getUsers() <em>Users</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getUsers()
   * @generated
   * @ordered
   */
  protected EList<User> users;

  /**
   * The cached value of the '{@link #getSitePermissions() <em>Site Permissions</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getSitePermissions()
   * @generated
   * @ordered
   */
  protected EList<SitePermission> sitePermissions;

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

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

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

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<User> getUsers()
  {
    if (users == null)
    {
      users = new EObjectContainmentEList<User>(User.class, this, MyDsl2Package.USER_MODEL__USERS);
    }
    return users;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<SitePermission> getSitePermissions()
  {
    if (sitePermissions == null)
    {
      sitePermissions = new EObjectContainmentEList<SitePermission>(SitePermission.class, this, MyDsl2Package.USER_MODEL__SITE_PERMISSIONS);
    }
    return sitePermissions;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case MyDsl2Package.USER_MODEL__USERS:
        return ((InternalEList<?>)getUsers()).basicRemove(otherEnd, msgs);
      case MyDsl2Package.USER_MODEL__SITE_PERMISSIONS:
        return ((InternalEList<?>)getSitePermissions()).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 MyDsl2Package.USER_MODEL__NAME:
        return getName();
      case MyDsl2Package.USER_MODEL__USERS:
        return getUsers();
      case MyDsl2Package.USER_MODEL__SITE_PERMISSIONS:
        return getSitePermissions();
    }
    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 MyDsl2Package.USER_MODEL__NAME:
        setName((String)newValue);
        return;
      case MyDsl2Package.USER_MODEL__USERS:
        getUsers().clear();
        getUsers().addAll((Collection<? extends User>)newValue);
        return;
      case MyDsl2Package.USER_MODEL__SITE_PERMISSIONS:
        getSitePermissions().clear();
        getSitePermissions().addAll((Collection<? extends SitePermission>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case MyDsl2Package.USER_MODEL__NAME:
        setName(NAME_EDEFAULT);
        return;
      case MyDsl2Package.USER_MODEL__USERS:
        getUsers().clear();
        return;
      case MyDsl2Package.USER_MODEL__SITE_PERMISSIONS:
        getSitePermissions().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case MyDsl2Package.USER_MODEL__NAME:
        return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
      case MyDsl2Package.USER_MODEL__USERS:
        return users != null && !users.isEmpty();
      case MyDsl2Package.USER_MODEL__SITE_PERMISSIONS:
        return sitePermissions != null && !sitePermissions.isEmpty();
    }
    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(" (name: ");
    result.append(name);
    result.append(')');
    return result.toString();
  }

} //UserModelImpl
