net.intelie.pipes.time.ExtendSpan Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pipes-api Show documentation
Show all versions of pipes-api Show documentation
Intelie Pipes' API classes and interfaces
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);
}
}