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

net.intelie.pipes.time.CompositeSpan 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.checkArgument;
import static net.intelie.pipes.util.Preconditions.checkState;

public class CompositeSpan extends TimeSpanBase {
    private static final long serialVersionUID = 1L;
    private final TimeSpan startSpan;
    private final TimeSpan endSpan;

    public CompositeSpan(TimeSpan startSpan, TimeSpan endSpan) {
        super(startSpan == null ? "until $2" :
                endSpan == null ? "since $1" :
                        "from $1 to $2", startSpan, endSpan);
        checkArgument(startSpan != null || endSpan != null, "Both startSpan and endSpan are null.");

        this.startSpan = startSpan;
        this.endSpan = endSpan;
    }

    @Override
    public CompositeSpan forceZone(ZoneId zone) {
        return new CompositeSpan(forceZone(startSpan, zone), forceZone(endSpan, zone));
    }

    public TimeSpan startSpan() {
        checkState(startSpan != null, "The selected composite span has no startSpan");
        return startSpan;
    }

    public TimeSpan endSpan() {
        checkState(endSpan != null, "The selected composite span has no endSpan");
        return endSpan;
    }

    @Override
    public long start(long reference) {
        if (startSpan == null) return 0;
        return startSpan.start(reference);
    }

    @Override
    public long end(long reference) {
        if (endSpan == null) return reference;
        return endSpan.end(reference);
    }

    @Override
    public boolean isFixed() {
        return (startSpan == null || startSpan.isFixed()) && endSpan != null && endSpan.isFixed();
    }

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

    @Override
    public boolean includesPresent() {
        return endSpan == null || endSpan.includesPresent();
    }


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

        CompositeSpan that = (CompositeSpan) o;

        return Objects.equals(this.startSpan, that.startSpan) &&
                Objects.equals(this.endSpan, that.endSpan);
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy