/** */ package ftp.impl; import ftp.AnalogBattery; import ftp.ElectricalPort; import ftp.FloatValue; import ftp.FtpPackage; import ftp.Port; import ftp.TypedPortValue; import java.util.ArrayList; import java.util.List; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.notify.NotificationChain; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.InternalEObject; import org.eclipse.emf.ecore.impl.ENotificationImpl; /** * <!-- begin-user-doc --> * An implementation of the model object '<em><b>Analog Battery</b></em>'. * <!-- end-user-doc --> * <p> * The following features are implemented: * </p> * <ul> * <li>{@link ftp.impl.AnalogBatteryImpl#getInPort <em>In Port</em>}</li> * <li>{@link ftp.impl.AnalogBatteryImpl#getOutPort <em>Out Port</em>}</li> * <li>{@link ftp.impl.AnalogBatteryImpl#getVoltage <em>Voltage</em>}</li> * </ul> * * @generated */ public class AnalogBatteryImpl extends PrimitiveComponentImpl implements AnalogBattery { /** * The cached value of the '{@link #getInPort() <em>In Port</em>}' containment reference. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @see #getInPort() * @generated * @ordered */ protected ElectricalPort inPort; /** * The cached value of the '{@link #getOutPort() <em>Out Port</em>}' containment reference. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @see #getOutPort() * @generated * @ordered */ protected ElectricalPort outPort; /** * The default value of the '{@link #getVoltage() <em>Voltage</em>}' attribute. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @see #getVoltage() * @generated * @ordered */ protected static final float VOLTAGE_EDEFAULT = 12.0F; /** * The cached value of the '{@link #getVoltage() <em>Voltage</em>}' attribute. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @see #getVoltage() * @generated * @ordered */ protected float voltage = VOLTAGE_EDEFAULT; /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated NOT */ protected AnalogBatteryImpl() { super(); setType("a_battery"); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override protected EClass eStaticClass() { return FtpPackage.Literals.ANALOG_BATTERY; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated NOT */ public ElectricalPort getInPort() { if (inPort == null) { ElectricalPort ep = new ElectricalPortImpl(); ep.setType("In"); setInPort(ep); } return inPort; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public NotificationChain basicSetInPort(ElectricalPort newInPort, NotificationChain msgs) { ElectricalPort oldInPort = inPort; inPort = newInPort; if (eNotificationRequired()) { ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, FtpPackage.ANALOG_BATTERY__IN_PORT, oldInPort, newInPort); if (msgs == null) msgs = notification; else msgs.add(notification); } return msgs; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setInPort(ElectricalPort newInPort) { if (newInPort != inPort) { NotificationChain msgs = null; if (inPort != null) msgs = ((InternalEObject)inPort).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - FtpPackage.ANALOG_BATTERY__IN_PORT, null, msgs); if (newInPort != null) msgs = ((InternalEObject)newInPort).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - FtpPackage.ANALOG_BATTERY__IN_PORT, null, msgs); msgs = basicSetInPort(newInPort, msgs); if (msgs != null) msgs.dispatch(); } else if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, FtpPackage.ANALOG_BATTERY__IN_PORT, newInPort, newInPort)); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated NOT */ public ElectricalPort getOutPort() { if (outPort == null) { ElectricalPort ep = new ElectricalPortImpl(); ep.setType("Out"); setOutPort(ep); } return outPort; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public NotificationChain basicSetOutPort(ElectricalPort newOutPort, NotificationChain msgs) { ElectricalPort oldOutPort = outPort; outPort = newOutPort; if (eNotificationRequired()) { ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, FtpPackage.ANALOG_BATTERY__OUT_PORT, oldOutPort, newOutPort); if (msgs == null) msgs = notification; else msgs.add(notification); } return msgs; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setOutPort(ElectricalPort newOutPort) { if (newOutPort != outPort) { NotificationChain msgs = null; if (outPort != null) msgs = ((InternalEObject)outPort).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - FtpPackage.ANALOG_BATTERY__OUT_PORT, null, msgs); if (newOutPort != null) msgs = ((InternalEObject)newOutPort).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - FtpPackage.ANALOG_BATTERY__OUT_PORT, null, msgs); msgs = basicSetOutPort(newOutPort, msgs); if (msgs != null) msgs.dispatch(); } else if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, FtpPackage.ANALOG_BATTERY__OUT_PORT, newOutPort, newOutPort)); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public float getVoltage() { return voltage; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setVoltage(float newVoltage) { float oldVoltage = voltage; voltage = newVoltage; if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, FtpPackage.ANALOG_BATTERY__VOLTAGE, oldVoltage, voltage)); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) { switch (featureID) { case FtpPackage.ANALOG_BATTERY__IN_PORT: return basicSetInPort(null, msgs); case FtpPackage.ANALOG_BATTERY__OUT_PORT: return basicSetOutPort(null, 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 FtpPackage.ANALOG_BATTERY__IN_PORT: return getInPort(); case FtpPackage.ANALOG_BATTERY__OUT_PORT: return getOutPort(); case FtpPackage.ANALOG_BATTERY__VOLTAGE: return getVoltage(); } return super.eGet(featureID, resolve, coreType); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case FtpPackage.ANALOG_BATTERY__IN_PORT: setInPort((ElectricalPort)newValue); return; case FtpPackage.ANALOG_BATTERY__OUT_PORT: setOutPort((ElectricalPort)newValue); return; case FtpPackage.ANALOG_BATTERY__VOLTAGE: setVoltage((Float)newValue); return; } super.eSet(featureID, newValue); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void eUnset(int featureID) { switch (featureID) { case FtpPackage.ANALOG_BATTERY__IN_PORT: setInPort((ElectricalPort)null); return; case FtpPackage.ANALOG_BATTERY__OUT_PORT: setOutPort((ElectricalPort)null); return; case FtpPackage.ANALOG_BATTERY__VOLTAGE: setVoltage(VOLTAGE_EDEFAULT); return; } super.eUnset(featureID); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public boolean eIsSet(int featureID) { switch (featureID) { case FtpPackage.ANALOG_BATTERY__IN_PORT: return inPort != null; case FtpPackage.ANALOG_BATTERY__OUT_PORT: return outPort != null; case FtpPackage.ANALOG_BATTERY__VOLTAGE: return voltage != VOLTAGE_EDEFAULT; } 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(" (voltage: "); result.append(voltage); result.append(')'); return result.toString(); } public List<Port> retrievePorts() { List<Port> ports = new ArrayList<Port>(); ports.add(getInPort()); ports.add(getOutPort()); return ports; } public List<TypedPortValue> retrieveParams() { List<TypedPortValue> params = new ArrayList<TypedPortValue>(); FloatValue fv = new FloatValueImpl(); fv.setValue(getVoltage()); params.add(fv); return params; } public List<Predicate> translateToLogic() { if (logic == null) { Predicate pred = new Predicate(); pred.functor = "a_battery/4"; pred.stateArgs = 1; List<String> clauses = new ArrayList<String>(); clauses.add("(a_battery(electrical(V1,I1),electrical(V2,I2),Voltage,ok):-{I1+I2=0,Voltage=V1-V2})"); clauses.add("(a_battery(electrical(V1,0),electrical(V2,0),_Voltage,failed(discharged)):-{V1-V2 = 0})"); pred.clauses = clauses; List<Predicate> preds = new ArrayList<Predicate>(); preds.add(pred); logic = preds; } return logic; } } //AnalogBatteryImpl