00001 package cedar.hepdata.model;
00002
00003 import cedar.hepdata.util.*;
00004 import javax.persistence.*;
00005
00006
00015 @Embeddable
00016 public class DatasetError extends Uncertainty {
00017
00018 @Column(name="LocalId", nullable=false)
00019 private Integer _localId;
00020
00021 @Transient
00023 private Dataset _dataset;
00024
00025
00027
00028
00030 public DatasetError() { super(); }
00031
00038 public DatasetError(Double plusminus, ErrorSource sourcetype, ErrorNorm normtype) {
00039 super(plusminus, sourcetype, normtype);
00040 }
00041
00049 public DatasetError(Double plus, Double minus, ErrorSource sourcetype, ErrorNorm normtype) {
00050 super(plus, minus, sourcetype, normtype);
00051 }
00052
00059 public DatasetError(Dataset dataset, Double plusminus, ErrorSource sourcetype, ErrorNorm normtype) {
00060 super(plusminus, sourcetype, normtype);
00061 setDataset(dataset);
00062 }
00063
00071 public DatasetError(Dataset dataset, Double plus, Double minus, ErrorSource sourcetype, ErrorNorm normtype) {
00072 super(plus, minus, sourcetype, normtype);
00073 setDataset(dataset);
00074 }
00075
00076
00078
00079
00081 public Integer getId() {
00082 return _localId;
00083 }
00084
00086 public DatasetError setId(Integer datasetErrorId) {
00087 _localId = datasetErrorId;
00088 return this;
00089 }
00090
00091
00093
00094
00095 @org.hibernate.annotations.Parent
00097 public Dataset getDataset() {
00098 return _dataset;
00099 }
00100
00102 public DatasetError setDataset(Dataset parentDataset) {
00103 log().debug("Calling setDataset()");
00104 _dataset = parentDataset;
00105 if (parentDataset != null) {
00106 if (getId() == null) {
00107 int highestId = 0;
00108 if (parentDataset.getErrors().size() > 0) {
00109 highestId = parentDataset.getErrors().last().getId();
00110 }
00111 log().debug("Incrementing dataset error ID: " + (highestId + 1));
00112 setId(highestId + 1);
00113 }
00114 parentDataset.getErrors().add(this);
00115 }
00116 return this;
00117 }
00118
00119
00121
00122
00131 public DatasetError setNormType(ErrorNorm normtype) {
00132 if (normtype != ErrorNorm.ABS) {
00133 super.setNormType(normtype);
00134 } else {
00135 log().warn("Tried to set an absolute normalization on a DatasetError");
00136
00137 }
00138 return this;
00139 }
00148 public Uncertainty setNormTypeString(String normtypeStr) throws HDException {
00149 try {
00150 ErrorNorm normtype = Enum.valueOf(ErrorNorm.class, normtypeStr.toUpperCase());
00151 setNormType(normtype);
00152 } catch (IllegalArgumentException e) {
00153 throw new HDException(e);
00154 }
00155 return this;
00156 }
00157
00158
00160
00161
00162 public int compareTo(DatasetError other) {
00163 log().debug("Comparing dataset errors...");
00164 if (getId() == null) {
00165 log().warn("Null dataset error ID");
00166 return 1;
00167 } else if (getId() > other.getId()) {
00168 log().debug("Greater than");
00169 return 1;
00170 } else if (getId() < other.getId()) {
00171 log().debug("Less than");
00172 return -1;
00173 } else {
00174 log().debug("Equal to");
00175 return 0;
00176 }
00177 }
00178
00179
00181
00182
00184 public boolean equals(Object other) {
00185 if (this == other) return true;
00186 if (! (other instanceof DatasetError)) return false;
00187 return hashCode() == other.hashCode();
00188 }
00189
00191 public int hashCode() {
00192 int code = 29;
00193 if (getId() != null) code ^= getId().hashCode();
00194 if (getSourceType() != null) code ^= getSourceType().hashCode();
00195 if (getNormType() != null) code ^= getNormType().hashCode();
00196 if (getPlus() != null) code ^= 2 * getPlus().hashCode();
00197 if (getMinus() != null) code ^= 2 * getMinus().hashCode();
00198 return code;
00199 }
00200
00201 }