DatasetError.java

Go to the documentation of this file.
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     @Column(name="LocalId", nullable=false)
00018     private Integer _localId;
00019 
00020 
00022 
00023 
00025     public DatasetError() { super(); }
00026 
00033     public DatasetError(Double plusminus, ErrorSource sourcetype, ErrorNorm normtype) {
00034         super(plusminus, sourcetype, normtype);
00035     }
00036 
00044     public DatasetError(Double plus, Double minus, ErrorSource sourcetype, ErrorNorm normtype) {
00045         super(plus, minus, sourcetype, normtype);
00046     }
00047 
00054     public DatasetError(Dataset dataset, Double plusminus, ErrorSource sourcetype, ErrorNorm normtype) {
00055         super(plusminus, sourcetype, normtype);
00056         dataset.addError(this);
00057     }
00058 
00066     public DatasetError(Dataset dataset, Double plus, Double minus, ErrorSource sourcetype, ErrorNorm normtype) {
00067         super(plus, minus, sourcetype, normtype);
00068         dataset.addError(this);
00069     }
00070 
00071 
00073 
00074 
00076     public Integer getId() {
00077         return _localId;
00078     }
00079 
00081     public DatasetError setId(Integer datasetErrorId) {
00082         _localId = datasetErrorId;
00083         return this;
00084     }
00085 
00086 
00088 
00089 
00098     public DatasetError setNormType(ErrorNorm normtype) {
00099         if (normtype != ErrorNorm.ABS) {
00100             super.setNormType(normtype);
00101         } else {
00102             log().warn("Tried to set an absolute normalization on a DatasetError");
00103             //throw new HDErrorNormException("Tried to set an absolute normalization on a DatasetError");
00104         }
00105         return this;
00106     }
00115     public Uncertainty setNormTypeString(String normtypeStr) throws HDException {
00116         try {
00117             ErrorNorm normtype = Enum.valueOf(ErrorNorm.class, normtypeStr.toUpperCase());
00118             setNormType(normtype);
00119         } catch (IllegalArgumentException e) {
00120             throw new HDException(e);
00121         }
00122         return this;
00123     }
00124 
00125 
00127 
00128 
00129     public int compareTo(DatasetError other) {
00130         log().debug("Comparing dataset errors...");
00131         if (getId() == null) {
00132             log().warn("Null dataset error ID");
00133             return 1; // Sort null errors at the end
00134         } else if (getId() > other.getId()) {
00135             log().debug("Greater than");
00136             return 1;
00137         } else if (getId() < other.getId()) {
00138             log().debug("Less than");
00139             return -1;
00140         } else {
00141             log().debug("Equal to");
00142             return 0;
00143         }
00144     }
00145 
00146 
00148 
00149 
00151     public boolean equals(Object other) {
00152         if (this == other) return true;
00153         if (! (other instanceof DatasetError)) return false;
00154         return hashCode() == other.hashCode();
00155     }
00156 
00158     public int hashCode() {
00159         int code = 29;
00160         if (getId() != null) code ^= getId().hashCode();
00161         if (getSourceType() != null) code ^= getSourceType().hashCode();
00162         if (getNormType() != null) code ^= getNormType().hashCode();
00163         if (getPlus() != null) code ^= 2 * getPlus().hashCode(); // ensure this is even
00164         if (getMinus() != null) code ^= 2 * getMinus().hashCode(); // ensure this is even
00165         return code;
00166     }
00167 
00168 }

Generated on Thu Sep 20 11:41:37 2007 by  doxygen 1.5.3