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

berlin.yuna.survey.model.HistoryItem Maven / Gradle / Ivy

Go to download

Survey is a plain java library to provide a base for surveys / questionnaires. It also provides a function to generate diagrams and to measure answer times.

There is a newer version: 0.1.110
Show newest version
package berlin.yuna.survey.model;

import berlin.yuna.survey.model.types.FlowItem;

import java.util.Optional;

@SuppressWarnings({"unused", "UnusedReturnValue"})
public class HistoryItem extends HistoryItemBase {

    public HistoryItem() {
        super();
    }

    public HistoryItem(final String label) {
        super(label);
    }

    public HistoryItem(final HistoryItemBase item, final Object answer) {
        super(item.getLabel(), answer, item.getCreatedAt(), item.getState());
    }

    public static Optional of(final FlowItem flowStart, final HistoryItemBase item) {
        return flowStart.get(item.getLabel()).stream().findAny().map(flowItem -> {
            if (item instanceof HistoryItem historyItem) {
                return historyItem;
            } else if (item.getAnswer() instanceof String str) {
                return new HistoryItem(item, flowItem.fromJson(str).orElse(null));
            } else {
                return null;
            }
        });
    }
}