package net.minecraft.gametest.framework;

import com.google.common.collect.Lists;
import javax.annotation.Nullable;
import java.util.Collection;

public class MultipleTestTracker {
    private final Collection<GameTestInfo> tests;
    @Nullable
    private GameTestListener listener;
    
    public MultipleTestTracker() {
        this.tests = Lists.newArrayList();
    }
    
    public MultipleTestTracker(final Collection<GameTestInfo> collection) {
        (this.tests = Lists.newArrayList()).addAll(collection);
    }
    
    public void add(final GameTestInfo iw) {
        this.tests.add(iw);
        if (this.listener != null) {
            iw.addListener(this.listener);
        }
    }
    
    public void setListener(final GameTestListener ix) {
        this.listener = ix;
        this.tests.forEach(iw -> iw.addListener(ix));
    }
    
    public int getFailedRequiredCount() {
        return (int)this.tests.stream().filter(GameTestInfo::hasFailed).filter(GameTestInfo::isRequired).count();
    }
    
    public int getFailedOptionalCount() {
        return (int)this.tests.stream().filter(GameTestInfo::hasFailed).filter(GameTestInfo::isOptional).count();
    }
    
    public int getDoneCount() {
        return (int)this.tests.stream().filter(GameTestInfo::isDone).count();
    }
    
    public boolean hasFailedRequired() {
        return this.getFailedRequiredCount() > 0;
    }
    
    public boolean hasFailedOptional() {
        return this.getFailedOptionalCount() > 0;
    }
    
    public int getTotalCount() {
        return this.tests.size();
    }
    
    public boolean isDone() {
        return this.getDoneCount() == this.getTotalCount();
    }
    
    public String getProgressBar() {
        final StringBuffer stringBuffer2 = new StringBuffer();
        stringBuffer2.append('[');
        final StringBuffer sb;
        this.tests.forEach(iw -> {
            if (!iw.hasStarted()) {
                sb.append(' ');
            }
            else if (iw.hasSucceeded()) {
                sb.append('+');
            }
            else if (iw.hasFailed()) {
                sb.append(iw.isRequired() ? 'X' : 'x');
            }
            else {
                sb.append('_');
            }
            return;
        });
        stringBuffer2.append(']');
        return stringBuffer2.toString();
    }
    
    @Override
    public String toString() {
        return this.getProgressBar();
    }
}
