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

import org.eclipse.emf.ecore.util.EObjectWithInverseResolvingEList;
import org.eclipse.emf.ecore.util.InternalEList;

import ua.ansymo.hintco.HintcoPackage;
import ua.ansymo.hintco.PrecedenceNode;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Precedence Node</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link ua.ansymo.hintco.impl.PrecedenceNodeImpl#getPrecedes <em>Precedes</em>}</li>
 *   <li>{@link ua.ansymo.hintco.impl.PrecedenceNodeImpl#getSucceeds <em>Succeeds</em>}</li>
 *   <li>{@link ua.ansymo.hintco.impl.PrecedenceNodeImpl#getBefore <em>Before</em>}</li>
 *   <li>{@link ua.ansymo.hintco.impl.PrecedenceNodeImpl#getAfter <em>After</em>}</li>
 * </ul>
 *
 * @generated
 */
public abstract class PrecedenceNodeImpl extends MinimalEObjectImpl.Container implements PrecedenceNode {
	/**
	 * The cached value of the '{@link #getPrecedes() <em>Precedes</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPrecedes()
	 * @generated
	 * @ordered
	 */
	protected EList<PrecedenceNode> precedes;

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

	/**
	 * The cached value of the '{@link #getBefore() <em>Before</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBefore()
	 * @generated
	 * @ordered
	 */
	protected PrecedenceNode before;

	/**
	 * The cached value of the '{@link #getAfter() <em>After</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAfter()
	 * @generated
	 * @ordered
	 */
	protected PrecedenceNode after;

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<PrecedenceNode> getPrecedes() {
		if (precedes == null) {
			precedes = new EObjectWithInverseResolvingEList.ManyInverse<PrecedenceNode>(PrecedenceNode.class, this, HintcoPackage.PRECEDENCE_NODE__PRECEDES, HintcoPackage.PRECEDENCE_NODE__SUCCEEDS);
		}
		return precedes;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<PrecedenceNode> getSucceeds() {
		if (succeeds == null) {
			succeeds = new EObjectWithInverseResolvingEList.ManyInverse<PrecedenceNode>(PrecedenceNode.class, this, HintcoPackage.PRECEDENCE_NODE__SUCCEEDS, HintcoPackage.PRECEDENCE_NODE__PRECEDES);
		}
		return succeeds;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PrecedenceNode getBefore() {
		if (before != null && before.eIsProxy()) {
			InternalEObject oldBefore = (InternalEObject)before;
			before = (PrecedenceNode)eResolveProxy(oldBefore);
			if (before != oldBefore) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, HintcoPackage.PRECEDENCE_NODE__BEFORE, oldBefore, before));
			}
		}
		return before;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PrecedenceNode basicGetBefore() {
		return before;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetBefore(PrecedenceNode newBefore, NotificationChain msgs) {
		PrecedenceNode oldBefore = before;
		before = newBefore;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, HintcoPackage.PRECEDENCE_NODE__BEFORE, oldBefore, newBefore);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setBefore(PrecedenceNode newBefore) {
		if (newBefore != before) {
			NotificationChain msgs = null;
			if (before != null)
				msgs = ((InternalEObject)before).eInverseRemove(this, HintcoPackage.PRECEDENCE_NODE__AFTER, PrecedenceNode.class, msgs);
			if (newBefore != null)
				msgs = ((InternalEObject)newBefore).eInverseAdd(this, HintcoPackage.PRECEDENCE_NODE__AFTER, PrecedenceNode.class, msgs);
			msgs = basicSetBefore(newBefore, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, HintcoPackage.PRECEDENCE_NODE__BEFORE, newBefore, newBefore));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PrecedenceNode getAfter() {
		if (after != null && after.eIsProxy()) {
			InternalEObject oldAfter = (InternalEObject)after;
			after = (PrecedenceNode)eResolveProxy(oldAfter);
			if (after != oldAfter) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, HintcoPackage.PRECEDENCE_NODE__AFTER, oldAfter, after));
			}
		}
		return after;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PrecedenceNode basicGetAfter() {
		return after;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetAfter(PrecedenceNode newAfter, NotificationChain msgs) {
		PrecedenceNode oldAfter = after;
		after = newAfter;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, HintcoPackage.PRECEDENCE_NODE__AFTER, oldAfter, newAfter);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setAfter(PrecedenceNode newAfter) {
		if (newAfter != after) {
			NotificationChain msgs = null;
			if (after != null)
				msgs = ((InternalEObject)after).eInverseRemove(this, HintcoPackage.PRECEDENCE_NODE__BEFORE, PrecedenceNode.class, msgs);
			if (newAfter != null)
				msgs = ((InternalEObject)newAfter).eInverseAdd(this, HintcoPackage.PRECEDENCE_NODE__BEFORE, PrecedenceNode.class, msgs);
			msgs = basicSetAfter(newAfter, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, HintcoPackage.PRECEDENCE_NODE__AFTER, newAfter, newAfter));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case HintcoPackage.PRECEDENCE_NODE__PRECEDES:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getPrecedes()).basicAdd(otherEnd, msgs);
			case HintcoPackage.PRECEDENCE_NODE__SUCCEEDS:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getSucceeds()).basicAdd(otherEnd, msgs);
			case HintcoPackage.PRECEDENCE_NODE__BEFORE:
				if (before != null)
					msgs = ((InternalEObject)before).eInverseRemove(this, HintcoPackage.PRECEDENCE_NODE__AFTER, PrecedenceNode.class, msgs);
				return basicSetBefore((PrecedenceNode)otherEnd, msgs);
			case HintcoPackage.PRECEDENCE_NODE__AFTER:
				if (after != null)
					msgs = ((InternalEObject)after).eInverseRemove(this, HintcoPackage.PRECEDENCE_NODE__BEFORE, PrecedenceNode.class, msgs);
				return basicSetAfter((PrecedenceNode)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case HintcoPackage.PRECEDENCE_NODE__PRECEDES:
				return ((InternalEList<?>)getPrecedes()).basicRemove(otherEnd, msgs);
			case HintcoPackage.PRECEDENCE_NODE__SUCCEEDS:
				return ((InternalEList<?>)getSucceeds()).basicRemove(otherEnd, msgs);
			case HintcoPackage.PRECEDENCE_NODE__BEFORE:
				return basicSetBefore(null, msgs);
			case HintcoPackage.PRECEDENCE_NODE__AFTER:
				return basicSetAfter(null, 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.PRECEDENCE_NODE__PRECEDES:
				return getPrecedes();
			case HintcoPackage.PRECEDENCE_NODE__SUCCEEDS:
				return getSucceeds();
			case HintcoPackage.PRECEDENCE_NODE__BEFORE:
				if (resolve) return getBefore();
				return basicGetBefore();
			case HintcoPackage.PRECEDENCE_NODE__AFTER:
				if (resolve) return getAfter();
				return basicGetAfter();
		}
		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.PRECEDENCE_NODE__PRECEDES:
				getPrecedes().clear();
				getPrecedes().addAll((Collection<? extends PrecedenceNode>)newValue);
				return;
			case HintcoPackage.PRECEDENCE_NODE__SUCCEEDS:
				getSucceeds().clear();
				getSucceeds().addAll((Collection<? extends PrecedenceNode>)newValue);
				return;
			case HintcoPackage.PRECEDENCE_NODE__BEFORE:
				setBefore((PrecedenceNode)newValue);
				return;
			case HintcoPackage.PRECEDENCE_NODE__AFTER:
				setAfter((PrecedenceNode)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case HintcoPackage.PRECEDENCE_NODE__PRECEDES:
				getPrecedes().clear();
				return;
			case HintcoPackage.PRECEDENCE_NODE__SUCCEEDS:
				getSucceeds().clear();
				return;
			case HintcoPackage.PRECEDENCE_NODE__BEFORE:
				setBefore((PrecedenceNode)null);
				return;
			case HintcoPackage.PRECEDENCE_NODE__AFTER:
				setAfter((PrecedenceNode)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case HintcoPackage.PRECEDENCE_NODE__PRECEDES:
				return precedes != null && !precedes.isEmpty();
			case HintcoPackage.PRECEDENCE_NODE__SUCCEEDS:
				return succeeds != null && !succeeds.isEmpty();
			case HintcoPackage.PRECEDENCE_NODE__BEFORE:
				return before != null;
			case HintcoPackage.PRECEDENCE_NODE__AFTER:
				return after != null;
		}
		return super.eIsSet(featureID);
	}

} //PrecedenceNodeImpl
