ingo@2217: package de.intevation.flys.artifacts.model;
ingo@2217:
ingo@2217: import java.util.ArrayList;
ingo@4171: import java.util.Collections;
ingo@2217: import java.util.List;
ingo@2217:
ingo@2217:
ingo@2217: /**
ingo@2217: * @author Ingo Weinzierl
ingo@2217: */
ingo@2217: public class WQTimerange extends WQ {
ingo@2217:
ingo@4171: public static class TimerangeItem implements Comparable {
ingo@4171: public double q;
ingo@4171: public double w;
ingo@4171: public Timerange timerange;
ingo@4171:
ingo@4171: public TimerangeItem (Timerange timerange, double q, double w) {
ingo@4171: this.timerange = timerange;
ingo@4171: this.q = q;
ingo@4171: this.w = w;
ingo@4171: }
ingo@4171:
felix@5335: /** Sets [w,q] in wq. */
ingo@4171: public double[] get(double[] wq) {
ingo@4171: if (wq.length >= 2) {
ingo@4171: wq[0] = w;
ingo@4171: wq[1] = q;
ingo@4171: }
ingo@4171:
ingo@4171: return wq;
ingo@4171: }
ingo@4171:
ingo@4171: @Override
ingo@4171: public int compareTo(TimerangeItem other) {
ingo@4171: if (other.timerange.getStart() < timerange.getStart()) {
ingo@4171: return 1;
ingo@4171: }
ingo@4171: else if (other.timerange.getStart() > timerange.getStart()) {
ingo@4171: return -1;
ingo@4171: }
ingo@4171: else if (other.timerange.getEnd() < timerange.getEnd()) {
ingo@4171: return 1;
ingo@4171: }
ingo@4171: else if (other.timerange.getEnd() > timerange.getEnd()){
ingo@4171: return -1;
ingo@4171: }
ingo@4171: else {
ingo@4171: return 0;
ingo@4171: }
ingo@4171: }
ingo@4171: }
ingo@4171:
felix@5335: protected List timeranges;
ingo@2217:
ingo@2217:
ingo@2217: public WQTimerange() {
ingo@2217: super("");
ingo@2217: }
ingo@2217:
ingo@2217:
ingo@2217: public WQTimerange(String name) {
ingo@2217: super(name);
felix@5335: timeranges = new ArrayList();
ingo@2217: }
ingo@2217:
ingo@2217:
ingo@2217: public void add(double w, double q, Timerange t) {
ingo@2217: ws.add(w);
ingo@2217: qs.add(q);
felix@5335: timeranges.add(t);
ingo@2217: }
ingo@2217:
ingo@2217:
ingo@2239: public Timerange getTimerange(int idx) {
felix@5335: return timeranges.get(idx);
ingo@2239: }
ingo@2239:
ingo@2239:
ingo@2217: public Timerange[] getTimeranges() {
felix@5335: return timeranges.toArray(new Timerange[timeranges.size()]);
ingo@2217: }
ingo@4171:
ingo@4171: public List sort() {
felix@5335: ArrayList items = new ArrayList(timeranges.size());
ingo@4171: for (int i = 0, n = size(); i < n; i++) {
ingo@4171: items.add(new TimerangeItem(getTimerange(i), getQ(i), getW(i)));
ingo@4171: }
ingo@4171:
ingo@4171: Collections.sort(items);
ingo@4171: return items;
ingo@4171: }
ingo@2217: }
ingo@2217: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :