00001 package cedar.hepdata.model; 00002 00003 import cedar.hepdata.util.*; 00004 import javax.persistence.*; 00005 00016 @Embeddable 00017 public class Particle extends Storeable { 00019 @Column(name="ParticleName", nullable=false) 00020 private String name = null; 00021 00023 @Column(name="PDGCode", nullable=true) 00024 private Integer pdgCode = null; 00025 00027 @Column(name="Multiplicity", nullable=false) 00028 private Integer multiplicity = 1; 00029 00032 @Column(name="MultRelation", nullable=false) 00033 private Relation multRelation = Relation.EQUALS; 00034 00035 00037 00038 00040 public Particle() {} 00041 00042 public Particle(Integer pdgCode) { 00043 setPDGCode(pdgCode); 00044 } 00045 00046 public Particle(String name) { 00047 setName(name); 00048 } 00049 00050 public Particle(String name, Integer multiplicity) { 00051 this(name); 00052 setMultiplicity(multiplicity); 00053 } 00054 00055 public Particle(String name, Integer multiplicity, Relation relation) { 00056 this(name, multiplicity); 00057 setMultRelation(relation); 00058 } 00059 00060 00061 00063 00064 00065 public static Boolean sameType(Particle a, Particle b) { 00066 return a.getPDGCode() != null && b.getPDGCode() != null && a.getPDGCode() == b.getPDGCode() 00067 || 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 Particle)) return false; 00156 return hashCode() == other.hashCode(); 00157 } 00158 00159 00161 public int hashCode() { 00162 int code = 37; 00163 if (getName() != null) code ^= getName().hashCode(); 00164 if (getPDGCode() != null) code ^= getPDGCode().hashCode(); 00165 if (getMultiplicity() != null) code ^= getMultiplicity().hashCode(); 00166 if (getMultRelation() != null) code ^= getMultRelation().hashCode(); 00167 return code; 00168 } 00169 00170 00172 00173 00174 00175 public String toString() { 00176 StringBuffer s = new StringBuffer(); 00177 if (getMultiplicity() != null) { 00178 if (getMultRelation() != null && getMultRelation() != Relation.EQUALS) { 00179 s.append(getMultRelation()); 00180 s.append(getMultiplicity()); 00181 } else if (getMultiplicity() != 1) { 00182 s.append(getMultiplicity()); 00183 } 00184 } 00185 s.append(getName()); 00186 return s.toString(); 00187 } 00188 00189 00190 }