| package org.eclipse.stem.diseasemodels.standard.impl; |
| |
| /******************************************************************************* |
| * Copyright (c) 2006 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| *******************************************************************************/ |
| |
| import java.util.Collection; |
| import java.util.Map; |
| import java.util.TreeMap; |
| |
| import org.eclipse.emf.common.util.BasicEList; |
| import org.eclipse.emf.common.util.EList; |
| import org.eclipse.emf.ecore.EAttribute; |
| import org.eclipse.emf.ecore.EClass; |
| import org.eclipse.stem.core.graph.impl.IntegrationLabelValueImpl; |
| import org.eclipse.emf.ecore.util.EObjectResolvingEList; |
| import org.eclipse.stem.core.graph.Exchange; |
| import org.eclipse.stem.core.graph.IntegrationLabelValue; |
| import org.eclipse.stem.core.graph.LabelValue; |
| import org.eclipse.stem.core.graph.Node; |
| import org.eclipse.stem.core.graph.impl.LabelValueImpl; |
| import org.eclipse.stem.diseasemodels.standard.DiseaseModelLabelValue; |
| import org.eclipse.stem.diseasemodels.standard.StandardDiseaseModelLabelValue; |
| import org.eclipse.stem.diseasemodels.standard.StandardPackage; |
| |
| /** |
| * <!-- begin-user-doc --> An implementation of the model object ' |
| * <em><b>Disease Model Label Value</b></em>'. <!-- end-user-doc --> |
| * <p> |
| * The following features are implemented: |
| * <ul> |
| * <li>{@link org.eclipse.stem.diseasemodels.standard.impl.DiseaseModelLabelValueImpl#getPopulationCount <em>Population Count</em>}</li> |
| * </ul> |
| * </p> |
| * |
| * @generated |
| */ |
| public abstract class DiseaseModelLabelValueImpl extends IntegrationLabelValueImpl |
| implements DiseaseModelLabelValue { |
| public static final double ABS_TOLERANCE = 1E-12; // fix hardcoded? |
| |
| /** |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * @generated |
| */ |
| protected DiseaseModelLabelValueImpl() { |
| super(); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| protected EClass eStaticClass() { |
| return StandardPackage.Literals.DISEASE_MODEL_LABEL_VALUE; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @generated NOT |
| */ |
| public double getPopulationCount() { |
| EList<EAttribute> attributes = eClass().getEAllAttributes(); |
| double count = 0.0; |
| |
| for (EAttribute attribute : attributes) { |
| if (attribute.isChangeable() |
| && !attribute.getName().startsWith("incidence") |
| && !attribute.getName().startsWith("diseaseDeaths")) { |
| count += (Double) eGet(attribute); |
| } |
| } |
| |
| return count; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @generated NOT |
| */ |
| public IntegrationLabelValue set(IntegrationLabelValue value) { |
| EList<EAttribute> attributes = eClass().getEAllAttributes(); |
| |
| for (EAttribute attribute : attributes) { |
| if (attribute.isChangeable()) { |
| eSet(attribute, value.eGet(attribute)); |
| } |
| } |
| |
| return this; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @generated NOT |
| */ |
| public IntegrationLabelValue add(IntegrationLabelValue value) { |
| EList<EAttribute> attributes = eClass().getEAllAttributes(); |
| |
| for (EAttribute attribute : attributes) { |
| if (attribute.isChangeable()) { |
| eSet(attribute, |
| (Double) eGet(attribute) |
| + (Double) value.eGet(attribute)); |
| } |
| } |
| |
| return this; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @generated NOT |
| */ |
| public IntegrationLabelValue sub(IntegrationLabelValue value) { |
| EList<EAttribute> attributes = eClass().getEAllAttributes(); |
| |
| for (EAttribute attribute : attributes) { |
| if (attribute.isChangeable()) { |
| eSet(attribute, |
| (Double) eGet(attribute) |
| - (Double) value.eGet(attribute)); |
| } |
| } |
| |
| return this; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @generated NOT |
| */ |
| public IntegrationLabelValue scale(double scaleFactor) { |
| EList<EAttribute> attributes = eClass().getEAllAttributes(); |
| |
| for (EAttribute attribute : attributes) { |
| if (attribute.isChangeable()) { |
| eSet(attribute, scaleFactor * (Double) eGet(attribute)); |
| } |
| } |
| |
| return this; |
| } |
| |
| /** |
| * The default value of the '{@link #getPopulationCount() <em>Population Count</em>}' attribute. |
| * <!-- begin-user-doc --> <!-- |
| * end-user-doc --> |
| * @see #getPopulationCount() |
| * @generated |
| * @ordered |
| */ |
| protected static final double POPULATION_COUNT_EDEFAULT = 0.0; |
| |
| /** |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @generated NOT |
| */ |
| public IntegrationLabelValue add(double addition) { |
| EList<EAttribute> attributes = eClass().getEAllAttributes(); |
| |
| for (EAttribute attribute : attributes) { |
| if (attribute.isChangeable() |
| && !attribute.getName().startsWith("incidence")) { |
| eSet(attribute, (Double) eGet(attribute) + addition); |
| } |
| } |
| |
| return this; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @generated NOT |
| */ |
| public IntegrationLabelValue abs() { |
| EList<EAttribute> attributes = eClass().getEAllAttributes(); |
| |
| for (EAttribute attribute : attributes) { |
| if (attribute.isChangeable() |
| && !attribute.getName().startsWith("incidence")) { |
| eSet(attribute, Math.abs((Double) eGet(attribute))); |
| } |
| } |
| |
| return this; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @generated NOT |
| */ |
| public boolean avoidNegative(IntegrationLabelValue value) { |
| EList<EAttribute> attributes = eClass().getEAllAttributes(); |
| boolean adjusted = false; |
| |
| for (EAttribute attribute : attributes) { |
| if (attribute.isChangeable()) { |
| double newValue = (Double) eGet(attribute) |
| + (Double) value.eGet(attribute); |
| |
| if (newValue < 0.0) { |
| adjusted = true; |
| eSet(attribute, -(Double) value.eGet(attribute)); |
| } |
| } |
| } |
| |
| return adjusted; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @generated NOT |
| */ |
| public double computeDeltaAdjustment(IntegrationLabelValue value) { |
| EList<EAttribute> attributes = eClass().getEAllAttributes(); |
| double factor = 1.0; |
| |
| for (EAttribute attribute : attributes) { |
| if (attribute.isChangeable()) { |
| double newValue = (Double) eGet(attribute) |
| + (Double) value.eGet(attribute); |
| |
| if (newValue < MINIMUM_VALUE) { |
| factor = Math.min(factor, -(Double) value.eGet(attribute) |
| / (Double) eGet(attribute)); |
| } |
| } |
| } |
| |
| return factor; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @generated NOT |
| */ |
| public IntegrationLabelValue divide(IntegrationLabelValue value) { |
| EList<EAttribute> attributes = eClass().getEAllAttributes(); |
| |
| for (EAttribute attribute : attributes) { |
| if (attribute.isChangeable() |
| && !attribute.getName().startsWith("incidence")) { |
| eSet(attribute, |
| Math.abs((Double) eGet(attribute) |
| / (Double) value.eGet(attribute))); |
| } |
| } |
| |
| return this; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @generated NOT |
| */ |
| public double max() { |
| EList<EAttribute> attributes = eClass().getEAllAttributes(); |
| double maxValue = 0.0; |
| |
| for (EAttribute attribute : attributes) { |
| if (attribute.isChangeable() |
| && !attribute.getName().startsWith("incidence")) { |
| maxValue = Math.max(maxValue, (Double) eGet(attribute)); |
| } |
| } |
| |
| return maxValue; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> <!-- end-user-doc --> |
| * |
| * @generated NOT |
| */ |
| public void prepareCycle() { |
| EList<EAttribute> attributes = eClass().getEAllAttributes(); |
| |
| for (EAttribute attribute : attributes) { |
| if (attribute.isChangeable() |
| && attribute.getName().startsWith("incidence")) { |
| eSet(attribute, 0.0); |
| } |
| } |
| } |
| |
| /** |
| * @see org.eclipse.stem.core.graph.impl.LabelValueImpl#reset() |
| */ |
| @Override |
| public void reset() { |
| EList<EAttribute> attributes = eClass().getEAllAttributes(); |
| |
| for (EAttribute attribute : attributes) { |
| if (attribute.isChangeable()) { |
| eSet(attribute, 0.0); |
| } |
| } |
| |
| arrivals = null; |
| departures = null; |
| } // reset |
| |
| /** |
| * @see org.eclipse.stem.core.common.SanityChecker#sane() |
| */ |
| @Override |
| public boolean sane() { |
| EList<EAttribute> attributes = eClass().getEAllAttributes(); |
| boolean retValue = true; |
| |
| for (EAttribute attribute : attributes) { |
| if (attribute.isChangeable()) { |
| retValue = (Double) eGet(attribute) >= 0.0; |
| assert retValue; |
| retValue = (Double) eGet(attribute) <= MAX_POPULATION_VALUE; |
| assert retValue; |
| } |
| } |
| |
| return retValue; |
| } // sane |
| |
| /** |
| * <!-- begin-user-doc --> |
| * |
| * @param featureID |
| * @param resolve |
| * @param coreType |
| * @return |
| * |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public Object eGet(int featureID, boolean resolve, boolean coreType) { |
| switch (featureID) { |
| case StandardPackage.DISEASE_MODEL_LABEL_VALUE__POPULATION_COUNT: |
| return getPopulationCount(); |
| } |
| return super.eGet(featureID, resolve, coreType); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * |
| * @param featureID |
| * @return |
| * |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public boolean eIsSet(int featureID) { |
| switch (featureID) { |
| case StandardPackage.DISEASE_MODEL_LABEL_VALUE__POPULATION_COUNT: |
| return getPopulationCount() != POPULATION_COUNT_EDEFAULT; |
| } |
| return super.eIsSet(featureID); |
| } |
| |
| @Override |
| public boolean sameValue(LabelValue otherLabelValue) { |
| EList<EAttribute> attributes = eClass().getEAllAttributes(); |
| |
| for (EAttribute attribute : attributes) { |
| if (attribute.isChangeable() |
| && !attribute.getName().startsWith("incidence") |
| && !attribute.getName().startsWith("diseaseDeaths")) { |
| if (((Double) eGet(attribute)) |
| .compareTo((Double) otherLabelValue.eGet(attribute)) != 0) { |
| return false; |
| } |
| } |
| } |
| |
| return true; |
| } |
| } // DiseaseModelLabelValueImpl |