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

net.intelie.pipes.time.ShiftBySpan 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.Locale;
import java.util.Objects;

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

public class ShiftBySpan extends TimeSpanBase {
    private static final long serialVersionUID = 1L;
    private final Period period;
    private final TimeSpan span;
    private final Where where;

    public ShiftBySpan(TimeSpan span, Where where, Period period) {
        super("$1 shifted " + checkNotNull(where, "where").toString().toLowerCase(Locale.ROOT) + " by " +
                        checkNotNull(period, "period"),
                checkNotNull(span, "span"));
        this.period = period;
        this.span = span;
        this.where = where;
    }

    @Override
    public ShiftBySpan forceZone(ZoneId zone) {
        return new ShiftBySpan(forceZone(span, zone), where, forceZone(period, zone));
    }

    @Override
    public long start(long reference) {
        reference = span.start(reference);
        return where == Where.LEFT ? period.sub(reference) : period.add(reference);
    }

    @Override
    public long end(long reference) {
        reference = span.end(reference);
        return where == Where.LEFT ? period.sub(reference) : period.add(reference);
    }

    @Override
    public boolean isFixed() {
        return span.isFixed();
    }

    @Override
    public boolean isPoint() {
        return span.isPoint();
    }

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

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

        ShiftBySpan that = (ShiftBySpan) o;

        return Objects.equals(this.period, that.period) &&
                Objects.equals(this.span, that.span);
    }

    @Override
    public int hashCode() {
        return Objects.hash(this.period, this.span);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy