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

net.intelie.pipes.time.ExtendSpan 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 ExtendSpan extends TimeSpanBase {
    private static final long serialVersionUID = 1L;
    private final TimeSpan span;
    private final Where where;
    private final Period iterable;

    public ExtendSpan(TimeSpan span, Where where, Period iterable) {
        super("$1 extended " + checkNotNull(where, "where").toString().toLowerCase(Locale.ROOT) + " by " + checkNotNull(iterable, "iterable"),
                checkNotNull(span, "span"));

        this.span = span;
        this.where = where;
        this.iterable = iterable;
    }

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

    @Override
    public long start(long reference) {
        long start = span.start(reference);
        if (where == Where.LEFT)
            start = iterable.sub(start);
        return start;
    }

    @Override
    public long end(long reference) {
        long end = span.end(reference);
        if (where == Where.RIGHT) {
            end = iterable.add(end);
        }
        return end;
    }

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

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

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

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

        ExtendSpan that = (ExtendSpan) o;

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy