/**
 */
package ua.ansymo.hintco.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.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;
import org.eclipse.emf.ecore.util.InternalEList;

import ua.ansymo.hintco.Alternative;
import ua.ansymo.hintco.CandidateScenario;
import ua.ansymo.hintco.CosimUnitInstance;
import ua.ansymo.hintco.HintcoPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Candidate Scenario</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link ua.ansymo.hintco.impl.CandidateScenarioImpl#getWeight <em>Weight</em>}</li>
 *   <li>{@link ua.ansymo.hintco.impl.CandidateScenarioImpl#getImplies <em>Implies</em>}</li>
 *   <li>{@link ua.ansymo.hintco.impl.CandidateScenarioImpl#getCosimunits <em>Cosimunits</em>}</li>
 *   <li>{@link ua.ansymo.hintco.impl.CandidateScenarioImpl#getName <em>Name</em>}</li>
 * </ul>
 *
 * @generated
 */
public class CandidateScenarioImpl extends IDedImpl implements CandidateScenario {
	/**
	 * The default value of the '{@link #getWeight() <em>Weight</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getWeight()
	 * @generated
	 * @ordered
	 */
	protected static final int WEIGHT_EDEFAULT = 0;

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

	/**
	 * The cached value of the '{@link #getImplies() <em>Implies</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getImplies()
	 * @generated
	 * @ordered
	 */
	protected EList<Alternative> implies;

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

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

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

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setWeight(int newWeight) {
		int oldWeight = weight;
		weight = newWeight;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, HintcoPackage.CANDIDATE_SCENARIO__WEIGHT, oldWeight, weight));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Alternative> getImplies() {
		if (implies == null) {
			implies = new EObjectResolvingEList<Alternative>(Alternative.class, this, HintcoPackage.CANDIDATE_SCENARIO__IMPLIES);
		}
		return implies;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<CosimUnitInstance> getCosimunits() {
		if (cosimunits == null) {
			cosimunits = new EObjectContainmentEList<CosimUnitInstance>(CosimUnitInstance.class, this, HintcoPackage.CANDIDATE_SCENARIO__COSIMUNITS);
		}
		return cosimunits;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		String _identifier = this.getIdentifier();
		String _plus = (_identifier + "(w=");
		int _weight = this.getWeight();
		String _plus_1 = (_plus + Integer.valueOf(_weight));
		return (_plus_1 + ")");
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case HintcoPackage.CANDIDATE_SCENARIO__COSIMUNITS:
				return ((InternalEList<?>)getCosimunits()).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 HintcoPackage.CANDIDATE_SCENARIO__WEIGHT:
				return getWeight();
			case HintcoPackage.CANDIDATE_SCENARIO__IMPLIES:
				return getImplies();
			case HintcoPackage.CANDIDATE_SCENARIO__COSIMUNITS:
				return getCosimunits();
			case HintcoPackage.CANDIDATE_SCENARIO__NAME:
				return getName();
		}
		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 HintcoPackage.CANDIDATE_SCENARIO__WEIGHT:
				setWeight((Integer)newValue);
				return;
			case HintcoPackage.CANDIDATE_SCENARIO__IMPLIES:
				getImplies().clear();
				getImplies().addAll((Collection<? extends Alternative>)newValue);
				return;
			case HintcoPackage.CANDIDATE_SCENARIO__COSIMUNITS:
				getCosimunits().clear();
				getCosimunits().addAll((Collection<? extends CosimUnitInstance>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case HintcoPackage.CANDIDATE_SCENARIO__WEIGHT:
				setWeight(WEIGHT_EDEFAULT);
				return;
			case HintcoPackage.CANDIDATE_SCENARIO__IMPLIES:
				getImplies().clear();
				return;
			case HintcoPackage.CANDIDATE_SCENARIO__COSIMUNITS:
				getCosimunits().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case HintcoPackage.CANDIDATE_SCENARIO__WEIGHT:
				return weight != WEIGHT_EDEFAULT;
			case HintcoPackage.CANDIDATE_SCENARIO__IMPLIES:
				return implies != null && !implies.isEmpty();
			case HintcoPackage.CANDIDATE_SCENARIO__COSIMUNITS:
				return cosimunits != null && !cosimunits.isEmpty();
			case HintcoPackage.CANDIDATE_SCENARIO__NAME:
				return NAME_EDEFAULT == null ? getName() != null : !NAME_EDEFAULT.equals(getName());
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public int eBaseStructuralFeatureID(int derivedFeatureID, Class<?> baseClass) {
		if (baseClass == Alternative.class) {
			switch (derivedFeatureID) {
				case HintcoPackage.CANDIDATE_SCENARIO__WEIGHT: return HintcoPackage.ALTERNATIVE__WEIGHT;
				case HintcoPackage.CANDIDATE_SCENARIO__IMPLIES: return HintcoPackage.ALTERNATIVE__IMPLIES;
				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 == Alternative.class) {
			switch (baseFeatureID) {
				case HintcoPackage.ALTERNATIVE__WEIGHT: return HintcoPackage.CANDIDATE_SCENARIO__WEIGHT;
				case HintcoPackage.ALTERNATIVE__IMPLIES: return HintcoPackage.CANDIDATE_SCENARIO__IMPLIES;
				default: return -1;
			}
		}
		return super.eDerivedStructuralFeatureID(baseFeatureID, baseClass);
	}

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

		StringBuilder result = new StringBuilder(super.toString());
		result.append(" (weight: ");
		result.append(weight);
		result.append(')');
		return result.toString();
	}

} //CandidateScenarioImpl
