AxisError.java

Go to the documentation of this file.
00001 package cedar.hepdata.model;
00002 
00003 import cedar.hepdata.util.HDException;
00004 
00005 import javax.persistence.*;
00006 
00014 @Embeddable
00015 public class AxisError extends Uncertainty {
00016 
00018     @Column(name="LocalId", nullable=true)
00019     private Integer _localId;
00020 
00021 
00023 
00024 
00026     public AxisError() { super(); }
00027 
00034     public AxisError(Double plusminus, ErrorSource sourcetype, ErrorNorm normtype) {
00035         super(plusminus, sourcetype, normtype);
00036     }
00037 
00045     public AxisError(Double plus, Double minus, ErrorSource sourcetype, ErrorNorm normtype) {
00046         super(plus, minus, sourcetype, normtype);
00047     }
00048 
00049 
00051 
00052 
00054     public Integer getId() {
00055         return _localId;
00056     }
00058     public AxisError setId(Integer axisErrorId) {
00059         _localId = axisErrorId;
00060         return this;
00061     }
00062 
00063 
00065 
00066 
00067     public int compareTo(AxisError other) {
00068         log().debug("Comparing axis errors...");
00069         if (getId() == null) {
00070             log().warn("Null axis error ID");
00071             return 1; // Sort null errors at the end
00072         } else if (getId() > other.getId()) {
00073             log().debug("Greater than");
00074             return 1;
00075         } else if (getId() < other.getId()) {
00076             log().debug("Less than");
00077             return -1;
00078         } else {
00079             log().debug("Equal to");
00080             return 0;
00081         }
00082     }
00083 
00084 
00086 
00087 
00089     public boolean equals(Object other) {
00090         if (this == other) return true;
00091         if (! (other instanceof AxisError)) return false;
00092 
00093         final AxisError test = (AxisError) other;
00094         if (! test.getNormType().equals(getNormType()) ) return false;
00095         if (! test.getSourceType().equals(getSourceType()) ) return false;
00096         if ( (test.getPlus() - getPlus())/getPlus() > 1e-6 ) return false;
00097         if ( (test.getMinus() - getMinus())/getMinus() > 1e-6 ) return false;
00098 
00099         return true;
00100     }
00101 
00102 
00104     public int hashCode() {
00105         int code = 117;
00106         if (getId() != null) code ^= getId().hashCode();
00108         if (getSourceType() != null) code ^= getSourceType().hashCode();
00109         if (getNormType() != null) code ^= getNormType().hashCode();
00110         if (getPlus() != null) code ^= 2 * getPlus().hashCode(); // ensure this is even
00111         if (getMinus() != null) code ^= 2 * getMinus().hashCode(); // ensure this is even
00112         return code;
00113     }
00114 }

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