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
00017 @Column(name="LocalId", nullable=false)
00019 private Integer _localId;
00020
00021
00022 @Transient
00024 private YAxis _axis;
00025
00026
00028
00029
00031 public AxisError() { super(); }
00032
00039 public AxisError(Double plusminus, ErrorSource sourcetype, ErrorNorm normtype) {
00040 super(plusminus, sourcetype, normtype);
00041 }
00042
00050 public AxisError(Double plus, Double minus, ErrorSource sourcetype, ErrorNorm normtype) {
00051 super(plus, minus, sourcetype, normtype);
00052 }
00053
00054
00058 public AxisError(YAxis parent, Double plusminus, ErrorSource sourcetype, ErrorNorm normtype) {
00059 super(plusminus, sourcetype, normtype);
00060 setAxis(parent);
00061 }
00062
00066 public AxisError(YAxis parent, Double plus, Double minus, ErrorSource sourcetype, ErrorNorm normtype) {
00067 super(plus, minus, sourcetype, normtype);
00068 setAxis(parent);
00069 }
00070
00071
00073
00074
00076 public Integer getId() {
00077 return _localId;
00078 }
00080 public AxisError setId(Integer axisErrorId) {
00081 _localId = axisErrorId;
00082 return this;
00083 }
00084
00085
00087
00088
00089 @org.hibernate.annotations.Parent
00091 public YAxis getAxis() {
00092 return _axis;
00093 }
00094
00096 public AxisError setAxis(YAxis parentAxis) {
00097 log().debug("Calling setAxis()");
00098 _axis = parentAxis;
00099 if (parentAxis != null) {
00100 if (getId() == null) {
00101 int highestId = 0;
00102 if (parentAxis.getErrors().size() > 0) {
00103 highestId = parentAxis.getErrors().last().getId();
00104 }
00105 log().debug("Incrementing axis error ID: " + (highestId + 1));
00106 setId(highestId + 1);
00107 }
00108 parentAxis.getErrors().add(this);
00109 }
00110 return this;
00111 }
00112
00113
00115
00116
00117 public int compareTo(AxisError other) {
00118 log().debug("Comparing axis errors...");
00119 if (getId() == null) {
00120 log().warn("Null axis error ID");
00121 return 1;
00122 } else if (getId() > other.getId()) {
00123 log().debug("Greater than");
00124 return 1;
00125 } else if (getId() < other.getId()) {
00126 log().debug("Less than");
00127 return -1;
00128 } else {
00129 log().debug("Equal to");
00130 return 0;
00131 }
00132 }
00133
00134
00136
00137
00139 public boolean equals(Object other) {
00140 if (this == other) return true;
00141 if (! (other instanceof AxisError)) return false;
00142 return hashCode() == other.hashCode();
00143 }
00144
00145
00147 public int hashCode() {
00148 int code = 117;
00149 if (getId() != null) code ^= getId().hashCode();
00150 if (getAxis() != null) code ^= getAxis().hashCode();
00151 if (getSourceType() != null) code ^= getSourceType().hashCode();
00152 if (getNormType() != null) code ^= getNormType().hashCode();
00153 if (getPlus() != null) code ^= 2 * getPlus().hashCode();
00154 if (getMinus() != null) code ^= 2 * getMinus().hashCode() + 1;
00155 return code;
00156 }
00157
00158 }