/*******************************************************************************
 * 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.IdentifiedElement;
import com.irtsaintexupery.pseim.pseim.PatternPort;
import com.irtsaintexupery.pseim.pseim.PatternPortDirection;
import com.irtsaintexupery.pseim.pseim.PseimPackage;

import com.irtsaintexupery.pseim.seim.BorderElement;
import com.irtsaintexupery.pseim.seim.Element;
import com.irtsaintexupery.pseim.seim.NamedElement;
import com.irtsaintexupery.pseim.seim.Port;
import com.irtsaintexupery.pseim.seim.PortDirection;
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 Port</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link com.irtsaintexupery.pseim.pseim.impl.PatternPortImpl#getMultiplicityValue <em>Multiplicity Value</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.pseim.impl.PatternPortImpl#getCardinalityElement <em>Cardinality Element</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.pseim.impl.PatternPortImpl#getIdentifiedAs <em>Identified As</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.pseim.impl.PatternPortImpl#getUid <em>Uid</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.pseim.impl.PatternPortImpl#getName <em>Name</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.pseim.impl.PatternPortImpl#getProperties <em>Properties</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.pseim.impl.PatternPortImpl#getDirection <em>Direction</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.pseim.impl.PatternPortImpl#getDir <em>Dir</em>}</li>
 * </ul>
 *
 * @generated
 */
public class PatternPortImpl extends MinimalEObjectImpl.Container implements PatternPort {
	/**
	 * The default value of the '{@link #getMultiplicityValue() <em>Multiplicity Value</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMultiplicityValue()
	 * @generated
	 * @ordered
	 */
	protected static final int MULTIPLICITY_VALUE_EDEFAULT = 1;

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

	/**
	 * 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 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 default value of the '{@link #getDirection() <em>Direction</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDirection()
	 * @generated
	 * @ordered
	 */
	protected static final PortDirection DIRECTION_EDEFAULT = PortDirection.UNSPECIFIED;

	/**
	 * The cached value of the '{@link #getDirection() <em>Direction</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDirection()
	 * @generated
	 * @ordered
	 */
	protected PortDirection direction = DIRECTION_EDEFAULT;

	/**
	 * The default value of the '{@link #getDir() <em>Dir</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDir()
	 * @generated
	 * @ordered
	 */
	protected static final PatternPortDirection DIR_EDEFAULT = PatternPortDirection.UNSPECIFIED;

