/*******************************************************************************
 * Copyright (c) 2018 IRT AESE (IRT Saint Exupéry).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0
 *
 * Contributors:
 *     Arnaud Dieumegard (IRT Saint Exupéry) - initial API and implementation
 *******************************************************************************/
/**
 */
package com.irtsaintexupery.pseim.pseim.impl;

import com.irtsaintexupery.pseim.pseim.CardinalityElement;
import com.irtsaintexupery.pseim.pseim.LinkType;
import com.irtsaintexupery.pseim.pseim.PatternLink;
import com.irtsaintexupery.pseim.pseim.PseimPackage;

import com.irtsaintexupery.pseim.seim.Element;
import com.irtsaintexupery.pseim.seim.GraphElement;
import com.irtsaintexupery.pseim.seim.IdentifiedElement;
import com.irtsaintexupery.pseim.seim.Link;
import com.irtsaintexupery.pseim.seim.NamedElement;
import com.irtsaintexupery.pseim.seim.Port;
import com.irtsaintexupery.pseim.seim.Property;
import com.irtsaintexupery.pseim.seim.PropertyHolder;
import com.irtsaintexupery.pseim.seim.SeimPackage;

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;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Pattern Link</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link com.irtsaintexupery.pseim.pseim.impl.PatternLinkImpl#getIdentifiedAs <em>Identified As</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.pseim.impl.PatternLinkImpl#getUid <em>Uid</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.pseim.impl.PatternLinkImpl#getName <em>Name</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.pseim.impl.PatternLinkImpl#getProperties <em>Properties</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.pseim.impl.PatternLinkImpl#getSrc <em>Src</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.pseim.impl.PatternLinkImpl#getDst <em>Dst</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.pseim.impl.PatternLinkImpl#getLinkType <em>Link Type</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.pseim.impl.PatternLinkImpl#getElement <em>Element</em>}</li>
 * </ul>
 *
 * @generated
 */
public class PatternLinkImpl extends MinimalEObjectImpl.Container implements PatternLink {
	/**
	 * The cached value of the '{@link #getIdentifiedAs() <em>Identified As</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getIdentifiedAs()
	 * @generated
	 * @ordered
	 */
	protected PropertyHolder identifiedAs;

	/**
	 * The default value of the '{@link #getUid() <em>Uid</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getUid()
	 * @generated
	 * @ordered
	 */
	protected static final String UID_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getUid() <em>Uid</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getUid()
	 * @generated
	 * @ordered
	 */
	protected String uid = UID_EDEFAULT;

	/**
	 * This is true if the Uid attribute has been set.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 * @ordered
	 */
	protected boolean uidESet;

	/**
	 * 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 #getProperties() <em>Properties</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getProperties()
	 * @generated
	 * @ordered
	 */
	protected EList<Property> properties;

	/**
	 * The cached value of the '{@link #getSrc() <em>Src</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSrc()
	 * @generated
	 * @ordered
	 */
	protected Port src;

	/**
	 * The cached value of the '{@link #getDst() <em>Dst</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDst()
	 * @generated
	 * @ordered
	 */
	protected Port dst;

	/**
	 * The default value of the '{@link #getLinkType() <em>Link Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLinkType()
	 * @generated
	 * @ordered
	 */
	protected static final LinkType LINK_TYPE_EDEFAULT = LinkType.TRANSPOSE;

	/**
	 * The cached value of the '{@link #getLinkType() <em>Link Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLinkType()
	 * @generated
	 * @ordered
	 */
	protected LinkType linkType = LINK_TYPE_EDEFAULT;

