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

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

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

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

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

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

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

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

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetBefore(PrecendenceNode newBefore, NotificationChain msgs) {
		PrecendenceNode oldBefore = before;
		before = newBefore;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, HintcoPackage.PRECENDENCE_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(PrecendenceNode newBefore) {
		if (newBefore != before) {
			NotificationChain msgs = null;
			if (before != null)
				msgs = ((InternalEObject)before).eInverseRemove(this, HintcoPackage.PRECENDENCE_NODE__AFTER, PrecendenceNode.class, msgs);
			if (newBefore != null)
				msgs = ((InternalEObject)newBefore).eInverseAdd(this, HintcoPackage.PRECENDENCE_NODE__AFTER, PrecendenceNode.class, msgs);
			msgs = basicSetBefore(newBefore, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, HintcoPackage.PRECENDENCE_NODE__BEFORE, newBefore, newBefore));
	}

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetAfter(PrecendenceNode newAfter, NotificationChain msgs) {
		PrecendenceNode oldAfter = after;
		after = newAfter;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, HintcoPackage.PRECENDENCE_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(PrecendenceNode newAfter) {
		if (newAfter != after) {
			NotificationChain msgs = null;
			if (after != null)
				msgs = ((InternalEObject)after).eInverseRemove(this, HintcoPackage.PRECENDENCE_NODE__BEFORE, PrecendenceNode.class, msgs);
			if (newAfter != null)
				msgs = ((InternalEObject)newAfter).eInverseAdd(this, HintcoPackage.PRECENDENCE_NODE__BEFORE, PrecendenceNode.class, msgs);
			msgs = basicSetAfter(newAfter, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, HintcoPackage.PRECENDENCE_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.PRECENDENCE_NODE__PRECEDES:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getPrecedes()).basicAdd(otherEnd, msgs);
			case HintcoPackage.PRECENDENCE_NODE__SUCCEEDS:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getSucceeds()).basicAdd(otherEnd, msgs);
			case HintcoPackage.PRECENDENCE_NODE__BEFORE:
				if (before != null)
					msgs = ((InternalEObject)before).eInverseRemove(this, HintcoPackage.PRECENDENCE_NODE__AFTER, PrecendenceNode.class, msgs);
				return basicSetBefore((PrecendenceNode)otherEnd, msgs);
			case HintcoPackage.PRECENDENCE_NODE__AFTER:
				if (after != null)
					msgs = ((InternalEObject)after).eInverseRemove(this, HintcoPackage.PRECENDENCE_NODE__BEFORE, PrecendenceNode.class, msgs);
				return basicSetAfter((PrecendenceNode)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.PRECENDENCE_NODE__PRECEDES:
				return ((InternalEList<?>)getPrecedes()).basicRemove(otherEnd, msgs);
			case HintcoPackage.PRECENDENCE_NODE__SUCCEEDS:
				return ((InternalEList<?>)getSucceeds()).basicRemove(otherEnd, msgs);
			case HintcoPackage.PRECENDENCE_NODE__BEFORE:
				return basicSetBefore(null, msgs);
			case HintcoPackage.PRECENDENCE_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.PRECENDENCE_NODE__PRECEDES:
				return getPrecedes();
			case HintcoPackage.PRECENDENCE_NODE__SUCCEEDS:
				return getSucceeds();
			case HintcoPackage.PRECENDENCE_NODE__BEFORE:
				if (resolve) return getBefore();
				return basicGetBefore();
			case HintcoPackage.PRECENDENCE_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.PRECENDENCE_NODE__PRECEDES:
				getPrecedes().clear();
				getPrecedes().addAll((Collection<? extends PrecendenceNode>)newValue);
				return;
			case HintcoPackage.PRECENDENCE_NODE__SUCCEEDS:
				getSucceeds().clear();
				getSucceeds().addAll((Collection<? extends PrecendenceNode>)newValue);
				return;
			case HintcoPackage.PRECENDENCE_NODE__BEFORE:
				setBefore((PrecendenceNode)newValue);
				return;
			case HintcoPackage.PRECENDENCE_NODE__AFTER:
				setAfter((PrecendenceNode)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case HintcoPackage.PRECENDENCE_NODE__PRECEDES:
				getPrecedes().clear();
				return;
			case HintcoPackage.PRECENDENCE_NODE__SUCCEEDS:
				getSucceeds().clear();
				return;
			case HintcoPackage.PRECENDENCE_NODE__BEFORE:
				setBefore((PrecendenceNode)null);
				return;
			case HintcoPackage.PRECENDENCE_NODE__AFTER:
				setAfter((PrecendenceNode)null);
				return;
		}
		super.eUnset(featureID);
	}

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

} //PrecendenceNodeImpl
