/*******************************************************************************
 * 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
 *******************************************************************************/
/**
 */
package com.irtsaintexupery.fiacre.instance.fiacreinstance.impl;

import fr.irit.fiacre.xtext.fiacre.Model;

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 com.irtsaintexupery.fiacre.instance.fiacreinstance.DeclarationInstance;
import com.irtsaintexupery.fiacre.instance.fiacreinstance.FiacreinstancePackage;
import com.irtsaintexupery.fiacre.instance.fiacreinstance.InstanceModel;
import com.irtsaintexupery.fiacre.instance.fiacreinstance.StatementBlock;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Instance Model</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link com.irtsaintexupery.fiacre.instance.fiacreinstance.impl.InstanceModelImpl#getName <em>Name</em>}</li>
 *   <li>{@link com.irtsaintexupery.fiacre.instance.fiacreinstance.impl.InstanceModelImpl#getModel <em>Model</em>}</li>
 *   <li>{@link com.irtsaintexupery.fiacre.instance.fiacreinstance.impl.InstanceModelImpl#getInstance <em>Instance</em>}</li>
 *   <li>{@link com.irtsaintexupery.fiacre.instance.fiacreinstance.impl.InstanceModelImpl#getStatementBlocks <em>Statement Blocks</em>}</li>
 * </ul>
 *
 * @generated
 */
public class InstanceModelImpl extends MinimalEObjectImpl.Container implements InstanceModel {
	/**
	 * 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 #getModel() <em>Model</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getModel()
	 * @generated
	 * @ordered
	 */
	protected Model model;

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

	/**
	 * The cached value of the '{@link #getStatementBlocks() <em>Statement Blocks</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStatementBlocks()
	 * @generated
	 * @ordered
	 */
	protected EList<StatementBlock> statementBlocks;

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return FiacreinstancePackage.Literals.INSTANCE_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, FiacreinstancePackage.INSTANCE_MODEL__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Model getModel() {
		if (model != null && model.eIsProxy()) {
			InternalEObject oldModel = (InternalEObject)model;
			model = (Model)eResolveProxy(oldModel);
			if (model != oldModel) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, FiacreinstancePackage.INSTANCE_MODEL__MODEL, oldModel, model));
			}
		}
		return model;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Model basicGetModel() {
		return model;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setModel(Model newModel) {
		Model oldModel = model;
		model = newModel;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, FiacreinstancePackage.INSTANCE_MODEL__MODEL, oldModel, model));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<DeclarationInstance> getInstance() {
		if (instance == null) {
			instance = new EObjectContainmentEList<DeclarationInstance>(DeclarationInstance.class, this, FiacreinstancePackage.INSTANCE_MODEL__INSTANCE);
		}
		return instance;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<StatementBlock> getStatementBlocks() {
		if (statementBlocks == null) {
			statementBlocks = new EObjectContainmentEList<StatementBlock>(StatementBlock.class, this, FiacreinstancePackage.INSTANCE_MODEL__STATEMENT_BLOCKS);
		}
		return statementBlocks;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case FiacreinstancePackage.INSTANCE_MODEL__INSTANCE:
				return ((InternalEList<?>)getInstance()).basicRemove(otherEnd, msgs);
			case FiacreinstancePackage.INSTANCE_MODEL__STATEMENT_BLOCKS:
				return ((InternalEList<?>)getStatementBlocks()).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 FiacreinstancePackage.INSTANCE_MODEL__NAME:
				return getName();
			case FiacreinstancePackage.INSTANCE_MODEL__MODEL:
				if (resolve) return getModel();
				return basicGetModel();
			case FiacreinstancePackage.INSTANCE_MODEL__INSTANCE:
				return getInstance();
			case FiacreinstancePackage.INSTANCE_MODEL__STATEMENT_BLOCKS:
				return getStatementBlocks();
		}
		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 FiacreinstancePackage.INSTANCE_MODEL__NAME:
				setName((String)newValue);
				return;
			case FiacreinstancePackage.INSTANCE_MODEL__MODEL:
				setModel((Model)newValue);
				return;
			case FiacreinstancePackage.INSTANCE_MODEL__INSTANCE:
				getInstance().clear();
				getInstance().addAll((Collection<? extends DeclarationInstance>)newValue);
				return;
			case FiacreinstancePackage.INSTANCE_MODEL__STATEMENT_BLOCKS:
				getStatementBlocks().clear();
				getStatementBlocks().addAll((Collection<? extends StatementBlock>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case FiacreinstancePackage.INSTANCE_MODEL__NAME:
				setName(NAME_EDEFAULT);
				return;
			case FiacreinstancePackage.INSTANCE_MODEL__MODEL:
				setModel((Model)null);
				return;
			case FiacreinstancePackage.INSTANCE_MODEL__INSTANCE:
				getInstance().clear();
				return;
			case FiacreinstancePackage.INSTANCE_MODEL__STATEMENT_BLOCKS:
				getStatementBlocks().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case FiacreinstancePackage.INSTANCE_MODEL__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case FiacreinstancePackage.INSTANCE_MODEL__MODEL:
				return model != null;
			case FiacreinstancePackage.INSTANCE_MODEL__INSTANCE:
				return instance != null && !instance.isEmpty();
			case FiacreinstancePackage.INSTANCE_MODEL__STATEMENT_BLOCKS:
				return statementBlocks != null && !statementBlocks.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();
	}

} //InstanceModelImpl
