net.intelie.pipes.time.CompositeSpan 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.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);
}
}