00001 package cedar.hepdata.model; 00002 00003 import cedar.hepdata.util.*; 00004 00005 import javax.persistence.*; 00006 00017 @Embeddable 00018 public class Particle extends Storeable { 00020 @Column(name="ParticleName", nullable=false) 00021 private String name; 00022 00024 @Column(name="PDGCode", nullable=true) 00025 private Integer pdgCode; 00026 00028 @Column(name="Multiplicity", nullable=false) 00029 private Integer multiplicity = 1; 00030 00033 @Column(name="MultRelation", nullable=false) 00034 private Relation multRelation = Relation.EQUALS; 00035 00036 00038 00039 00041 public Particle() {} 00042 00043 public Particle(Integer pdgCode) { 00044 setPDGCode(pdgCode); 00045 } 00046 00047 public Particle(String name) { 00048 setName(name); 00049 } 00050 00051 public Particle(String name, Integer multiplicity) { 00052 this(name); 00053 setMultiplicity(multiplicity); 00054 } 00055 00056 public Particle(String name, Integer multiplicity, Relation relation) { 00057 this(name, multiplicity); 00058 setMultRelation(relation); 00059 } 00060 00061 00062 00064 00065 00066 public static Boolean sameType(Particle a, Particle b) { 00067 return a.getPDGCode() == b.getPDGCode() || a.getName() == b.getName(); 00068 } 00069 00070 00072 00073 00075 public Integer getPDGCode() { 00076 return pdgCode; 00077 } 00079 public Particle setPDGCode(Integer pdgCode) { 00080 this.pdgCode = pdgCode; 00081 return this; 00082 } 00083 00084 00088 public String getName() { 00089 return name; 00090 } 00094 public Particle setName(String name) { 00095 this.name = name; 00096 return this; 00097 } 00098 00099 00101 public Integer getMultiplicity() { 00102 return multiplicity; 00103 } 00105 public Particle setMultiplicity(Integer multiplicity) { 00106 this.multiplicity = multiplicity; 00107 return this; 00108 } 00109 00110 00114 public Relation getMultRelation() { 00115 return multRelation; 00116 } 00120 public Particle setMultRelation(Relation multRelation) { 00121 this.multRelation = multRelation; 00122 return this; 00123 } 00124 00125 00126 00128 00129 00130 00134 public String getHtmlName() throws HDException { 00135 throw new HDException("YaPPI functionality currently unimplemented"); 00136 } 00137 00138 00142 public String getTexName() throws HDException { 00143 throw new HDException("YaPPI functionality currently unimplemented"); 00144 } 00145 00146 00147 00149 00150 00151 00153 public boolean equals(Object other) { 00154 if (this == other) return true; 00155 //if (! (other instanceof Reaction)) return false; 00156 if (! (other instanceof Particle)) return false; 00157 return hashCode() == other.hashCode(); 00158 } 00159 00161 public int hashCode() { 00162 int code = 37; 00163 if (getPDGCode() != null) code ^= getPDGCode().hashCode(); 00164 if (getMultiplicity() != null) code ^= getMultiplicity().hashCode(); 00165 if (getMultRelation() != null) code ^= getMultRelation().hashCode(); 00166 return code; 00167 } 00168 00169 00171 00172 00173 00174 public String toString() { 00175 StringBuffer s = new StringBuffer(); 00176 if (getMultiplicity() != null) { 00177 if (getMultRelation() != Relation.EQUALS) { 00178 s.append(getMultRelation()); 00179 s.append(getMultiplicity()); 00180 } else if (getMultiplicity() != 1) { 00181 s.append(getMultiplicity()); 00182 } 00183 } 00184 s.append(getName()); 00185 return s.toString(); 00186 } 00187 00188 00189 }