YAxis.java

Go to the documentation of this file.
00001 package cedar.hepdata.model;
00002 
00003 import java.util.Collection;
00004 import java.util.Arrays;
00005 import java.util.SortedSet;
00006 import java.util.TreeSet;
00007 import java.util.Set;
00008 import java.util.HashSet;
00009 import java.util.List;
00010 import java.util.Vector;
00011 
00012 import javax.persistence.*;
00013 
00014 import cedar.hepdata.util.Unit;
00015 
00024 @Entity
00025 @Table(name="YAxes")
00026 public class YAxis extends Axis implements Comparable<YAxis> {
00028     @Column(name="LocalId", nullable=false)
00029     private Integer _localId;
00030 
00032     @OneToMany(mappedBy="_yAxis")
00033     @org.hibernate.annotations.Fetch(value=org.hibernate.annotations.FetchMode.JOIN)
00034     @org.hibernate.annotations.Cascade(value={org.hibernate.annotations.CascadeType.ALL,
00035                                               org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
00036     @org.hibernate.annotations.Sort(type=org.hibernate.annotations.SortType.NATURAL)
00037     @org.hibernate.annotations.BatchSize(size=20)
00038     private SortedSet<Point> _points = new TreeSet<Point>();
00039 
00041     @org.hibernate.annotations.CollectionOfElements
00042     @JoinTable(name="AxisErrors", joinColumns=@JoinColumn(name="AXIS_ID"))
00043     @org.hibernate.annotations.CollectionId(columns=@Column(name="AxisErrorId"),
00044                                             type=@org.hibernate.annotations.Type(type="long"),
00045                                             generator="sequence")
00046     @org.hibernate.annotations.Sort(type=org.hibernate.annotations.SortType.NATURAL)
00047     @org.hibernate.annotations.BatchSize(size=5)
00048     private SortedSet<AxisError> _errors = new TreeSet<AxisError>();
00049 
00051     @OneToMany(mappedBy="_yAxis")
00052     @org.hibernate.annotations.Cascade(value={org.hibernate.annotations.CascadeType.ALL,
00053                                               org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
00054     private Set<AxisProperty> _properties = new HashSet<AxisProperty>();
00055 
00057     @OneToMany(mappedBy="_yAxis")
00058     @org.hibernate.annotations.Cascade(value={org.hibernate.annotations.CascadeType.ALL,
00059                                               org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
00060     private Set<AxisReaction> _reactions = new HashSet<AxisReaction>();
00061 
00063     @ManyToOne
00064     @org.hibernate.annotations.Cascade(value={org.hibernate.annotations.CascadeType.ALL})
00065     private Observable _observable = null;
00066 
00068     @org.hibernate.annotations.CollectionOfElements
00069     @JoinTable(name="YAxisComments", joinColumns=@JoinColumn(name="AXIS_ID"))
00070     @org.hibernate.annotations.IndexColumn(name="Posn")
00071     @Column(name="Comments", length=10000)
00072     private List<String> _comments = new Vector<String>();
00073 
00075     @ManyToOne
00076     protected Dataset _dataset;
00077 
00078 
00080 
00081 
00083     public YAxis() {
00084         super();
00085         log().debug("Making a YAxis (0 arg constructor)");
00086     }
00087 
00088     public YAxis(String header) {
00089         super(header);
00090         log().debug("Making a YAxis (1 arg constructor)");
00091     }
00092 
00093     public YAxis(String header, Unit unit) {
00094         super(header, unit);
00095         log().debug("Making a YAxis (2 arg constructor)");
00096     }
00097 
00098     public YAxis(Dataset dataset) {
00099         this();
00100         setDataset(dataset);
00101         log().debug("Making a YAxis (1 arg constructor)");
00102     }
00103 
00104     public YAxis(Dataset dataset, String header) {
00105         this(header);
00106         setDataset(dataset);
00107         log().debug("Making a YAxis (2 arg constructor)");
00108     }
00109 
00110     public YAxis(Dataset dataset, String header, Unit unit) {
00111         this(header, unit);
00112         setDataset(dataset);
00113         log().debug("Making a YAxis (3 arg constructor)");
00114     }
00115 
00116     public YAxis(Observable observable) {
00117         this();
00118         log().debug("Making a YAxis (1 arg constructor)");
00119         setObservable(observable);
00120     }
00121 
00122     public YAxis(Observable observable, String header) {
00123         this(header);
00124         log().debug("Making a YAxis (2 arg constructor)");
00125         setObservable(observable);
00126     }
00127 
00128     public YAxis(Observable observable, String header, Unit unit) {
00129         this(header, unit);
00130         log().debug("Making a YAxis (3 arg constructor)");
00131         setObservable(observable);
00132     }
00133 
00134     public YAxis(Dataset dataset, Observable observable) {
00135         this(dataset);
00136         log().debug("Making a YAxis (2 arg constructor)");
00137         setObservable(observable);
00138     }
00139 
00140     public YAxis(Dataset dataset, Observable observable, String header) {
00141         this(dataset, header);
00142         log().debug("Making a YAxis (3 arg constructor)");
00143         setObservable(observable);
00144     }
00145 
00146     public YAxis(Dataset dataset, Observable observable, String header, Unit unit) {
00147         this(dataset, header, unit);
00148         log().debug("Making a YAxis (4 arg constructor)");
00149         setObservable(observable);
00150     }
00151 
00152 
00154 
00155 
00159     public Paper getPaper() {
00160         if (getDataset() != null) {
00161             return getDataset().getPaper();
00162         } else {
00163             return null;
00164         }
00165     }
00166 
00167 
00168     // Comments
00169     public List<String> getComments() {
00170         return _comments;
00171     }
00172     public YAxis setComments(List<String> comments) {
00173         _comments = comments;
00174         return this;
00175     }
00176     public YAxis addComment(String comment) {
00177         _comments.add(comment);
00178         return this;
00179     }
00180     public YAxis removeComment(String comment) {
00181         _comments.remove(comment);
00182         return this;
00183     }
00184 
00185 
00187 
00188 
00190     public Integer getId() {
00191         return _localId;
00192     }
00194     public YAxis setId(Integer yAxisId) {
00195         _localId = yAxisId;
00196         return this;
00197     }
00198 
00199 
00201     public Dataset getDataset() {
00202         return _dataset;
00203     }
00205     public YAxis setDataset(Dataset dataset) {
00206         log().debug("Calling setDataset()");
00207         _dataset = dataset;
00208         if (dataset != null) {
00209             if (getId() == null) {
00210                 int highestId = 0;
00211                 if (dataset.getYAxes().size() > 0) {
00212                     highestId = dataset.getYAxes().last().getId();
00213                 }
00214                 log().debug("Incrementing y-axis ID: " + (highestId + 1));
00215                 setId(highestId + 1);
00216             }
00217             log().debug("Adding myself to a Dataset");
00218             dataset.getYAxes().add(this);
00219         } else {
00220             log().warn("Tried to attach a YAxis to a null Dataset");
00221         }
00222         return this;
00223     }
00224 
00225 
00227     public SortedSet<XAxis> getXAxes() {
00228         if (getDataset() != null) {
00229             return getDataset().getXAxes();
00230         } else {
00231             return null;
00232         }
00233     }
00234 
00235 
00236     // Reactions
00237     public Set<AxisReaction> getReactions() {
00238         return _reactions;
00239     }
00240     public YAxis setReactions(Set<AxisReaction> reactions) {
00242         _reactions = reactions;
00243         return this;
00244     }
00245     public YAxis addReaction(AxisReaction reaction) {
00246         if (reaction != null) {
00247             reaction.setYAxis(this);
00248             _reactions.add(reaction);
00249         } else {
00250             log().warn("Tried to add a null reaction to a y-axis");
00251         }
00252         return this;
00253     }
00254     public YAxis removeReaction(AxisReaction reaction) {
00255         if (reaction != null) {
00256             reaction.setYAxis(null);
00257             _reactions.remove(reaction);
00258         } else {
00259             log().warn("Tried to remove a null reaction from a y-axis");
00260         }
00261         return this;
00262     }
00263 
00264 
00266     public Observable getObservable() {
00267         return _observable;
00268     }
00269 
00271     public YAxis setObservable(Observable observable) {
00272         if (observable != null) observable.getYAxes().add(this);
00273         _observable = observable;
00274         return this;
00275     }
00276 
00277 
00279     public SortedSet<Point> getPoints() {
00280         return _points;
00281     }
00282 
00284     public Point getPoint(Integer pointId) {
00285         Point thePoint = null;
00286         for (Point p : getPoints()) {
00287             if (p.getId().equals(pointId)) {
00288                 thePoint = p;
00289                 break;
00290             }
00291         }
00292         return thePoint;
00293     }
00294 
00296     public YAxis setPoints(SortedSet<Point> points) {
00297         log().debug("Calling setPoints(SortedSet<Point>)");
00298         _points = points;
00299         return this;
00300     }
00301 
00302 //     /** Set points from a Collection. */
00303 //     public YAxis setPoints(Collection<Point> points) {
00304 //         log().debug("Calling setPoints(Collection<Point>)");
00305 //         this.points.clear();
00306 //         for (Point p : points) addPoint(p);
00307 //         return this;
00308 //     }
00309 
00310 //     /** Set points from an array. */
00311 //     public YAxis setPoints(Point[] points) {
00312 //         setPoints(Arrays.asList(points));
00313 //         return this;
00314 //     }
00315 
00317     public YAxis addPoint(Point point) {
00318         if (point != null) {
00319             if (point.getId() == null) {
00320                 int highestId = 0;
00321                 if (getPoints().size() > 0) {
00322                     highestId = getPoints().last().getId();
00323                 }
00324                 log().debug("Incrementing point ID: " + (highestId + 1));
00325                 point.setId(highestId + 1);
00326             }
00327             log().debug("Adding point to y-axis " + getId() + ": ID = " + point.getId());
00328             point.setYAxis(this);
00329         } else {
00330             log().warn("Tried to add a null Point to a YAxis");
00331         }
00332         return this;
00333     }
00334 
00336     public YAxis removePoint(Point point) {
00337         log().debug("Removing point: " + point);
00338         if (point != null) {
00339             getPoints().remove(point);
00340             point.setYAxis(null);
00341         } else {
00342             log().warn("Tried to remove a null Point from a YAxis");
00343         }
00344         log().debug("Removing point: done");
00345         return this;
00346     }
00347 
00348 
00349     // Axis errors
00350     public SortedSet<AxisError> getErrors() {
00351         return _errors;
00352     }
00353     public YAxis setErrors(SortedSet<AxisError> axisErrors) {
00354         getErrors().clear();
00355         for (AxisError e : axisErrors) addError(e);
00356         return this;
00357     }
00358     public YAxis setErrors(Collection<AxisError> axisErrors) {
00359         getErrors().clear();
00360         for (AxisError e : axisErrors) addError(e);
00361         return this;
00362     }
00363     public YAxis addError(AxisError axisError) {
00364         if (axisError != null) {
00365             getErrors().add(axisError);
00366             // Auto-increment the local ID if necessary
00367             if (axisError.getId() == null) {
00368                 if (getErrors().last() != null && getErrors().last().getId() != null) {
00369                     axisError.setId(getErrors().last().getId() + 1);
00370                 } else {
00371                     axisError.setId(getErrors().size() + 1);
00372                 }
00373             }
00374         } else {
00375             log().warn("Tried to add a null AxisError to a YAxis");
00376         }
00377         return this;
00378     }
00379     public YAxis removeError(AxisError axisError) {
00380         if (axisError != null) {
00381             getErrors().remove(axisError);
00382         } else {
00383             log().warn("Tried to remove a null AxisError from a YAxis");
00384         }
00385         return this;
00386     }
00387 
00388 
00389     // Other errors
00390     public SortedSet<Uncertainty> getDatasetErrors() {
00391         SortedSet<Uncertainty> dsErrors = new TreeSet<Uncertainty>();
00392         if (getDataset() != null) {
00393             dsErrors.addAll( getDataset().getErrors() );
00394         }
00395         return dsErrors;
00396     }
00397     public SortedSet<Uncertainty> getAllErrors() {
00398         SortedSet<Uncertainty> allErrors = new TreeSet<Uncertainty>();
00399         allErrors.addAll(getErrors());
00400         allErrors.addAll(getDatasetErrors());
00401         return allErrors;
00402     }
00403 
00404 
00405     // Properties
00406     public Set<AxisProperty> getProperties() {
00407         return _properties;
00408     }
00409     public YAxis setProperties(Set<AxisProperty> properties) {
00410         _properties = properties;
00411         return this;
00412     }
00413     public YAxis addProperty(AxisProperty property) {
00414         if (property != null) {
00415             property.setYAxis(this);
00416             _properties.add(property);
00417         } else {
00418             log().warn("Tried to add a null AxisProperty to a YAxis");
00419         }
00420         return this;
00421     }
00422     public YAxis removeProperty(AxisProperty property) {
00423         if (property != null) {
00424             property.setYAxis(null);
00425             _properties.remove(property);
00426         } else {
00427             log().warn("Tried to remove a null AxisProperty from a YAxis");
00428         }
00429         return this;
00430     }
00431 
00432 
00434 
00435 
00436     public int compareTo(YAxis other) {
00437         log().debug("Comparing y-axes...");
00438         if (getId() == null) {
00439             log().debug("Null YAxis ID");
00440             return 1; // Sort null y-axes at the end
00441         } else if (getId() > other.getId()) {
00442             log().debug("Greater than");
00443             return 1;
00444         } else if (getId() < other.getId()) {
00445             log().debug("Less than");
00446             return -1;
00447         } else {
00448             log().debug("Equal to");
00449             return 0;
00450         }
00451     }
00452 
00453 
00455 
00456 
00458     public String toString() {
00459         return toString(0);
00460     }
00461 
00463     public String toString(Integer indentBy) {
00464         log().debug("Writing out y-axis as a string");
00465         StringBuffer s = new StringBuffer();
00466         String indent = "";
00467         for (int i  = 0; i < indentBy; ++i) indent += " ";
00468 
00469         s.append(indent + "Y-axis ID: " + getId() + "\n");
00470         s.append(indent + "Header: " + getHeader());
00471         for (Point point : getPoints()) {
00472             s.append("\n" + point.toString(indentBy + 2));
00473         }
00474         return s.toString();
00475     }
00476 
00477 
00479 
00480 
00481     public boolean equals(Object other) {
00482         if (this == other) return true;
00483         if (! (other instanceof YAxis)) return false;
00484 
00485         final YAxis test = (YAxis) other;
00486         if (! test.getPaper().equals(getPaper()) ) return false;
00487         if (! test.getDataset().equals(getDataset()) ) return false;
00488         if (! test.getHeader().equals(getHeader()) ) return false;
00489         if (! test.getUnit().equals(getUnit()) ) return false;
00490         return true;
00491     }
00492 
00493     public int hashCode() {
00494         int code = 0;
00495         if (getPaper()   != null) code += 1000000 * getPaper().hashCode();
00496         if (getDataset() != null) code += 100 * getDataset().hashCode();
00497         if (getHeader()  != null) code += 10 * getHeader().hashCode();
00498         if (getUnit()    != null) code += getUnit().hashCode();
00499         code *= 2; // ensure this is even
00500         return code;
00501     }
00502 
00503 }

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