	/**
	 * The cached value of the '{@link #getElement() <em>Element</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getElement()
	 * @generated
	 * @ordered
	 */
	protected CardinalityElement element;

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PropertyHolder getIdentifiedAs() {
		if (identifiedAs != null && identifiedAs.eIsProxy()) {
			InternalEObject oldIdentifiedAs = (InternalEObject) identifiedAs;
			identifiedAs = (PropertyHolder) eResolveProxy(oldIdentifiedAs);
			if (identifiedAs != oldIdentifiedAs) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, PseimPackage.PATTERN_LINK__IDENTIFIED_AS,
							oldIdentifiedAs, identifiedAs));
			}
		}
		return identifiedAs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PropertyHolder basicGetIdentifiedAs() {
		return identifiedAs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setIdentifiedAs(PropertyHolder newIdentifiedAs) {
		PropertyHolder oldIdentifiedAs = identifiedAs;
		identifiedAs = newIdentifiedAs;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, PseimPackage.PATTERN_LINK__IDENTIFIED_AS,
					oldIdentifiedAs, identifiedAs));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getUid() {
		return uid;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isSetUid() {
		return uidESet;
	}

	/**
	 * <!-- 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, PseimPackage.PATTERN_LINK__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Property> getProperties() {
		if (properties == null) {
			properties = new EObjectContainmentEList<Property>(Property.class, this,
					PseimPackage.PATTERN_LINK__PROPERTIES);
		}
		return properties;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Port getSrc() {
		if (src != null && src.eIsProxy()) {
			InternalEObject oldSrc = (InternalEObject) src;
			src = (Port) eResolveProxy(oldSrc);
			if (src != oldSrc) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, PseimPackage.PATTERN_LINK__SRC, oldSrc,
							src));
			}
		}
		return src;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Port basicGetSrc() {
		return src;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setSrc(Port newSrc) {
		Port oldSrc = src;
		src = newSrc;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, PseimPackage.PATTERN_LINK__SRC, oldSrc, src));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Port getDst() {
		if (dst != null && dst.eIsProxy()) {
			InternalEObject oldDst = (InternalEObject) dst;
			dst = (Port) eResolveProxy(oldDst);
			if (dst != oldDst) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, PseimPackage.PATTERN_LINK__DST, oldDst,
							dst));
			}
		}
		return dst;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Port basicGetDst() {
		return dst;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDst(Port newDst) {
		Port oldDst = dst;
		dst = newDst;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, PseimPackage.PATTERN_LINK__DST, oldDst, dst));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public LinkType getLinkType() {
		return linkType;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setLinkType(LinkType newLinkType) {
		LinkType oldLinkType = linkType;
		linkType = newLinkType == null ? LINK_TYPE_EDEFAULT : newLinkType;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, PseimPackage.PATTERN_LINK__LINK_TYPE, oldLinkType,
					linkType));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public CardinalityElement getElement() {
		if (element != null && element.eIsProxy()) {
			InternalEObject oldElement = (InternalEObject) element;
			element = (CardinalityElement) eResolveProxy(oldElement);
			if (element != oldElement) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, PseimPackage.PATTERN_LINK__ELEMENT,
							oldElement, element));
			}
		}
		return element;
	}

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setElement(CardinalityElement newElement) {
		CardinalityElement oldElement = element;
		element = newElement;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, PseimPackage.PATTERN_LINK__ELEMENT, oldElement,
					element));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
		case PseimPackage.PATTERN_LINK__PROPERTIES:
			return ((InternalEList<?>) getProperties()).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 PseimPackage.PATTERN_LINK__IDENTIFIED_AS:
			if (resolve)
				return getIdentifiedAs();
			return basicGetIdentifiedAs();
		case PseimPackage.PATTERN_LINK__UID:
			return getUid();
		case PseimPackage.PATTERN_LINK__NAME:
			return getName();
		case PseimPackage.PATTERN_LINK__PROPERTIES:
			return getProperties();
		case PseimPackage.PATTERN_LINK__SRC:
			if (resolve)
				return getSrc();
			return basicGetSrc();
		case PseimPackage.PATTERN_LINK__DST:
			if (resolve)
				return getDst();
			return basicGetDst();
		case PseimPackage.PATTERN_LINK__LINK_TYPE:
			return getLinkType();
		case PseimPackage.PATTERN_LINK__ELEMENT:
			if (resolve)
				return getElement();
			return basicGetElement();
		}
		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 PseimPackage.PATTERN_LINK__IDENTIFIED_AS:
			setIdentifiedAs((PropertyHolder) newValue);
			return;
		case PseimPackage.PATTERN_LINK__NAME:
			setName((String) newValue);
			return;
		case PseimPackage.PATTERN_LINK__PROPERTIES:
			getProperties().clear();
			getProperties().addAll((Collection<? extends Property>) newValue);
			return;
		case PseimPackage.PATTERN_LINK__SRC:
			setSrc((Port) newValue);
			return;
		case PseimPackage.PATTERN_LINK__DST:
			setDst((Port) newValue);
			return;
		case PseimPackage.PATTERN_LINK__LINK_TYPE:
			setLinkType((LinkType) newValue);
			return;
		case PseimPackage.PATTERN_LINK__ELEMENT:
			setElement((CardinalityElement) newValue);
			return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
		case PseimPackage.PATTERN_LINK__IDENTIFIED_AS:
			setIdentifiedAs((PropertyHolder) null);
			return;
		case PseimPackage.PATTERN_LINK__NAME:
			setName(NAME_EDEFAULT);
			return;
		case PseimPackage.PATTERN_LINK__PROPERTIES:
			getProperties().clear();
			return;
		case PseimPackage.PATTERN_LINK__SRC:
			setSrc((Port) null);
			return;
		case PseimPackage.PATTERN_LINK__DST:
			setDst((Port) null);
			return;
		case PseimPackage.PATTERN_LINK__LINK_TYPE:
			setLinkType(LINK_TYPE_EDEFAULT);
			return;
		case PseimPackage.PATTERN_LINK__ELEMENT:
			setElement((CardinalityElement) null);
			return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
		case PseimPackage.PATTERN_LINK__IDENTIFIED_AS:
			return identifiedAs != null;
		case PseimPackage.PATTERN_LINK__UID:
			return isSetUid();
		case PseimPackage.PATTERN_LINK__NAME:
			return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
		case PseimPackage.PATTERN_LINK__PROPERTIES:
			return properties != null && !properties.isEmpty();
		case PseimPackage.PATTERN_LINK__SRC:
			return src != null;
		case PseimPackage.PATTERN_LINK__DST:
			return dst != null;
		case PseimPackage.PATTERN_LINK__LINK_TYPE:
			return linkType != LINK_TYPE_EDEFAULT;
		case PseimPackage.PATTERN_LINK__ELEMENT:
			return element != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public int eBaseStructuralFeatureID(int derivedFeatureID, Class<?> baseClass) {
		if (baseClass == IdentifiedElement.class) {
			switch (derivedFeatureID) {
			case PseimPackage.PATTERN_LINK__UID:
				return SeimPackage.IDENTIFIED_ELEMENT__UID;
			default:
				return -1;
			}
		}
		if (baseClass == NamedElement.class) {
			switch (derivedFeatureID) {
			case PseimPackage.PATTERN_LINK__NAME:
				return SeimPackage.NAMED_ELEMENT__NAME;
			default:
				return -1;
			}
		}
		if (baseClass == PropertyHolder.class) {
			switch (derivedFeatureID) {
			case PseimPackage.PATTERN_LINK__PROPERTIES:
				return SeimPackage.PROPERTY_HOLDER__PROPERTIES;
			default:
				return -1;
			}
		}
		if (baseClass == Element.class) {
			switch (derivedFeatureID) {
			default:
				return -1;
			}
		}
		if (baseClass == GraphElement.class) {
			switch (derivedFeatureID) {
			default:
				return -1;
			}
		}
		if (baseClass == Link.class) {
			switch (derivedFeatureID) {
			case PseimPackage.PATTERN_LINK__SRC:
				return SeimPackage.LINK__SRC;
			case PseimPackage.PATTERN_LINK__DST:
				return SeimPackage.LINK__DST;
			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 == IdentifiedElement.class) {
			switch (baseFeatureID) {
			case SeimPackage.IDENTIFIED_ELEMENT__UID:
				return PseimPackage.PATTERN_LINK__UID;
			default:
				return -1;
			}
		}
		if (baseClass == NamedElement.class) {
			switch (baseFeatureID) {
			case SeimPackage.NAMED_ELEMENT__NAME:
				return PseimPackage.PATTERN_LINK__NAME;
			default:
				return -1;
			}
		}
		if (baseClass == PropertyHolder.class) {
			switch (baseFeatureID) {
			case SeimPackage.PROPERTY_HOLDER__PROPERTIES:
				return PseimPackage.PATTERN_LINK__PROPERTIES;
			default:
				return -1;
			}
		}
		if (baseClass == Element.class) {
			switch (baseFeatureID) {
			default:
				return -1;
			}
		}
		if (baseClass == GraphElement.class) {
			switch (baseFeatureID) {
			default:
				return -1;
			}
		}
		if (baseClass == Link.class) {
			switch (baseFeatureID) {
			case SeimPackage.LINK__SRC:
				return PseimPackage.PATTERN_LINK__SRC;
			case SeimPackage.LINK__DST:
				return PseimPackage.PATTERN_LINK__DST;
			default:
				return -1;
			}
		}
		return super.eDerivedStructuralFeatureID(baseFeatureID, baseClass);
	}

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

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (uid: ");
		if (uidESet)
			result.append(uid);
		else
			result.append("<unset>");
		result.append(", name: ");
		result.append(name);
		result.append(", linkType: ");
		result.append(linkType);
		result.append(')');
		return result.toString();
	}

} //PatternLinkImpl
