PointError.java

Go to the documentation of this file.
00001 package cedar.hepdata.model;
00002 
00003 import javax.persistence.*;
00004 
00005 import cedar.hepdata.util.HDException;
00006 
00013 @Embeddable
00014 public class PointError extends Uncertainty {
00015 
00017     @Column(name="LocalId", nullable=false)
00018     private Integer _localId;
00019 
00020 
00021     @Transient
00023     private Point _point;
00024 
00025 
00027 
00028 
00030     public PointError() { super(); }
00031 
00038     public PointError(Double plusminus, ErrorSource sourcetype, ErrorNorm normtype) {
00039         super(plusminus, sourcetype, normtype);
00040     }
00041 
00049     public PointError(Double plus, Double minus, ErrorSource sourcetype, ErrorNorm normtype) {
00050         super(plus, minus, sourcetype, normtype);
00051     }
00052 
00056     public PointError(Point parent, Double plusminus, ErrorSource sourcetype, ErrorNorm normtype) {
00057         super(plusminus, sourcetype, normtype);
00058         setPoint(parent);
00059     }
00060 
00064     public PointError(Point parent, Double plus, Double minus, ErrorSource sourcetype, ErrorNorm normtype) {
00065         super(plus, minus, sourcetype, normtype);
00066         setPoint(parent);
00067     }
00068 
00069 
00071 
00072 
00074     public Uncertainty getAbsoluteError() throws HDException {
00075         return super.getAbsoluteError(getPoint());
00076     }
00077 
00078 
00080     public Uncertainty getAbsoluteError(Point p) throws HDException {
00081         if (! p.equals(getPoint())) {
00082             throw new HDException("Tried to apply a point error to a point other than its owner.");
00083         }
00084         return super.getAbsoluteError(p);
00085     }
00086 
00087 
00089 
00090 
00092     public Integer getId() {
00093         return _localId;
00094     }
00096     public PointError setId(Integer pointErrorId) {
00097         _localId = pointErrorId;
00098         return this;
00099     }
00100 
00101 
00103 
00104 
00105     @org.hibernate.annotations.Parent
00107     public Point getPoint() {
00108         return _point;
00109     }
00110 
00112     public PointError setPoint(Point parentPoint) {
00113         log().debug("Calling setPoint()");
00114         _point = parentPoint;
00115         if (parentPoint != null) {
00116             if (getId() == null) {
00117                 int highestId = 0;
00118                 if (parentPoint.getErrors().size() > 0) {
00119                     highestId = parentPoint.getErrors().last().getId();
00120                 }
00121                 log().debug("Incrementing point error ID: " + (highestId + 1));
00122                 setId(highestId + 1);
00123             }
00124             parentPoint.getErrors().add(this);
00125         } else {
00126             log().warn("Tried to attach a PointError to a null Point");
00127         }
00128         return this;
00129     }
00130 
00131 
00133 
00134 
00135     public int compareTo(PointError other) {
00136         log().debug("Comparing point errors...");
00137         if (getId() == null) {
00138             log().warn("Null point error ID");
00139             return 1; // Sort null point errors at the end
00140         } else if (getId() > other.getId()) {
00141             log().debug("Greater than");
00142             return 1;
00143         } else if (getId() < other.getId()) {
00144             log().debug("Less than");
00145             return -1;
00146         } else {
00147             log().debug("Equal to");
00148             return 0;
00149         }
00150     }
00151 
00152 
00154 
00155 
00157     public boolean equals(Object other) {
00158         if (this == other) return true;
00159         if (! (other instanceof PointError)) return false;
00160         return hashCode() == other.hashCode();
00161     }
00162 
00164     public int hashCode() {
00165         int code = 23;
00166         if (getPoint() != null)      code ^= getPoint().hashCode();
00167         if (getSourceType() != null) code ^= getSourceType().hashCode();
00168         if (getNormType() != null)   code ^= getNormType().hashCode();
00169         if (getId() != null)         code ^= getId().hashCode();
00170         if (getPlus() != null)       code ^= 2 * getPlus().hashCode(); // ensure this is even
00171         if (getMinus() != null)      code ^= 2 * getMinus().hashCode() + 1; // ensure this is odd
00172         return code;
00173     }
00174 }

Generated on Tue Apr 21 15:54:38 2009 for HepData object model by  doxygen 1.5.5