00001 package cedar.hepdata.model;
00002
00003 import java.util.Set;
00004 import java.util.HashSet;
00005
00006 import javax.persistence.*;
00007
00014 @Entity
00015 @Table(name="ObservableGroups")
00016 public class ObservableGroup extends Storeable {
00018 @Id @GeneratedValue
00019 @Column(name="OBSERVABLEGROUP_ID")
00020 private Long _id;
00021
00023 @Column(name="Name", nullable=false, unique=true)
00024 private String _name;
00025
00027 @Column(name="Comment", length=10000)
00028 private String _comment = "";
00029
00031 @ManyToMany
00032 @JoinTable(name="ObservableGroupMembers",
00033 joinColumns=@JoinColumn(name="OBSERVABLEGROUP_ID"),
00034 inverseJoinColumns=@JoinColumn(name="OBSERVABLE_ID"))
00035 private Set<Observable> _observables = new HashSet<Observable>();
00036
00037
00039
00041 public ObservableGroup() {}
00042
00044 public ObservableGroup(String name) {
00045 setName(name);
00046 }
00047
00049
00050
00052 public String getName() {
00053 return _name;
00054 }
00056 public ObservableGroup setName(String name) {
00057 _name = name;
00058 return this;
00059 }
00060
00062 public String getComment() {
00063 return _comment;
00064 }
00066 public ObservableGroup setComment(String comment) {
00067 _comment = comment;
00068 return this;
00069 }
00070
00071
00072
00073 public Set<Observable> getObservables() {
00074 return _observables;
00075 }
00076 public ObservableGroup setObservables(Set<Observable> observables) {
00077 for (Observable o : getObservables()) removeObservable(o);
00078 for (Observable o : observables) addObservable(o);
00079 return this;
00080 }
00081 public ObservableGroup addObservable(Observable observable) {
00082 if (observable != null) {
00083 observable.getObservableGroups().add(this);
00084 getObservables().add(observable);
00085 } else {
00086 log().warn("Tried to add a null observable to an observable group");
00087 }
00088 return this;
00089 }
00090 public ObservableGroup removeObservable(Observable observable) {
00091 if (observable != null) {
00092 observable.getObservableGroups().remove(this);
00093 getObservables().remove(observable);
00094 } else {
00095 log().warn("Tried to remove a null observable from an observable group");
00096 }
00097 return this;
00098 }
00099
00100
00102
00103
00104
00105
00106 }