/**
 */
package com.irtsaintexupery.pseim.mapping.impl;

import com.irtsaintexupery.pseim.mapping.CardinalityValue;
import com.irtsaintexupery.pseim.mapping.MappingPackage;

import com.irtsaintexupery.pseim.pseim.CardinalityElement;

import org.eclipse.emf.common.notify.Notification;

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>Cardinality Value</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link com.irtsaintexupery.pseim.mapping.impl.CardinalityValueImpl#getCardinalityElement <em>Cardinality Element</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.mapping.impl.CardinalityValueImpl#getValue <em>Value</em>}</li>
 * </ul>
 *
 * @generated
 */
public class CardinalityValueImpl extends MinimalEObjectImpl.Container implements CardinalityValue {
	/**
	 * The cached value of the '{@link #getCardinalityElement() <em>Cardinality Element</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCardinalityElement()
	 * @generated
	 * @ordered
	 */
	protected CardinalityElement cardinalityElement;

	/**
	 * The default value of the '{@link #getValue() <em>Value</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getValue()
	 * @generated
	 * @ordered
	 */
	protected static final int VALUE_EDEFAULT = 0;

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

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public CardinalityElement getCardinalityElement() {
		if (cardinalityElement != null && cardinalityElement.eIsProxy()) {
			InternalEObject oldCardinalityElement = (InternalEObject)cardinalityElement;
			cardinalityElement = (CardinalityElement)eResolveProxy(oldCardinalityElement);
			if (cardinalityElement != oldCardinalityElement) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, MappingPackage.CARDINALITY_VALUE__CARDINALITY_ELEMENT, oldCardinalityElement, cardinalityElement));
			}
		}
		return cardinalityElement;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public CardinalityElement basicGetCardinalityElement() {
		return cardinalityElement;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setCardinalityElement(CardinalityElement newCardinalityElement) {
		CardinalityElement oldCardinalityElement = cardinalityElement;
		cardinalityElement = newCardinalityElement;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, MappingPackage.CARDINALITY_VALUE__CARDINALITY_ELEMENT, oldCardinalityElement, cardinalityElement));
	}

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setValue(int newValue) {
		int oldValue = value;
		value = newValue;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, MappingPackage.CARDINALITY_VALUE__VALUE, oldValue, value));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case MappingPackage.CARDINALITY_VALUE__CARDINALITY_ELEMENT:
				if (resolve) return getCardinalityElement();
				return basicGetCardinalityElement();
			case MappingPackage.CARDINALITY_VALUE__VALUE:
				return getValue();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case MappingPackage.CARDINALITY_VALUE__CARDINALITY_ELEMENT:
				setCardinalityElement((CardinalityElement)newValue);
				return;
			case MappingPackage.CARDINALITY_VALUE__VALUE:
				setValue((Integer)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case MappingPackage.CARDINALITY_VALUE__CARDINALITY_ELEMENT:
				setCardinalityElement((CardinalityElement)null);
				return;
			case MappingPackage.CARDINALITY_VALUE__VALUE:
				setValue(VALUE_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case MappingPackage.CARDINALITY_VALUE__CARDINALITY_ELEMENT:
				return cardinalityElement != null;
			case MappingPackage.CARDINALITY_VALUE__VALUE:
				return value != VALUE_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(" (value: ");
		result.append(value);
		result.append(')');
		return result.toString();
	}

} //CardinalityValueImpl
