net.intelie.pipes.time.SpanMetadata 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 net.intelie.pipes.util.AutomatonRepr;
import net.intelie.pipes.util.SpanReprHelper;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
public class SpanMetadata implements Serializable {
private static final long serialVersionUID = 1L;
private final String label;
private final TimeSpan[] children;
private final String reprToString;
private final List childrenList;
private final SpanAnnotations annotations;
public SpanMetadata(String label, TimeSpan... children) {
this.label = label;
this.children = children;
this.childrenList = Collections.unmodifiableList(Arrays.asList(children));
this.annotations = SpanAnnotations.merge(childrenList.stream()
.filter(Objects::nonNull)
.map(TimeSpan::annotations)
.collect(Collectors.toList()));
this.reprToString = makeToString(label, children);
}
public static String makeToString(String label, TimeSpan... children) {
String base = label;
for (int i = 0; i < children.length; i++) {
base = base.replace("$" + (i + 1), "(" + children[i] + ")");
}
return base;
}
public SpanAnnotations annotations() {
return annotations;
}
public List children() {
return childrenList;
}
public AutomatonRepr repr(TimeSpan span, long timestamp, String zone) {
return SpanReprHelper.repr(span, timestamp, zone, label, children);
}
@Override
public String toString() {
return reprToString;
}
}