All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.intelie.pipes.time.PointSpan Maven / Gradle / Ivy

There is a newer version: 0.25.5
Show newest version
package net.intelie.pipes.time;

import java.time.ZoneId;
import java.util.Objects;

import static net.intelie.pipes.util.Preconditions.checkNotNull;

public class PointSpan extends TimeSpanBase {
    public static final PointSpan NOW = new PointSpan(null);
    private static final long serialVersionUID = 1L;
    private final Period periods;

    public PointSpan(Period periods) {
        super(periods == null ? "now" : checkNotNull(periods, "periods") + " ago");
        this.periods = periods;
    }

    @Override
    public PointSpan forceZone(ZoneId zone) {
        return new PointSpan(forceZone(periods, zone));
    }

    @Override
    public long start(long reference) {
        if (periods != null)
            reference = periods.sub(reference);
        return reference;
    }

    @Override
    public boolean isFixed() {
        return false;
    }

    @Override
    public long end(long reference) {
        return start(reference);
    }

    @Override
    public boolean isPoint() {
        return true;
    }

    @Override
    public boolean includesPresent() {
        return periods == null;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof PointSpan)) return false;

        PointSpan that = (PointSpan) o;

        return Objects.equals(this.periods, that.periods);
    }

    @Override
    public int hashCode() {
        return Objects.hash(this.periods);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy