001package org.biopax.paxtools.impl.level3;
002
003import org.biopax.paxtools.model.BioPAXElement;
004import org.biopax.paxtools.model.level3.PhysicalEntity;
005import org.biopax.paxtools.model.level3.Stoichiometry;
006import org.hibernate.annotations.Cache;
007import org.hibernate.annotations.CacheConcurrencyStrategy;
008import org.hibernate.annotations.Proxy;
009import org.hibernate.annotations.DynamicInsert;
010import org.hibernate.annotations.DynamicUpdate; 
011import org.hibernate.search.annotations.Indexed;
012
013import javax.persistence.Entity;
014import javax.persistence.ManyToOne;
015import javax.persistence.Transient;
016
017@Entity
018@Proxy(proxyClass= Stoichiometry.class)
019@Indexed//(index = BioPAXElementImpl.SEARCH_INDEX_NAME)
020@DynamicUpdate @DynamicInsert
021@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
022public class StoichiometryImpl extends L3ElementImpl implements Stoichiometry
023{
024        private float stoichiometricCoefficient = UNKNOWN_FLOAT;
025        private PhysicalEntity physicalEntity;
026
027
028        public StoichiometryImpl() {}
029
030        @Transient
031        public Class<? extends Stoichiometry> getModelInterface()
032        {
033                return Stoichiometry.class;
034        }
035
036        @Override
037        protected boolean semanticallyEquivalent(BioPAXElement element)
038        {
039
040                boolean value = false;
041                if (element instanceof Stoichiometry)
042                {
043                        Stoichiometry that = (Stoichiometry) element;
044                        if (that.getPhysicalEntity() != null && this.getPhysicalEntity() != null)
045                        {
046                                value = (that.getStoichiometricCoefficient() ==
047                                         this.getStoichiometricCoefficient()) &&
048                                        that.getPhysicalEntity().equals(this.getPhysicalEntity());
049
050                        }
051                }
052                return value;
053        }
054
055        @Override
056        public int equivalenceCode()
057        {
058                return ((int) this.getStoichiometricCoefficient()) +
059               ((this.getPhysicalEntity() != null)
060                ? 31 * this.getPhysicalEntity().hashCode()
061                : 0);
062        }
063
064        @ManyToOne(targetEntity = PhysicalEntityImpl.class)
065        public PhysicalEntity getPhysicalEntity()
066        {
067                return physicalEntity;
068        }
069
070        public void setPhysicalEntity(PhysicalEntity PhysicalEntity)
071        {
072                this.physicalEntity = PhysicalEntity;
073        }
074
075        
076        public float getStoichiometricCoefficient()
077        {
078                return stoichiometricCoefficient;
079        }
080
081        public void setStoichiometricCoefficient(float newStoichiometricCoefficient)
082        {
083                stoichiometricCoefficient = newStoichiometricCoefficient;
084        }
085}