	/**
	 * The cached value of the '{@link #getDir() <em>Dir</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDir()
	 * @generated
	 * @ordered
	 */
	protected PatternPortDirection dir = DIR_EDEFAULT;

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

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMultiplicityValue(int newMultiplicityValue) {
		int oldMultiplicityValue = multiplicityValue;
		multiplicityValue = newMultiplicityValue;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, PseimPackage.PATTERN_PORT__MULTIPLICITY_VALUE,
					oldMultiplicityValue, multiplicityValue));
	}

	/**
	 * <!-- 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,
							PseimPackage.PATTERN_PORT__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, PseimPackage.PATTERN_PORT__CARDINALITY_ELEMENT,
					oldCardinalityElement, cardinalityElement));
	}

	/**
	 * <!-- 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_PORT__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_PORT__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_PORT__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_PORT__PROPERTIES);
		}
		return properties;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PortDirection getDirection() {
		return direction;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDirection(PortDirection newDirection) {
		PortDirection oldDirection = direction;
		direction = newDirection == null ? DIRECTION_EDEFAULT : newDirection;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, PseimPackage.PATTERN_PORT__DIRECTION, oldDirection,
					direction));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PatternPortDirection getDir() {
		return dir;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDir(PatternPortDirection newDir) {
		PatternPortDirection oldDir = dir;
		dir = newDir == null ? DIR_EDEFAULT : newDir;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, PseimPackage.PATTERN_PORT__DIR, oldDir, dir));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
		case PseimPackage.PATTERN_PORT__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_PORT__MULTIPLICITY_VALUE:
			return getMultiplicityValue();
		case PseimPackage.PATTERN_PORT__CARDINALITY_ELEMENT:
			if (resolve)
				return getCardinalityElement();
			return basicGetCardinalityElement();
		case PseimPackage.PATTERN_PORT__IDENTIFIED_AS:
			if (resolve)
				return getIdentifiedAs();
			return basicGetIdentifiedAs();
		case PseimPackage.PATTERN_PORT__UID:
			return getUid();
		case PseimPackage.PATTERN_PORT__NAME:
			return getName();
		case PseimPackage.PATTERN_PORT__PROPERTIES:
			return getProperties();
		case PseimPackage.PATTERN_PORT__DIRECTION:
			return getDirection();
		case PseimPackage.PATTERN_PORT__DIR:
			return getDir();
		}
		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_PORT__MULTIPLICITY_VALUE:
			setMultiplicityValue((Integer) newValue);
			return;
		case PseimPackage.PATTERN_PORT__CARDINALITY_ELEMENT:
			setCardinalityElement((CardinalityElement) newValue);
			return;
		case PseimPackage.PATTERN_PORT__IDENTIFIED_AS:
			setIdentifiedAs((PropertyHolder) newValue);
			return;
		case PseimPackage.PATTERN_PORT__NAME:
			setName((String) newValue);
			return;
		case PseimPackage.PATTERN_PORT__PROPERTIES:
			getProperties().clear();
			getProperties().addAll((Collection<? extends Property>) newValue);
			return;
		case PseimPackage.PATTERN_PORT__DIRECTION:
			setDirection((PortDirection) newValue);
			return;
		case PseimPackage.PATTERN_PORT__DIR:
			setDir((PatternPortDirection) newValue);
			return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
		case PseimPackage.PATTERN_PORT__MULTIPLICITY_VALUE:
			setMultiplicityValue(MULTIPLICITY_VALUE_EDEFAULT);
			return;
		case PseimPackage.PATTERN_PORT__CARDINALITY_ELEMENT:
			setCardinalityElement((CardinalityElement) null);
			return;
		case PseimPackage.PATTERN_PORT__IDENTIFIED_AS:
			setIdentifiedAs((PropertyHolder) null);
			return;
		case PseimPackage.PATTERN_PORT__NAME:
			setName(NAME_EDEFAULT);
			return;
		case PseimPackage.PATTERN_PORT__PROPERTIES:
			getProperties().clear();
			return;
		case PseimPackage.PATTERN_PORT__DIRECTION:
			setDirection(DIRECTION_EDEFAULT);
			return;
		case PseimPackage.PATTERN_PORT__DIR:
			setDir(DIR_EDEFAULT);
			return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
		case PseimPackage.PATTERN_PORT__MULTIPLICITY_VALUE:
			return multiplicityValue != MULTIPLICITY_VALUE_EDEFAULT;
		case PseimPackage.PATTERN_PORT__CARDINALITY_ELEMENT:
			return cardinalityElement != null;
		case PseimPackage.PATTERN_PORT__IDENTIFIED_AS:
			return identifiedAs != null;
		case PseimPackage.PATTERN_PORT__UID:
			return isSetUid();
		case PseimPackage.PATTERN_PORT__NAME:
			return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
		case PseimPackage.PATTERN_PORT__PROPERTIES:
			return properties != null && !properties.isEmpty();
		case PseimPackage.PATTERN_PORT__DIRECTION:
			return direction != DIRECTION_EDEFAULT;
		case PseimPackage.PATTERN_PORT__DIR:
			return dir != DIR_EDEFAULT;
		}
		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_PORT__IDENTIFIED_AS:
				return PseimPackage.IDENTIFIED_ELEMENT__IDENTIFIED_AS;
			default:
				return -1;
			}
		}
		if (baseClass == com.irtsaintexupery.pseim.seim.IdentifiedElement.class) {
			switch (derivedFeatureID) {
			case PseimPackage.PATTERN_PORT__UID:
				return SeimPackage.IDENTIFIED_ELEMENT__UID;
			default:
				return -1;
			}
		}
		if (baseClass == NamedElement.class) {
			switch (derivedFeatureID) {
			case PseimPackage.PATTERN_PORT__NAME:
				return SeimPackage.NAMED_ELEMENT__NAME;
			default:
				return -1;
			}
		}
		if (baseClass == PropertyHolder.class) {
			switch (derivedFeatureID) {
			case PseimPackage.PATTERN_PORT__PROPERTIES:
				return SeimPackage.PROPERTY_HOLDER__PROPERTIES;
			default:
				return -1;
			}
		}
		if (baseClass == Element.class) {
			switch (derivedFeatureID) {
			default:
				return -1;
			}
		}
		if (baseClass == BorderElement.class) {
			switch (derivedFeatureID) {
			default:
				return -1;
			}
		}
		if (baseClass == Port.class) {
			switch (derivedFeatureID) {
			case PseimPackage.PATTERN_PORT__DIRECTION:
				return SeimPackage.PORT__DIRECTION;
			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 PseimPackage.IDENTIFIED_ELEMENT__IDENTIFIED_AS:
				return PseimPackage.PATTERN_PORT__IDENTIFIED_AS;
			default:
				return -1;
			}
		}
		if (baseClass == com.irtsaintexupery.pseim.seim.IdentifiedElement.class) {
			switch (baseFeatureID) {
			case SeimPackage.IDENTIFIED_ELEMENT__UID:
				return PseimPackage.PATTERN_PORT__UID;
			default:
				return -1;
			}
		}
		if (baseClass == NamedElement.class) {
			switch (baseFeatureID) {
			case SeimPackage.NAMED_ELEMENT__NAME:
				return PseimPackage.PATTERN_PORT__NAME;
			default:
				return -1;
			}
		}
		if (baseClass == PropertyHolder.class) {
			switch (baseFeatureID) {
			case SeimPackage.PROPERTY_HOLDER__PROPERTIES:
				return PseimPackage.PATTERN_PORT__PROPERTIES;
			default:
				return -1;
			}
		}
		if (baseClass == Element.class) {
			switch (baseFeatureID) {
			default:
				return -1;
			}
		}
		if (baseClass == BorderElement.class) {
			switch (baseFeatureID) {
			default:
				return -1;
			}
		}
		if (baseClass == Port.class) {
			switch (baseFeatureID) {
			case SeimPackage.PORT__DIRECTION:
				return PseimPackage.PATTERN_PORT__DIRECTION;
			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(" (multiplicityValue: ");
		result.append(multiplicityValue);
		result.append(", uid: ");
		if (uidESet)
			result.append(uid);
		else
			result.append("<unset>");
		result.append(", name: ");
		result.append(name);
		result.append(", direction: ");
		result.append(direction);
		result.append(", dir: ");
		result.append(dir);
		result.append(')');
		return result.toString();
	}

} //PatternPortImpl
