sascha@167: package de.intevation.flys.model; sascha@167: sascha@167: import java.io.Serializable; ingo@4173: import java.util.Date; ingo@4173: import java.util.List; sascha@167: ingo@4173: import javax.persistence.Column; sascha@171: import javax.persistence.Entity; ingo@4173: import javax.persistence.GeneratedValue; ingo@4173: import javax.persistence.GenerationType; sascha@171: import javax.persistence.Id; ingo@4173: import javax.persistence.JoinColumn; sascha@174: import javax.persistence.OneToMany; sascha@174: import javax.persistence.OneToOne; sascha@2425: import javax.persistence.OrderBy; ingo@4173: import javax.persistence.SequenceGenerator; ingo@4173: import javax.persistence.Table; sascha@171: sascha@171: @Entity sascha@171: @Table(name = "discharge_tables") sascha@167: public class DischargeTable ingo@4173: implements Serializable, Comparable sascha@167: { sascha@172: private Integer id; sascha@167: private Gauge gauge; sascha@493: private String description; teichmann@4776: private String bfgId; sascha@467: private Integer kind; sascha@167: private TimeInterval timeInterval; sascha@167: sascha@174: private List dischargeTableValues; sascha@174: sascha@167: public DischargeTable() { sascha@467: kind = 0; sascha@167: } sascha@167: ingo@198: public DischargeTable(Gauge gauge) { teichmann@4776: this(gauge, null, null, 0, null); sascha@467: } sascha@467: sascha@493: public DischargeTable( sascha@493: Gauge gauge, sascha@493: String description, teichmann@4776: String bfgId, sascha@493: Integer kind, sascha@493: TimeInterval timeInterval sascha@493: ) { sascha@493: this.gauge = gauge; sascha@493: this.description = description; teichmann@4776: this.bfgId = bfgId; sascha@493: this.kind = kind; sascha@493: this.timeInterval = timeInterval; ingo@198: } ingo@198: sascha@171: @Id sascha@171: @SequenceGenerator( sascha@171: name = "SEQUENCE_DISCHARGE_TABLES_ID_SEQ", sascha@171: sequenceName = "DISCHARGE_TABLES_ID_SEQ", sascha@171: allocationSize = 1) sascha@171: @GeneratedValue( sascha@171: strategy = GenerationType.SEQUENCE, sascha@171: generator = "SEQUENCE_DISCHARGE_TABLES_ID_SEQ") sascha@171: @Column(name = "id") sascha@171: public Integer getId() { sascha@171: return id; sascha@171: } sascha@171: sascha@168: public void setId(Integer id) { sascha@167: this.id = id; sascha@167: } sascha@167: sascha@174: @OneToOne sascha@467: @JoinColumn(name = "gauge_id" ) sascha@467: public Gauge getGauge() { sascha@467: return gauge; sascha@467: } sascha@467: sascha@467: public void setGauge(Gauge gauge) { sascha@467: this.gauge = gauge; sascha@467: } sascha@467: sascha@493: @Column(name = "description") sascha@493: public String getDescription() { sascha@493: return description; sascha@493: } sascha@493: sascha@493: public void setDescription(String description) { sascha@493: this.description = description; sascha@493: } sascha@493: teichmann@4776: @Column(name = "bfg_id") teichmann@4776: public String getBfgId() { teichmann@4776: return bfgId; teichmann@4776: } teichmann@4776: teichmann@4776: public void setBfgId(String bfgId) { teichmann@4776: this.bfgId = bfgId; teichmann@4776: } teichmann@4776: sascha@467: @Column(name = "kind") sascha@467: public Integer getKind() { sascha@467: return kind; sascha@467: } sascha@467: sascha@467: public void setKind(Integer kind) { sascha@467: this.kind = kind; sascha@467: } sascha@467: sascha@467: @OneToOne sascha@174: @JoinColumn(name = "time_interval_id" ) sascha@174: public TimeInterval getTimeInterval() { sascha@174: return timeInterval; sascha@174: } sascha@174: sascha@167: public void setTimeInterval(TimeInterval timeInterval) { sascha@167: this.timeInterval = timeInterval; sascha@167: } sascha@167: sascha@174: @OneToMany sascha@174: @JoinColumn(name = "table_id") sascha@2425: @OrderBy("q") sascha@174: public List getDischargeTableValues() { sascha@174: return dischargeTableValues; sascha@174: } sascha@174: sascha@174: public void setDischargeTableValues( sascha@174: List dischargeTableValues sascha@174: ) { sascha@174: this.dischargeTableValues = dischargeTableValues; sascha@167: } ingo@4173: ingo@4173: @Override ingo@4173: public int compareTo(DischargeTable o) { ingo@4173: if (getKind() == 0 && o.getKind() != 0) { ingo@4173: return 1; ingo@4173: } ingo@4173: ingo@4173: TimeInterval other = o.getTimeInterval(); ingo@4227: if (other == null && timeInterval == null) { ingo@4227: return 1; ingo@4227: } ingo@4227: else if (other == null) { ingo@4227: return -1; ingo@4227: } ingo@4227: else if (timeInterval == null) { ingo@4227: return 1; ingo@4227: } ingo@4173: ingo@4173: Date otherStartTime = other.getStartTime(); ingo@4173: Date thisStartTime = timeInterval.getStartTime(); ingo@4173: ingo@4173: if (otherStartTime == null) { ingo@4173: return -1; ingo@4173: } ingo@4173: else if (thisStartTime == null) { ingo@4173: return 1; ingo@4173: } ingo@4173: ingo@4173: long otherStart = otherStartTime.getTime(); ingo@4173: long thisStart = thisStartTime.getTime(); ingo@4173: ingo@4173: if (otherStart < thisStart) { ingo@4173: return 1; ingo@4173: } ingo@4173: else if (otherStart > thisStart) { ingo@4173: return -1; ingo@4173: } ingo@4173: ingo@4173: Date otherStopTime = other.getStopTime(); ingo@4173: Date thisStopTime = timeInterval.getStopTime(); ingo@4173: ingo@4173: if (otherStopTime == null) { ingo@4173: return -1; ingo@4173: } ingo@4173: else if (thisStopTime == null) { ingo@4173: return 1; ingo@4173: } ingo@4173: ingo@4173: long otherEnd = otherStopTime.getTime(); ingo@4173: long thisEnd = thisStopTime.getTime(); ingo@4173: ingo@4173: if (otherEnd < thisEnd) { ingo@4173: return 1; ingo@4173: } ingo@4173: else if (otherEnd > thisEnd) { ingo@4173: return -1; ingo@4173: } ingo@4173: else { ingo@4173: return 0; ingo@4173: } ingo@4173: } sascha@167: } sascha@167: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :