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 @org.hibernate.annotations.Parent
00018 @Column(name="ParentPoint", nullable=false)
00019 @Transient
00021 private Point _point;
00022
00023
00025 @Column(name="LocalId", nullable=false)
00026 private Integer _localId;
00027
00028
00030
00031
00033 public PointError() { super(); }
00034
00041 public PointError(Double plusminus, ErrorSource sourcetype, ErrorNorm normtype) {
00042 super(plusminus, sourcetype, normtype);
00043 }
00044
00052 public PointError(Double plus, Double minus, ErrorSource sourcetype, ErrorNorm normtype) {
00053 super(plus, minus, sourcetype, normtype);
00054 }
00055
00059 public PointError(Point parent, Double plusminus, ErrorSource sourcetype, ErrorNorm normtype) {
00060 super(plusminus, sourcetype, normtype);
00061 setPoint(parent);
00062 }
00063
00067 public PointError(Point parent, Double plus, Double minus, ErrorSource sourcetype, ErrorNorm normtype) {
00068 super(plus, minus, sourcetype, normtype);
00069 setPoint(parent);
00070 }
00071
00072
00074
00075
00077 public Uncertainty getAbsoluteError() throws HDException {
00078 return super.getAbsoluteError(getPoint());
00079 }
00080
00081
00083 public Uncertainty getAbsoluteError(Point p) throws HDException {
00084 if (! p.equals(getPoint())) {
00085 throw new HDException("Tried to apply a point error to a point other than its owner.");
00086 }
00087 return super.getAbsoluteError(p);
00088 }
00089
00090
00092
00093
00095 public Integer getId() {
00096 return _localId;
00097 }
00099 public PointError setId(Integer pointErrorId) {
00100 _localId = pointErrorId;
00101 return this;
00102 }
00103
00104
00106
00107
00109 public Point getPoint() {
00110 return _point;
00111 }
00112
00114 public PointError setPoint(Point parentPoint) {
00116 _point = parentPoint;
00117 return this;
00118 }
00119
00120
00122
00123 public int compareTo(PointError other) {
00124 log().debug("Comparing point errors...");
00125 if (getId() == null) {
00126 log().warn("Null point error ID");
00127 return 1;
00128 } else if (getId() > other.getId()) {
00129 log().debug("Greater than");
00130 return 1;
00131 } else if (getId() < other.getId()) {
00132 log().debug("Less than");
00133 return -1;
00134 } else {
00135 log().debug("Equal to");
00136 return 0;
00137 }
00138 }
00139
00140
00142
00143
00145 public boolean equals(Object other) {
00146 if (this == other) return true;
00147 if (! (other instanceof PointError)) return false;
00148 return hashCode() == other.hashCode();
00149 }
00150
00152 public int hashCode() {
00153 int code = 23;
00154 if (getSourceType() != null) code ^= getSourceType().hashCode();
00155 if (getNormType() != null) code ^= getNormType().hashCode();
00156 if (getId() != null) code ^= getId().hashCode();
00158 if (getPlus() != null) code ^= 2 * getPlus().hashCode();
00159 if (getMinus() != null) code ^= 2 * getMinus().hashCode() + 1;
00160 return code;
00161 }
00162 }