teichmann@5844: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5844: * Software engineering by Intevation GmbH teichmann@5844: * teichmann@5992: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5844: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5992: * documentation coming with Dive4Elements River for details. teichmann@5844: */ teichmann@5844: teichmann@5829: package org.dive4elements.river.importer; sascha@185: teichmann@5829: import org.dive4elements.river.model.Range; teichmann@5829: import org.dive4elements.river.model.River; sascha@188: sascha@188: import java.math.BigDecimal; sascha@188: sascha@188: import org.apache.log4j.Logger; sascha@188: felix@4713: /** A range that is about to be imported. */ sascha@185: public class ImportRange sascha@186: implements Comparable sascha@185: { teichmann@8200: /** Private log. */ sascha@188: private static Logger log = Logger.getLogger(ImportRange.class); sascha@188: sascha@189: protected BigDecimal a; sascha@189: protected BigDecimal b; sascha@188: sascha@188: protected Range peer; sascha@185: sascha@185: public ImportRange() { sascha@185: } sascha@185: tom@8412: public ImportRange(BigDecimal a) { tom@8412: this.a = a; tom@8412: this.b = null; tom@8412: } tom@8412: sascha@189: public ImportRange(BigDecimal a, BigDecimal b) { tom@7003: teichmann@7376: // enforce a 0) { teichmann@7376: BigDecimal t = a; a = b; b = t; tom@7003: } tom@7003: this.a = a; tom@7003: this.b = b; tom@7003: } sascha@186: } sascha@186: sascha@189: private static final int compare(BigDecimal a, BigDecimal b) { sascha@186: if (a == null && b == null) { sascha@186: return 0; sascha@186: } sascha@186: if (a == null && b != null) { sascha@186: return -1; sascha@186: } sascha@186: if (a != null && b == null) { sascha@186: return +1; sascha@186: } sascha@186: return a.compareTo(b); sascha@186: } sascha@186: sascha@186: public int compareTo(ImportRange other) { sascha@189: int cmp = compare(a, other.a); sascha@186: if (cmp != 0) return cmp; sascha@189: return compare(b, other.b); sascha@185: } sascha@185: sascha@189: public BigDecimal getA() { sascha@189: return a; sascha@185: } sascha@185: sascha@189: public void setA(BigDecimal a) { tom@7221: if (this.b != null && a.compareTo(b) >= 0) { tom@8856: throw new IllegalArgumentException( tom@8856: "a (" + a + ") must be smaller than b (" + b + ")."); tom@7221: } teichmann@7376: this.a = a; sascha@185: } sascha@185: sascha@189: public BigDecimal getB() { sascha@189: return b; sascha@189: } sascha@189: sascha@189: public void setB(BigDecimal b) { tom@7221: if (b != null && b.compareTo(a) <= 0) { tom@8856: throw new IllegalArgumentException( tom@8856: "b (" + b + ") must be greater than a (" + a + ") or null."); tom@7221: } teichmann@7376: this.b = b; sascha@185: } sascha@188: sascha@188: public Range getPeer(River river) { sascha@188: if (peer == null) { sascha@500: peer = ImporterSession.getInstance().getRange(river, a, b); sascha@188: } sascha@188: return peer; sascha@188: } sascha@185: } sascha@185: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :