| /** |
| * ******************************************************************************* |
| * Copyright (c) 2015-2021 Robert Bosch GmbH and others. |
| * |
| * This program and the accompanying materials are made |
| * available under the terms of the Eclipse Public License 2.0 |
| * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Generated using Eclipse EMF |
| * |
| * ******************************************************************************* |
| */ |
| package org.eclipse.app4mc.amalthea.model.impl; |
| |
| import com.google.common.base.Objects; |
| import java.lang.reflect.InvocationTargetException; |
| |
| import java.util.Map; |
| |
| import org.eclipse.app4mc.amalthea.model.AmaltheaPackage; |
| import org.eclipse.app4mc.amalthea.model.AmaltheaValidations; |
| import org.eclipse.app4mc.amalthea.model.EnumMode; |
| import org.eclipse.app4mc.amalthea.model.Mode; |
| import org.eclipse.app4mc.amalthea.model.ModeLabel; |
| import org.eclipse.app4mc.amalthea.model.ModeLiteral; |
| import org.eclipse.app4mc.amalthea.model.ModeValue; |
| import org.eclipse.app4mc.amalthea.model.NumericMode; |
| import org.eclipse.emf.common.notify.Notification; |
| |
| import org.eclipse.emf.common.util.DiagnosticChain; |
| 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.xtext.xbase.lib.Functions.Function1; |
| import org.eclipse.xtext.xbase.lib.IterableExtensions; |
| |
| /** |
| * <!-- begin-user-doc --> |
| * An implementation of the model object '<em><b>Mode Value</b></em>'. |
| * <!-- end-user-doc --> |
| * <p> |
| * The following features are implemented: |
| * </p> |
| * <ul> |
| * <li>{@link org.eclipse.app4mc.amalthea.model.impl.ModeValueImpl#getLabel <em>Label</em>}</li> |
| * <li>{@link org.eclipse.app4mc.amalthea.model.impl.ModeValueImpl#getValue <em>Value</em>}</li> |
| * </ul> |
| * |
| * @generated |
| */ |
| public abstract class ModeValueImpl extends BaseObjectImpl implements ModeValue { |
| /** |
| * The cached value of the '{@link #getLabel() <em>Label</em>}' reference. |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @see #getLabel() |
| * @generated |
| * @ordered |
| */ |
| protected ModeLabel label; |
| |
| /** |
| * The default value of the '{@link #getValue() <em>Value</em>}' attribute. |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @see #getValue() |
| * @generated |
| * @ordered |
| */ |
| protected static final String VALUE_EDEFAULT = null; |
| |
| /** |
| * The cached value of the '{@link #getValue() <em>Value</em>}' attribute. |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @see #getValue() |
| * @generated |
| * @ordered |
| */ |
| protected String value = VALUE_EDEFAULT; |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| protected ModeValueImpl() { |
| super(); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| protected EClass eStaticClass() { |
| return AmaltheaPackage.eINSTANCE.getModeValue(); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public ModeLabel getLabel() { |
| if (label != null && label.eIsProxy()) { |
| InternalEObject oldLabel = (InternalEObject)label; |
| label = (ModeLabel)eResolveProxy(oldLabel); |
| if (label != oldLabel) { |
| if (eNotificationRequired()) |
| eNotify(new ENotificationImpl(this, Notification.RESOLVE, AmaltheaPackage.MODE_VALUE__LABEL, oldLabel, label)); |
| } |
| } |
| return label; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public ModeLabel basicGetLabel() { |
| return label; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public void setLabel(ModeLabel newLabel) { |
| ModeLabel oldLabel = label; |
| label = newLabel; |
| if (eNotificationRequired()) |
| eNotify(new ENotificationImpl(this, Notification.SET, AmaltheaPackage.MODE_VALUE__LABEL, oldLabel, label)); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public String getValue() { |
| return value; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public void setValue(String newValue) { |
| String oldValue = value; |
| value = newValue; |
| if (eNotificationRequired()) |
| eNotify(new ENotificationImpl(this, Notification.SET, AmaltheaPackage.MODE_VALUE__VALUE, oldValue, value)); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public boolean validateInvariants(final DiagnosticChain diagnostics, final Map<Object, Object> context) { |
| return AmaltheaValidations.validateInvariants(this, diagnostics); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public ModeLiteral getLiteral() { |
| ModeLiteral _xblockexpression = null; { |
| String _value = this.getValue(); |
| boolean _tripleEquals = (_value == null); |
| if (_tripleEquals) { |
| return null; |
| } |
| ModeLabel _label = this.getLabel(); |
| Mode _mode = null; |
| if (_label!=null) { |
| _mode=_label.getMode(); |
| } |
| final Mode mode = _mode; |
| ModeLiteral _xifexpression = null; |
| if ((mode instanceof EnumMode)) { |
| final Function1<ModeLiteral, Boolean> _function = new Function1<ModeLiteral, Boolean>() { |
| public Boolean apply(final ModeLiteral it) { |
| String _name = it.getName(); |
| String _value = ModeValueImpl.this.getValue(); |
| return Boolean.valueOf(Objects.equal(_name, _value)); |
| } |
| }; |
| _xifexpression = IterableExtensions.<ModeLiteral>findFirst(((EnumMode)mode).getLiterals(), _function); |
| } |
| else { |
| _xifexpression = null; |
| } |
| _xblockexpression = _xifexpression; |
| } |
| return _xblockexpression; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public Integer getInteger() { |
| Integer _xblockexpression = null; { |
| String _value = this.getValue(); |
| boolean _tripleEquals = (_value == null); |
| if (_tripleEquals) { |
| return null; |
| } |
| ModeLabel _label = this.getLabel(); |
| Mode _mode = null; |
| if (_label!=null) { |
| _mode=_label.getMode(); |
| } |
| final Mode mode = _mode; |
| Integer _xifexpression = null; |
| if (((mode instanceof NumericMode) && this.getValue().matches("-?\\d+"))) { |
| _xifexpression = Integer.valueOf(Integer.parseInt(this.getValue())); |
| } |
| else { |
| _xifexpression = null; |
| } |
| _xblockexpression = _xifexpression; |
| } |
| return _xblockexpression; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public Object eGet(int featureID, boolean resolve, boolean coreType) { |
| switch (featureID) { |
| case AmaltheaPackage.MODE_VALUE__LABEL: |
| if (resolve) return getLabel(); |
| return basicGetLabel(); |
| case AmaltheaPackage.MODE_VALUE__VALUE: |
| return getValue(); |
| } |
| return super.eGet(featureID, resolve, coreType); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public void eSet(int featureID, Object newValue) { |
| switch (featureID) { |
| case AmaltheaPackage.MODE_VALUE__LABEL: |
| setLabel((ModeLabel)newValue); |
| return; |
| case AmaltheaPackage.MODE_VALUE__VALUE: |
| setValue((String)newValue); |
| return; |
| } |
| super.eSet(featureID, newValue); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public void eUnset(int featureID) { |
| switch (featureID) { |
| case AmaltheaPackage.MODE_VALUE__LABEL: |
| setLabel((ModeLabel)null); |
| return; |
| case AmaltheaPackage.MODE_VALUE__VALUE: |
| setValue(VALUE_EDEFAULT); |
| return; |
| } |
| super.eUnset(featureID); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public boolean eIsSet(int featureID) { |
| switch (featureID) { |
| case AmaltheaPackage.MODE_VALUE__LABEL: |
| return label != null; |
| case AmaltheaPackage.MODE_VALUE__VALUE: |
| return VALUE_EDEFAULT == null ? value != null : !VALUE_EDEFAULT.equals(value); |
| } |
| return super.eIsSet(featureID); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| @SuppressWarnings("unchecked") |
| public Object eInvoke(int operationID, EList<?> arguments) throws InvocationTargetException { |
| switch (operationID) { |
| case AmaltheaPackage.MODE_VALUE___VALIDATE_INVARIANTS__DIAGNOSTICCHAIN_MAP: |
| return validateInvariants((DiagnosticChain)arguments.get(0), (Map<Object, Object>)arguments.get(1)); |
| case AmaltheaPackage.MODE_VALUE___GET_LITERAL: |
| return getLiteral(); |
| case AmaltheaPackage.MODE_VALUE___GET_INTEGER: |
| return getInteger(); |
| } |
| return super.eInvoke(operationID, arguments); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public String toString() { |
| if (eIsProxy()) return super.toString(); |
| |
| StringBuilder result = new StringBuilder(super.toString()); |
| result.append(" (value: "); |
| result.append(value); |
| result.append(')'); |
| return result.toString(); |
| } |
| |
| } //ModeValueImpl |