ingo@2327: package de.intevation.flys.jfree;
ingo@2327:
ingo@2327:
ingo@2327: import org.jfree.chart.axis.ValueAxis;
ingo@2327: import org.jfree.data.Range;
ingo@2327:
ingo@2327:
ingo@2327: /**
ingo@2327: * @author Ingo Weinzierl
ingo@2327: */
ingo@2327: public class DoubleBounds implements Bounds {
ingo@2327:
ingo@2327: protected double lower;
ingo@2327: protected double upper;
ingo@2327:
ingo@2327:
ingo@2397: /**
ingo@2397: * Default constructor. A DoubleBounds has always set lower <
ingo@2397: * upper!
ingo@2397: */
ingo@2327: public DoubleBounds(double lower, double upper) {
ingo@2397: this.lower = Math.min(lower, upper);
ingo@2397: this.upper = Math.max(lower, upper);
ingo@2327: }
ingo@2327:
ingo@2327:
ingo@2327: @Override
ingo@2327: public Number getLower() {
ingo@2327: return Double.valueOf(lower);
ingo@2327: }
ingo@2327:
ingo@2327:
ingo@2327: @Override
ingo@2327: public Number getUpper() {
ingo@2327: return Double.valueOf(upper);
ingo@2327: }
ingo@2327:
ingo@2327:
ingo@2327: @Override
ingo@2327: public void applyBounds(ValueAxis axis) {
ingo@2327: axis.setRange(new Range(lower, upper));
ingo@2327: }
ingo@2327:
ingo@2327:
ingo@2327: @Override
ingo@2327: public Bounds combine(Bounds bounds) {
ingo@2327: if (bounds == null) {
ingo@2327: return this;
ingo@2327: }
ingo@2327:
ingo@2327: DoubleBounds other = (DoubleBounds) bounds;
ingo@2327:
ingo@2327: double otherLower = other.getLower().doubleValue();
ingo@2327: double otherUpper = other.getUpper().doubleValue();
ingo@2327:
ingo@2327: return new DoubleBounds(
ingo@2327: otherLower < lower ? otherLower : lower,
ingo@2327: otherUpper > upper ? otherUpper : upper);
ingo@2327: }
ingo@2327:
ingo@2327:
ingo@2327: @Override
ingo@2327: public String toString() {
ingo@2327: return "DoubleBounds=[" + lower + " ; " + upper + "]";
ingo@2327: }
ingo@2327: }
ingo@2327: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :