/** */ package ftp.impl; import ftp.ElectricalPort; import ftp.FloatValue; import ftp.FtpPackage; import ftp.Port; import ftp.Resistor; 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>Resistor</b></em>'. * <!-- end-user-doc --> * <p> * The following features are implemented: * </p> * <ul> * <li>{@link ftp.impl.ResistorImpl#getResistance <em>Resistance</em>}</li> * <li>{@link ftp.impl.ResistorImpl#getInPort <em>In Port</em>}</li> * <li>{@link ftp.impl.ResistorImpl#getOutPort <em>Out Port</em>}</li> * </ul> * * @generated */ public class ResistorImpl extends PrimitiveComponentImpl implements Resistor { /** * The default value of the '{@link #getResistance() <em>Resistance</em>}' attribute. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @see #getResistance() * @generated * @ordered */ protected static final float RESISTANCE_EDEFAULT = 6.0F; /** * The cached value of the '{@link #getResistance() <em>Resistance</em>}' attribute. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @see #getResistance() * @generated * @ordered */ protected float resistance = RESISTANCE_EDEFAULT; /** * 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; /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected ResistorImpl() { super(); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override protected EClass eStaticClass() { return FtpPackage.Literals.RESISTOR; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public float getResistance() { return resistance; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setResistance(float newResistance) { float oldResistance = resistance; resistance = newResistance; if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, FtpPackage.RESISTOR__RESISTANCE, oldResistance, resistance)); } /** * <!-- 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.RESISTOR__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.RESISTOR__IN_PORT, null, msgs); if (newInPort != null) msgs = ((InternalEObject)newInPort).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - FtpPackage.RESISTOR__IN_PORT, null, msgs); msgs = basicSetInPort(newInPort, msgs); if (msgs != null) msgs.dispatch(); } else if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, FtpPackage.RESISTOR__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.RESISTOR__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.RESISTOR__OUT_PORT, null, msgs); if (newOutPort != null) msgs = ((InternalEObject)newOutPort).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - FtpPackage.RESISTOR__OUT_PORT, null, msgs); msgs = basicSetOutPort(newOutPort, msgs); if (msgs != null) msgs.dispatch(); } else if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, FtpPackage.RESISTOR__OUT_PORT, newOutPort, newOutPort)); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) { switch (featureID) { case FtpPackage.RESISTOR__IN_PORT: return basicSetInPort(null, msgs); case FtpPackage.RESISTOR__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.RESISTOR__RESISTANCE: return getResistance(); case FtpPackage.RESISTOR__IN_PORT: return getInPort(); case FtpPackage.RESISTOR__OUT_PORT: return getOutPort(); } 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.RESISTOR__RESISTANCE: setResistance((Float)newValue); return; case FtpPackage.RESISTOR__IN_PORT: setInPort((ElectricalPort)newValue); return; case FtpPackage.RESISTOR__OUT_PORT: setOutPort((ElectricalPort)newValue); return; } super.eSet(featureID, newValue); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void eUnset(int featureID) { switch (featureID) { case FtpPackage.RESISTOR__RESISTANCE: setResistance(RESISTANCE_EDEFAULT); return; case FtpPackage.RESISTOR__IN_PORT: setInPort((ElectricalPort)null); return; case FtpPackage.RESISTOR__OUT_PORT: setOutPort((ElectricalPort)null); return; } super.eUnset(featureID); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public boolean eIsSet(int featureID) { switch (featureID) { case FtpPackage.RESISTOR__RESISTANCE: return resistance != RESISTANCE_EDEFAULT; case FtpPackage.RESISTOR__IN_PORT: return inPort != null; case FtpPackage.RESISTOR__OUT_PORT: return outPort != null; } 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(" (resistance: "); result.append(resistance); 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(getResistance()); params.add(fv); return params; } public List<Predicate> translateToLogic() { if (logic == null) { Predicate pred = new Predicate(); pred.functor = "resistor/4"; pred.stateArgs = 1; List<String> clauses = new ArrayList<String>(); clauses.add("(resistor(electrical(V1,I1),electrical(V2,I2),R,ok):-{I1= -I2,V1-V2=I1*R})"); clauses.add("(resistor(electrical(V1,I1),electrical(V2,I2),R,failed(resistance(R2))):-{I1= -I2,V1-V2=I1*R2,R2>0,R2 =\\= R})"); pred.clauses = clauses; List<Predicate> preds = new ArrayList<Predicate>(); preds.add(pred); logic = preds; } return logic; } } //ResistorImpl