view artifacts/src/main/java/org/dive4elements/river/artifacts/model/DateRange.java @ 9155:9b4f5e61c02e

Changed to list of DateRange, added methods in DateRange to support year ranges
author mschaefer
date Tue, 19 Jun 2018 14:15:32 +0200
parents af13ceeba52a
children 091fd9676496
line wrap: on
line source
/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
 * Software engineering by Intevation GmbH
 *
 * This file is Free Software under the GNU AGPL (>=v3)
 * and comes with ABSOLUTELY NO WARRANTY! Check out the
 * documentation coming with Dive4Elements River for details.
 */

package org.dive4elements.river.artifacts.model;

import java.io.Serializable;
import java.util.Date;

import org.dive4elements.artifacts.common.utils.DateUtils;

public class DateRange
implements   Serializable
{
    private static final long serialVersionUID = -2553914795388094818L;

    protected Date from;
    protected Date to;

    public DateRange(final Date from, final Date to) {
        this.from = from;
        this.to   = to;
    }

    public Date getFrom() {
        return this.from;
    }

    public void setFrom(final Date from) {
        this.from = from;
    }

    public Date getTo() {
        return this.to;
    }

    public void setTo(final Date to) {
        this.to = to;
    }

    private static final boolean equalDates(final Date a, final Date b) {
        if (a == null && b != null) return false;
        if (a != null && b == null) return false;
        if (a == null) return true;
        return a.equals(b);
    }

    @Override
    public boolean equals(final Object other) {
        if (!(other instanceof DateRange)) {
            return false;
        }
        final DateRange o = (DateRange)other;
        return equalDates(this.from, o.from) && equalDates(this.to, o.to);
    }

    public int getFromYear() {
        return DateUtils.getYearFromDate(this.from);
    }

    public int getToYear() {
        return DateUtils.getYearFromDate(this.to);
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org