/*******************************************************************************
 * 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.Pattern;
import com.irtsaintexupery.pseim.pseim.PatternTypeFailureMode;
import com.irtsaintexupery.pseim.pseim.PatternTypeHS;
import com.irtsaintexupery.pseim.pseim.PseimPackage;
import com.irtsaintexupery.pseim.pseim.SafetyTactic;

import com.irtsaintexupery.pseim.seim.PropertyHolder;

import com.irtsaintexupery.pseim.seim.impl.ModelImpl;

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.util.EDataTypeUniqueEList;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Pattern</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * </p>
 * <ul>
 *   <li>{@link com.irtsaintexupery.pseim.pseim.impl.PatternImpl#getTypeHS <em>Type HS</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.pseim.impl.PatternImpl#getTypeFailure <em>Type Failure</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.pseim.impl.PatternImpl#getAlsoKnownAs <em>Also Known As</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.pseim.impl.PatternImpl#getUsedTactics <em>Used Tactics</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.pseim.impl.PatternImpl#getContext <em>Context</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.pseim.impl.PatternImpl#getDomain <em>Domain</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.pseim.impl.PatternImpl#isIsSingleChannel <em>Is Single Channel</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.pseim.impl.PatternImpl#getInterfaceElements <em>Interface Elements</em>}</li>
 *   <li>{@link com.irtsaintexupery.pseim.pseim.impl.PatternImpl#getCardinalityElements <em>Cardinality Elements</em>}</li>
 * </ul>
 *
 * @generated
 */
public class PatternImpl extends ModelImpl implements Pattern {
	/**
	 * The cached value of the '{@link #getTypeHS() <em>Type HS</em>}' attribute list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTypeHS()
	 * @generated
	 * @ordered
	 */
	protected EList<PatternTypeHS> typeHS;

	/**
	 * The default value of the '{@link #getTypeFailure() <em>Type Failure</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTypeFailure()
	 * @generated
	 * @ordered
	 */
	protected static final PatternTypeFailureMode TYPE_FAILURE_EDEFAULT = PatternTypeFailureMode.FAIL_SAFE;

	/**
	 * The cached value of the '{@link #getTypeFailure() <em>Type Failure</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTypeFailure()
	 * @generated
	 * @ordered
	 */
	protected PatternTypeFailureMode typeFailure = TYPE_FAILURE_EDEFAULT;

	/**
	 * The cached value of the '{@link #getAlsoKnownAs() <em>Also Known As</em>}' attribute list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAlsoKnownAs()
	 * @generated
	 * @ordered
	 */
	protected EList<String> alsoKnownAs;

	/**
	 * The cached value of the '{@link #getUsedTactics() <em>Used Tactics</em>}' attribute list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getUsedTactics()
	 * @generated
	 * @ordered
	 */
	protected EList<SafetyTactic> usedTactics;

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

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

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

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

	/**
	 * The default value of the '{@link #isIsSingleChannel() <em>Is Single Channel</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isIsSingleChannel()
	 * @generated
	 * @ordered
	 */
	protected static final boolean IS_SINGLE_CHANNEL_EDEFAULT = false;

	/**
	 * The cached value of the '{@link #isIsSingleChannel() <em>Is Single Channel</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isIsSingleChannel()
	 * @generated
	 * @ordered
	 */
	protected boolean isSingleChannel = IS_SINGLE_CHANNEL_EDEFAULT;

	/**
	 * The cached value of the '{@link #getInterfaceElements() <em>Interface Elements</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getInterfaceElements()
	 * @generated
	 * @ordered
	 */
	protected EList<PropertyHolder> interfaceElements;

	/**
	 * The cached value of the '{@link #getCardinalityElements() <em>Cardinality Elements</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCardinalityElements()
	 * @generated
	 * @ordered
	 */
	protected EList<CardinalityElement> cardinalityElements;

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

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<PatternTypeHS> getTypeHS() {
		if (typeHS == null) {
			typeHS = new EDataTypeUniqueEList<PatternTypeHS>(PatternTypeHS.class, this, PseimPackage.PATTERN__TYPE_HS);
		}
		return typeHS;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PatternTypeFailureMode getTypeFailure() {
		return typeFailure;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTypeFailure(PatternTypeFailureMode newTypeFailure) {
		PatternTypeFailureMode oldTypeFailure = typeFailure;
		typeFailure = newTypeFailure == null ? TYPE_FAILURE_EDEFAULT : newTypeFailure;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, PseimPackage.PATTERN__TYPE_FAILURE, oldTypeFailure,
					typeFailure));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<String> getAlsoKnownAs() {
		if (alsoKnownAs == null) {
			alsoKnownAs = new EDataTypeUniqueEList<String>(String.class, this, PseimPackage.PATTERN__ALSO_KNOWN_AS);
		}
		return alsoKnownAs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<SafetyTactic> getUsedTactics() {
		if (usedTactics == null) {
			usedTactics = new EDataTypeUniqueEList<SafetyTactic>(SafetyTactic.class, this,
					PseimPackage.PATTERN__USED_TACTICS);
		}
		return usedTactics;
	}

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setContext(String newContext) {
		String oldContext = context;
		context = newContext;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, PseimPackage.PATTERN__CONTEXT, oldContext, context));
	}

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDomain(String newDomain) {
		String oldDomain = domain;
		domain = newDomain;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, PseimPackage.PATTERN__DOMAIN, oldDomain, domain));
	}

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

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setIsSingleChannel(boolean newIsSingleChannel) {
		boolean oldIsSingleChannel = isSingleChannel;
		isSingleChannel = newIsSingleChannel;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, PseimPackage.PATTERN__IS_SINGLE_CHANNEL,
					oldIsSingleChannel, isSingleChannel));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<PropertyHolder> getInterfaceElements() {
		if (interfaceElements == null) {
			interfaceElements = new EObjectResolvingEList<PropertyHolder>(PropertyHolder.class, this,
					PseimPackage.PATTERN__INTERFACE_ELEMENTS);
		}
		return interfaceElements;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<CardinalityElement> getCardinalityElements() {
		if (cardinalityElements == null) {
			cardinalityElements = new EObjectContainmentEList<CardinalityElement>(CardinalityElement.class, this,
					PseimPackage.PATTERN__CARDINALITY_ELEMENTS);
		}
		return cardinalityElements;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
		case PseimPackage.PATTERN__CARDINALITY_ELEMENTS:
			return ((InternalEList<?>) getCardinalityElements()).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__TYPE_HS:
			return getTypeHS();
		case PseimPackage.PATTERN__TYPE_FAILURE:
			return getTypeFailure();
		case PseimPackage.PATTERN__ALSO_KNOWN_AS:
			return getAlsoKnownAs();
		case PseimPackage.PATTERN__USED_TACTICS:
			return getUsedTactics();
		case PseimPackage.PATTERN__CONTEXT:
			return getContext();
		case PseimPackage.PATTERN__DOMAIN:
			return getDomain();
		case PseimPackage.PATTERN__IS_SINGLE_CHANNEL:
			return isIsSingleChannel();
		case PseimPackage.PATTERN__INTERFACE_ELEMENTS:
			return getInterfaceElements();
		case PseimPackage.PATTERN__CARDINALITY_ELEMENTS:
			return getCardinalityElements();
		}
		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__TYPE_HS:
			getTypeHS().clear();
			getTypeHS().addAll((Collection<? extends PatternTypeHS>) newValue);
			return;
		case PseimPackage.PATTERN__TYPE_FAILURE:
			setTypeFailure((PatternTypeFailureMode) newValue);
			return;
		case PseimPackage.PATTERN__ALSO_KNOWN_AS:
			getAlsoKnownAs().clear();
			getAlsoKnownAs().addAll((Collection<? extends String>) newValue);
			return;
		case PseimPackage.PATTERN__USED_TACTICS:
			getUsedTactics().clear();
			getUsedTactics().addAll((Collection<? extends SafetyTactic>) newValue);
			return;
		case PseimPackage.PATTERN__CONTEXT:
			setContext((String) newValue);
			return;
		case PseimPackage.PATTERN__DOMAIN:
			setDomain((String) newValue);
			return;
		case PseimPackage.PATTERN__IS_SINGLE_CHANNEL:
			setIsSingleChannel((Boolean) newValue);
			return;
		case PseimPackage.PATTERN__INTERFACE_ELEMENTS:
			getInterfaceElements().clear();
			getInterfaceElements().addAll((Collection<? extends PropertyHolder>) newValue);
			return;
		case PseimPackage.PATTERN__CARDINALITY_ELEMENTS:
			getCardinalityElements().clear();
			getCardinalityElements().addAll((Collection<? extends 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__TYPE_HS:
			getTypeHS().clear();
			return;
		case PseimPackage.PATTERN__TYPE_FAILURE:
			setTypeFailure(TYPE_FAILURE_EDEFAULT);
			return;
		case PseimPackage.PATTERN__ALSO_KNOWN_AS:
			getAlsoKnownAs().clear();
			return;
		case PseimPackage.PATTERN__USED_TACTICS:
			getUsedTactics().clear();
			return;
		case PseimPackage.PATTERN__CONTEXT:
			setContext(CONTEXT_EDEFAULT);
			return;
		case PseimPackage.PATTERN__DOMAIN:
			setDomain(DOMAIN_EDEFAULT);
			return;
		case PseimPackage.PATTERN__IS_SINGLE_CHANNEL:
			setIsSingleChannel(IS_SINGLE_CHANNEL_EDEFAULT);
			return;
		case PseimPackage.PATTERN__INTERFACE_ELEMENTS:
			getInterfaceElements().clear();
			return;
		case PseimPackage.PATTERN__CARDINALITY_ELEMENTS:
			getCardinalityElements().clear();
			return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
		case PseimPackage.PATTERN__TYPE_HS:
			return typeHS != null && !typeHS.isEmpty();
		case PseimPackage.PATTERN__TYPE_FAILURE:
			return typeFailure != TYPE_FAILURE_EDEFAULT;
		case PseimPackage.PATTERN__ALSO_KNOWN_AS:
			return alsoKnownAs != null && !alsoKnownAs.isEmpty();
		case PseimPackage.PATTERN__USED_TACTICS:
			return usedTactics != null && !usedTactics.isEmpty();
		case PseimPackage.PATTERN__CONTEXT:
			return CONTEXT_EDEFAULT == null ? context != null : !CONTEXT_EDEFAULT.equals(context);
		case PseimPackage.PATTERN__DOMAIN:
			return DOMAIN_EDEFAULT == null ? domain != null : !DOMAIN_EDEFAULT.equals(domain);
		case PseimPackage.PATTERN__IS_SINGLE_CHANNEL:
			return isSingleChannel != IS_SINGLE_CHANNEL_EDEFAULT;
		case PseimPackage.PATTERN__INTERFACE_ELEMENTS:
			return interfaceElements != null && !interfaceElements.isEmpty();
		case PseimPackage.PATTERN__CARDINALITY_ELEMENTS:
			return cardinalityElements != null && !cardinalityElements.isEmpty();
		}
		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(" (typeHS: ");
		result.append(typeHS);
		result.append(", typeFailure: ");
		result.append(typeFailure);
		result.append(", alsoKnownAs: ");
		result.append(alsoKnownAs);
		result.append(", usedTactics: ");
		result.append(usedTactics);
		result.append(", context: ");
		result.append(context);
		result.append(", domain: ");
		result.append(domain);
		result.append(", isSingleChannel: ");
		result.append(isSingleChannel);
		result.append(')');
		return result.toString();
	}

} //PatternImpl
