blob: 84842445ba0422b05854a0915e38b43975674c4f [file] [log] [blame]
/**
* *******************************************************************************
* 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.math.BigInteger;
import org.eclipse.app4mc.amalthea.model.AmaltheaPackage;
import org.eclipse.app4mc.amalthea.model.AmaltheaServices;
import org.eclipse.app4mc.amalthea.model.DataSize;
import org.eclipse.app4mc.amalthea.model.DataSizeUnit;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
/**
* <!-- begin-user-doc -->
* An implementation of the model object '<em><b>Data Size</b></em>'.
* <!-- end-user-doc -->
* <p>
* The following features are implemented:
* </p>
* <ul>
* <li>{@link org.eclipse.app4mc.amalthea.model.impl.DataSizeImpl#getValue <em>Value</em>}</li>
* <li>{@link org.eclipse.app4mc.amalthea.model.impl.DataSizeImpl#getUnit <em>Unit</em>}</li>
* </ul>
*
* @generated
*/
public class DataSizeImpl extends QuantityImpl implements DataSize {
/**
* The default value of the '{@link #getValue() <em>Value</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getValue()
* @generated
* @ordered
*/
protected static final BigInteger VALUE_EDEFAULT = new BigInteger("0");
/**
* The cached value of the '{@link #getValue() <em>Value</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getValue()
* @generated
* @ordered
*/
protected BigInteger value = VALUE_EDEFAULT;
/**
* The default value of the '{@link #getUnit() <em>Unit</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getUnit()
* @generated
* @ordered
*/
protected static final DataSizeUnit UNIT_EDEFAULT = DataSizeUnit._UNDEFINED_;
/**
* The cached value of the '{@link #getUnit() <em>Unit</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getUnit()
* @generated
* @ordered
*/
protected DataSizeUnit unit = UNIT_EDEFAULT;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected DataSizeImpl() {
super();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected EClass eStaticClass() {
return AmaltheaPackage.eINSTANCE.getDataSize();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public BigInteger getValue() {
return value;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void setValue(BigInteger newValue) {
BigInteger oldValue = value;
value = newValue;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, AmaltheaPackage.DATA_SIZE__VALUE, oldValue, value));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public DataSizeUnit getUnit() {
return unit;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void setUnit(DataSizeUnit newUnit) {
DataSizeUnit oldUnit = unit;
unit = newUnit == null ? UNIT_EDEFAULT : newUnit;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, AmaltheaPackage.DATA_SIZE__UNIT, oldUnit, unit));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public String toString() {
BigInteger _value = this.getValue();
String _plus = (_value + " ");
String _xifexpression = null;
DataSizeUnit _unit = this.getUnit();
boolean _equals = Objects.equal(_unit, DataSizeUnit._UNDEFINED_);
if (_equals) {
_xifexpression = "<unit>";
}
else {
_xifexpression = this.getUnit().getLiteral();
}
return (_plus + _xifexpression);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public long getNumberBits() {
long _xblockexpression = (long) 0; {
DataSizeUnit _unit = this.getUnit();
boolean _tripleEquals = (_unit == DataSizeUnit.BIT);
if (_tripleEquals) {
return this.getValue().longValue();
}
final BigInteger bits = AmaltheaServices.convertToBit(this);
long _xifexpression = (long) 0;
if ((bits == null)) {
_xifexpression = (-1L);
}
else {
_xifexpression = bits.longValue();
}
_xblockexpression = _xifexpression;
}
return _xblockexpression;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public long getNumberBytes() {
long _xblockexpression = (long) 0; {
DataSizeUnit _unit = this.getUnit();
boolean _tripleEquals = (_unit == DataSizeUnit.B);
if (_tripleEquals) {
return this.getValue().longValue();
}
final BigInteger bits = AmaltheaServices.convertToBit(this);
long _xifexpression = (long) 0;
if ((bits == null)) {
_xifexpression = (-1L);
}
else {
long _longValue = bits.longValue();
long _divide = (_longValue / 8);
_xifexpression = Double.valueOf(Math.ceil(_divide)).longValue();
}
_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.DATA_SIZE__VALUE:
return getValue();
case AmaltheaPackage.DATA_SIZE__UNIT:
return getUnit();
}
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.DATA_SIZE__VALUE:
setValue((BigInteger)newValue);
return;
case AmaltheaPackage.DATA_SIZE__UNIT:
setUnit((DataSizeUnit)newValue);
return;
}
super.eSet(featureID, newValue);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID) {
switch (featureID) {
case AmaltheaPackage.DATA_SIZE__VALUE:
setValue(VALUE_EDEFAULT);
return;
case AmaltheaPackage.DATA_SIZE__UNIT:
setUnit(UNIT_EDEFAULT);
return;
}
super.eUnset(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean eIsSet(int featureID) {
switch (featureID) {
case AmaltheaPackage.DATA_SIZE__VALUE:
return VALUE_EDEFAULT == null ? value != null : !VALUE_EDEFAULT.equals(value);
case AmaltheaPackage.DATA_SIZE__UNIT:
return unit != UNIT_EDEFAULT;
}
return super.eIsSet(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Object eInvoke(int operationID, EList<?> arguments) throws InvocationTargetException {
switch (operationID) {
case AmaltheaPackage.DATA_SIZE___TO_STRING:
return toString();
case AmaltheaPackage.DATA_SIZE___GET_NUMBER_BITS:
return getNumberBits();
case AmaltheaPackage.DATA_SIZE___GET_NUMBER_BYTES:
return getNumberBytes();
}
return super.eInvoke(operationID, arguments);
}
} //DataSizeImpl