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

net.intelie.pipes.time.SpanMetadata Maven / Gradle / Ivy

There is a newer version: 0.25.5
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy