package com.atlassian.bitbucket.mesh.git.builder.config;

import com.atlassian.bitbucket.mesh.process.handler.AbstractLineStdioHandler;
import com.atlassian.bitbucket.mesh.process.handler.LineDecoder;

import javax.annotation.Nonnull;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

public class ListConfigStdioHandler extends AbstractLineStdioHandler<List<String>> {

    private final List<String> values;

    public ListConfigStdioHandler(boolean nullTerminated) {
        super(StandardCharsets.UTF_8, nullTerminated ? LineDecoder.Mode.NULL : LineDecoder.Mode.LF);

        values = new ArrayList<>();
    }

    @Override
    public List<String> getResult() {
        return values;
    }

    @Override
    protected boolean onStdout(@Nonnull String line, boolean truncated) {
        return values.add(line);
    }
}
