blob: 9e584b3e248836c1837950bab827bd8909901cf6 [file] [log] [blame]
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 org.eclipse.emf.common.notify.Notification;
import java.text.DecimalFormat;
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.stem.core.graph.GraphPackage;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.stem.core.graph.Exchange;
import org.eclipse.stem.core.graph.ExchangeType;
import org.eclipse.stem.core.graph.IntegrationLabel;
import org.eclipse.stem.core.graph.LabelValue;
import org.eclipse.stem.core.graph.IntegrationLabelValue;
import org.eclipse.stem.core.graph.Label;
import org.eclipse.stem.core.model.STEMTime;
import org.eclipse.stem.definitions.labels.PopulationLabelValue;
import org.eclipse.stem.diseasemodels.standard.StandardDiseaseModelLabel;
import org.eclipse.stem.diseasemodels.standard.StandardDiseaseModelLabelValue;
import org.eclipse.stem.diseasemodels.standard.StandardPackage;
import org.eclipse.stem.populationmodels.standard.DemographicPopulationModel;
import org.eclipse.stem.populationmodels.standard.PopulationGroup;
/**
* <!-- begin-user-doc --> An implementation of the model object '<em><b>Disease Model Label</b></em>'.
* <!-- end-user-doc -->
* <p>
* The following features are implemented:
* <ul>
* <li>{@link org.eclipse.stem.diseasemodels.standard.impl.StandardDiseaseModelLabelImpl#getDeltaValue <em>Delta Value</em>}</li>
* <li>{@link org.eclipse.stem.diseasemodels.standard.impl.StandardDiseaseModelLabelImpl#getTempValue <em>Temp Value</em>}</li>
* <li>{@link org.eclipse.stem.diseasemodels.standard.impl.StandardDiseaseModelLabelImpl#getProbeValue <em>Probe Value</em>}</li>
* <li>{@link org.eclipse.stem.diseasemodels.standard.impl.StandardDiseaseModelLabelImpl#getErrorScale <em>Error Scale</em>}</li>
* <li>{@link org.eclipse.stem.diseasemodels.standard.impl.StandardDiseaseModelLabelImpl#getIdentifier <em>Identifier</em>}</li>
* </ul>
* </p>
*
* @generated
*/
public abstract class StandardDiseaseModelLabelImpl extends
DiseaseModelLabelImpl implements StandardDiseaseModelLabel {
/**
* The cached value of the '{@link #getDeltaValue() <em>Delta Value</em>}' reference.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getDeltaValue()
* @generated
* @ordered
*/
protected IntegrationLabelValue deltaValue;
/**
* The cached value of the '{@link #getTempValue() <em>Temp Value</em>}' reference.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getTempValue()
* @generated
* @ordered
*/
protected IntegrationLabelValue tempValue;
/**
* The cached value of the '{@link #getProbeValue() <em>Probe Value</em>}' reference.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getProbeValue()
* @generated
* @ordered
*/
protected IntegrationLabelValue probeValue;
/**
* The cached value of the '{@link #getErrorScale() <em>Error Scale</em>}' reference.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getErrorScale()
* @generated
* @ordered
*/
protected IntegrationLabelValue errorScale;
/**
* The default value of the '{@link #getIdentifier() <em>Identifier</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getIdentifier()
* @generated
* @ordered
*/
protected static final String IDENTIFIER_EDEFAULT = null;
/**
* The cached value of the '{@link #getIdentifier() <em>Identifier</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getIdentifier()
* @generated
* @ordered
*/
protected String identifier = IDENTIFIER_EDEFAULT;
private static DecimalFormat formatPercentage = null;
/**
* @return a decimal formatter
*/
protected static DecimalFormat getPercentFormat() {
// Is there already a formatter?
if (formatPercentage == null) {
// No
formatPercentage = new DecimalFormat("#%");
}
return formatPercentage;
} // getPercentFormat()
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
protected StandardDiseaseModelLabelImpl() {
super();
}
/**
* @see org.eclipse.stem.core.graph.impl.DynamicLabelImpl#reset()
*/
@Override
public void reset() {
// The call to super.reset will reset the label value of this label
// which will zero out all of the disease state values.
super.reset();
getTempValue().reset();
getDeltaValue().reset();
getErrorScale().reset();
getProbeValue().reset();
// Is there a population instance associated with this instance?
if (getPopulationModelLabel() != null) {
// Yes
// Ok, set the susceptible population to the count of the number of
// population members
final StandardDiseaseModelLabelValue sValue = (StandardDiseaseModelLabelValue)getCurrentValue();
// Get the fraction of the population group if DemographicPopulationModel is used
double fraction = 1.0;
if (getPopulationModelLabel().getDecorator() instanceof DemographicPopulationModel) {
DemographicPopulationModel model = (DemographicPopulationModel) getPopulationModelLabel().getDecorator();
for (PopulationGroup group : model.getPopulationGroups()) {
if (group.getIdentifier() == getPopulationModelLabel().getPopulationIdentifier()) {
fraction = group.getFraction();
}
}
}
// Use the population label (not population model label).
sValue.setS(((PopulationLabelValue)getPopulationModelLabel().getPopulationLabel().getCurrentValue()).getCount() * fraction);
// Set the next value too. This is to avoid switching between zero values and non-zero values
// when the graph updates to the next value for nodes that are not being updated by this instance
((IntegrationLabelValue)getNextValue()).set((IntegrationLabelValue)getCurrentValue());
} // if
} // reset
/**
* Return the identifier for the label, i.e. the population identifier
*
* @return String The identifier
*/
public String getIdentifier() {
return this.getPopulationModelLabel().getPopulationIdentifier();
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
protected EClass eStaticClass() {
return StandardPackage.Literals.STANDARD_DISEASE_MODEL_LABEL;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public IntegrationLabelValue getDeltaValue() {
if (deltaValue != null && deltaValue.eIsProxy()) {
InternalEObject oldDeltaValue = (InternalEObject)deltaValue;
deltaValue = (IntegrationLabelValue)eResolveProxy(oldDeltaValue);
if (deltaValue != oldDeltaValue) {
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.RESOLVE, StandardPackage.STANDARD_DISEASE_MODEL_LABEL__DELTA_VALUE, oldDeltaValue, deltaValue));
}
}
return deltaValue;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public IntegrationLabelValue basicGetDeltaValue() {
return deltaValue;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setDeltaValue(IntegrationLabelValue newDeltaValue) {
IntegrationLabelValue oldDeltaValue = deltaValue;
deltaValue = newDeltaValue;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, StandardPackage.STANDARD_DISEASE_MODEL_LABEL__DELTA_VALUE, oldDeltaValue, deltaValue));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public IntegrationLabelValue getTempValue() {
if (tempValue != null && tempValue.eIsProxy()) {
InternalEObject oldTempValue = (InternalEObject)tempValue;
tempValue = (IntegrationLabelValue)eResolveProxy(oldTempValue);
if (tempValue != oldTempValue) {
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.RESOLVE, StandardPackage.STANDARD_DISEASE_MODEL_LABEL__TEMP_VALUE, oldTempValue, tempValue));
}
}
return tempValue;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public IntegrationLabelValue basicGetTempValue() {
return tempValue;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setTempValue(IntegrationLabelValue newTempValue) {
IntegrationLabelValue oldTempValue = tempValue;
tempValue = newTempValue;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, StandardPackage.STANDARD_DISEASE_MODEL_LABEL__TEMP_VALUE, oldTempValue, tempValue));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public IntegrationLabelValue getProbeValue() {
if (probeValue != null && probeValue.eIsProxy()) {
InternalEObject oldProbeValue = (InternalEObject)probeValue;
probeValue = (IntegrationLabelValue)eResolveProxy(oldProbeValue);
if (probeValue != oldProbeValue) {
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.RESOLVE, StandardPackage.STANDARD_DISEASE_MODEL_LABEL__PROBE_VALUE, oldProbeValue, probeValue));
}
}
return probeValue;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public IntegrationLabelValue basicGetProbeValue() {
return probeValue;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setProbeValue(IntegrationLabelValue newProbeValue) {
IntegrationLabelValue oldProbeValue = probeValue;
probeValue = newProbeValue;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, StandardPackage.STANDARD_DISEASE_MODEL_LABEL__PROBE_VALUE, oldProbeValue, probeValue));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public IntegrationLabelValue getErrorScale() {
if (errorScale != null && errorScale.eIsProxy()) {
InternalEObject oldErrorScale = (InternalEObject)errorScale;
errorScale = (IntegrationLabelValue)eResolveProxy(oldErrorScale);
if (errorScale != oldErrorScale) {
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.RESOLVE, StandardPackage.STANDARD_DISEASE_MODEL_LABEL__ERROR_SCALE, oldErrorScale, errorScale));
}
}
return errorScale;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public IntegrationLabelValue basicGetErrorScale() {
return errorScale;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setErrorScale(IntegrationLabelValue newErrorScale) {
IntegrationLabelValue oldErrorScale = errorScale;
errorScale = newErrorScale;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, StandardPackage.STANDARD_DISEASE_MODEL_LABEL__ERROR_SCALE, oldErrorScale, errorScale));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public String toTooltipString() {
// TODO: implement this method
// Ensure that you remove @generated or mark it @generated NOT
throw new UnsupportedOperationException();
}
/**
* @see org.eclipse.stem.diseasemodels.standard.StandardDiseaseModelLabel#getS()
*/
public double getS() {
return (((StandardDiseaseModelLabelValue)getCurrentValue())).getS();
} // getS
/**
* @see org.eclipse.stem.diseasemodels.standard.StandardDiseaseModelLabel#setS(double)
*/
public void setS(double s) {
(((StandardDiseaseModelLabelValue)getCurrentValue())).setS(s);
} // setS
/**
* @see org.eclipse.stem.diseasemodels.standard.StandardDiseaseModelLabel#getNextS()
*/
public double getNextS() {
return (((StandardDiseaseModelLabelValue)getNextValue())).getS();
} // getNextS
/**
* @see org.eclipse.stem.diseasemodels.standard.StandardDiseaseModelLabel#setNextS(double)
*/
public void setNextS(double s) {
(((StandardDiseaseModelLabelValue)getNextValue())).setS(s);
} // setNextS
public void reset(STEMTime time) {
// Adjust current value by adding/substracting deltas by other models (population models).
// We do this to set the right counts to match the population numbers at the beginning
// of the simulation.
for(Label l:this.getNode().getLabels()) {
if(l instanceof IntegrationLabel) {
if(!((IntegrationLabel)l).getIdentifier().equals(this.getPopulationModelLabel().getPopulationIdentifier()))
continue;
IntegrationLabel il = (IntegrationLabel)l;
if(l == this) continue;
IntegrationLabelValue delta = (IntegrationLabelValue)il.getDeltaValue();
EList<Exchange> arrivals = delta.getArrivals();
EList<Exchange> departures = delta.getDepartures();
// We scale the label values back since at this point the innoculators/infectors
// have already been applied and we need to modify all states of the disease
double popCount = ((StandardDiseaseModelLabelValue)this.getCurrentValue()).getPopulationCount();
if(arrivals != null && arrivals.size() == 1) {
assert(arrivals.get(0).getType() == ExchangeType.BIRTHS_AND_DEATHS);
double factor = arrivals.get(0).getCount() / popCount;
if(Double.isNaN(factor) || Double.isInfinite(factor)) factor = 0.0;// do nothing
IntegrationLabelValue addV = (IntegrationLabelValue)EcoreUtil.copy(this.getCurrentValue());
addV.scale(factor);
((IntegrationLabelValue)this.getCurrentValue()).add((IntegrationLabelValue)addV);
}
if(departures != null && departures.size() == 1) {
assert(departures.get(0).getType() == ExchangeType.BIRTHS_AND_DEATHS);
double factor = departures.get(0).getCount() / popCount;
if(Double.isNaN(factor) || Double.isInfinite(factor)) factor = 0.0;// do nothing
IntegrationLabelValue subV = (IntegrationLabelValue)EcoreUtil.copy(this.getCurrentValue());
subV.scale(factor);
((IntegrationLabelValue)this.getCurrentValue()).sub((IntegrationLabelValue)subV);
}
}
}
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Object eGet(int featureID, boolean resolve, boolean coreType) {
switch (featureID) {
case StandardPackage.STANDARD_DISEASE_MODEL_LABEL__DELTA_VALUE:
if (resolve) return getDeltaValue();
return basicGetDeltaValue();
case StandardPackage.STANDARD_DISEASE_MODEL_LABEL__TEMP_VALUE:
if (resolve) return getTempValue();
return basicGetTempValue();
case StandardPackage.STANDARD_DISEASE_MODEL_LABEL__PROBE_VALUE:
if (resolve) return getProbeValue();
return basicGetProbeValue();
case StandardPackage.STANDARD_DISEASE_MODEL_LABEL__ERROR_SCALE:
if (resolve) return getErrorScale();
return basicGetErrorScale();
case StandardPackage.STANDARD_DISEASE_MODEL_LABEL__IDENTIFIER:
return getIdentifier();
}
return super.eGet(featureID, resolve, coreType);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eSet(int featureID, Object newValue) {
switch (featureID) {
case StandardPackage.STANDARD_DISEASE_MODEL_LABEL__DELTA_VALUE:
setDeltaValue((IntegrationLabelValue)newValue);
return;
case StandardPackage.STANDARD_DISEASE_MODEL_LABEL__TEMP_VALUE:
setTempValue((IntegrationLabelValue)newValue);
return;
case StandardPackage.STANDARD_DISEASE_MODEL_LABEL__PROBE_VALUE:
setProbeValue((IntegrationLabelValue)newValue);
return;
case StandardPackage.STANDARD_DISEASE_MODEL_LABEL__ERROR_SCALE:
setErrorScale((IntegrationLabelValue)newValue);
return;
}
super.eSet(featureID, newValue);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID) {
switch (featureID) {
case StandardPackage.STANDARD_DISEASE_MODEL_LABEL__DELTA_VALUE:
setDeltaValue((IntegrationLabelValue)null);
return;
case StandardPackage.STANDARD_DISEASE_MODEL_LABEL__TEMP_VALUE:
setTempValue((IntegrationLabelValue)null);
return;
case StandardPackage.STANDARD_DISEASE_MODEL_LABEL__PROBE_VALUE:
setProbeValue((IntegrationLabelValue)null);
return;
case StandardPackage.STANDARD_DISEASE_MODEL_LABEL__ERROR_SCALE:
setErrorScale((IntegrationLabelValue)null);
return;
}
super.eUnset(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean eIsSet(int featureID) {
switch (featureID) {
case StandardPackage.STANDARD_DISEASE_MODEL_LABEL__DELTA_VALUE:
return deltaValue != null;
case StandardPackage.STANDARD_DISEASE_MODEL_LABEL__TEMP_VALUE:
return tempValue != null;
case StandardPackage.STANDARD_DISEASE_MODEL_LABEL__PROBE_VALUE:
return probeValue != null;
case StandardPackage.STANDARD_DISEASE_MODEL_LABEL__ERROR_SCALE:
return errorScale != null;
case StandardPackage.STANDARD_DISEASE_MODEL_LABEL__IDENTIFIER:
return IDENTIFIER_EDEFAULT == null ? identifier != null : !IDENTIFIER_EDEFAULT.equals(identifier);
}
return super.eIsSet(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public int eBaseStructuralFeatureID(int derivedFeatureID, Class<?> baseClass) {
if (baseClass == IntegrationLabel.class) {
switch (derivedFeatureID) {
case StandardPackage.STANDARD_DISEASE_MODEL_LABEL__DELTA_VALUE: return GraphPackage.INTEGRATION_LABEL__DELTA_VALUE;
case StandardPackage.STANDARD_DISEASE_MODEL_LABEL__TEMP_VALUE: return GraphPackage.INTEGRATION_LABEL__TEMP_VALUE;
case StandardPackage.STANDARD_DISEASE_MODEL_LABEL__PROBE_VALUE: return GraphPackage.INTEGRATION_LABEL__PROBE_VALUE;
case StandardPackage.STANDARD_DISEASE_MODEL_LABEL__ERROR_SCALE: return GraphPackage.INTEGRATION_LABEL__ERROR_SCALE;
case StandardPackage.STANDARD_DISEASE_MODEL_LABEL__IDENTIFIER: return GraphPackage.INTEGRATION_LABEL__IDENTIFIER;
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 == IntegrationLabel.class) {
switch (baseFeatureID) {
case GraphPackage.INTEGRATION_LABEL__DELTA_VALUE: return StandardPackage.STANDARD_DISEASE_MODEL_LABEL__DELTA_VALUE;
case GraphPackage.INTEGRATION_LABEL__TEMP_VALUE: return StandardPackage.STANDARD_DISEASE_MODEL_LABEL__TEMP_VALUE;
case GraphPackage.INTEGRATION_LABEL__PROBE_VALUE: return StandardPackage.STANDARD_DISEASE_MODEL_LABEL__PROBE_VALUE;
case GraphPackage.INTEGRATION_LABEL__ERROR_SCALE: return StandardPackage.STANDARD_DISEASE_MODEL_LABEL__ERROR_SCALE;
case GraphPackage.INTEGRATION_LABEL__IDENTIFIER: return StandardPackage.STANDARD_DISEASE_MODEL_LABEL__IDENTIFIER;
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(" (identifier: "); //$NON-NLS-1$
result.append(identifier);
result.append(')');
return result.toString();
}
} // StandardDiseaseModelLabelImpl